Esempio n. 1
0
  ///////////////////////////////////////////////////////////////////////////////
  // step
  //
  // executed each step of the model.
  // Ask the super-class to do its step() method,
  // and then this does display related activities.
  //
  public void step() {

    super.step(); // the model does whatever it does

    // add things after this for all displays (graphs, etc)
    dsurf.updateDisplay();
    graph.step();
    graphNbors.step();
    graphFood.step();
  }
Esempio n. 2
0
  public void setup() {
    // System.out.printf( "==> GUIModel setup() called...\n" );

    super.setup(); // the super class does conceptual-model setup

    // NOTE: you may want to set these next two to 'true'
    // if you are on a windows machine.  that would tell repast
    // to by default send System.out and .err output to
    // a special repast output window.
    AbstractGUIController.CONSOLE_ERR = false;
    AbstractGUIController.CONSOLE_OUT = false;
    AbstractGUIController.UPDATE_PROBES = true;

    if (dsurf != null) dsurf.dispose();
    if (graph != null) graph.dispose();
    if (graphNbors != null) graphNbors.dispose();
    if (graphFood != null) graphFood.dispose();
    graph = null;
    dsurf = null;
    graphNbors = null;
    graphFood = null;

    // tell the Ant class we are in GUI mode.
    Ant.setupBugDrawing(this);
    Food.setupFoodDrawing(this);

    // init, setup and turn on the modelMinipulator stuff (in custom actions)
    modelManipulator.init();
    // one custom action to just print the bug list
    modelManipulator.addButton(
        "Print Bugs",
        new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            System.out.printf("printBugs...\n");

            printBugs();
          }
        });
    // another action:  reset all bugs probRandMove field
    // using the parameters that define the distribution to use
    modelManipulator.addButton(
        "Reset Bug probRandMove",
        new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            resetBugProbRandMove();
          }
        });

    if (rDebug > 0) System.out.printf("<== GUIModel setup() done.\n");
  }
Esempio n. 3
0
  /////////////////////////////////////////////////////////////////////
  // buildDisplay
  //
  // builds the display and display related things
  //
  public void buildDisplay() {
    if (rDebug > 0) System.out.printf("==> GUIModel buildDisplay...\n");

    // create the object we see as the 2D "world" on the screen
    dsurf = new DisplaySurface(this, "Agent Display");
    registerDisplaySurface("Main Display", dsurf);

    // create the ColorMap for displayihg the amount of pheromone
    // as a degree of red-ness in the cells.
    pherColorMap = new ColorMap();
    for (int i = 0; i < colorMapSize; i++) {
      // we specify the position i, and a fraction of each of RGB shade
      pherColorMap.mapColor(i, 0, 0, i / colorMapMax);
    }

    // create the ColorMap for displayihg the amount of ant pheromone
    // as a degree of blue-ness in the cells.
    pherCFColorMap = new ColorMap();
    for (int i = 0; i < colorMapSize; i++) {
      // we specify the position i, and a fraction of each of RGB shade
      pherCFColorMap.mapColor(i, 0, i / colorMapMax, 0);
    }

    // we are going to display bug color based on probRandMove
    setBugColorBasedOnProbRandMove();

    // enable the custom action(s)
    modelManipulator.setEnabled(true);

    // create mapper object, from 2D GridWorld to the display surface
    worldDisplay = new Object2DDisplay(world);
    // foodDisplay = new Object2DDisplay( world );
    // speed up display of ants -- just display them!
    worldDisplay.setObjectList(allList);
    // foodDisplay.setObjectList( foodList );

    // create the link between the pSpace and the dsurf.
    // we have to tell it how to scale values to fit the colorMap.
    // We want the largest possible state (pheromone) value
    // to map into the colorMapMax-th entry in the colorMap array.
    // The Value2DDisplay does this mapping with the parameters m,c:
    //   int color index = (state / m) + c
    // so we want m = truncate( maxValue / maxColorIndex )
    pSpaceDisplay = new Value2DDisplay(pSpace, pherColorMap);
    int m = (int) (maxPher / colorMapMax);
    if (rDebug > 1) System.out.printf("  -> pSpaceDisplay scaling m = %d.\n", m);
    pSpaceDisplay.setDisplayMapping(m, 0);
    // and now for the food pheromone...
    pSpaceCarryingFoodDisplay = new Value2DDisplay(pSpaceCarryingFood, pherCFColorMap);
    int n = (int) (maxPher / colorMapMax);
    if (rDebug > 1) System.out.printf("  -> pSpaceCarryingFoodDisplay scaling m = %d.\n", n);
    pSpaceCarryingFoodDisplay.setDisplayMapping(n, 0);

    // add the pSpace to the surface first, so the bugs write over it.
    dsurf.addDisplayable(pSpaceDisplay, "Nest Pheromone");
    dsurf.addDisplayable(pSpaceCarryingFoodDisplay, "Ant Pheromone");
    // now add the display of agents
    dsurf.addDisplayableProbeable(worldDisplay, "Agents");
    // dsurf.addDisplayableProbeable( foodDisplay, "Food");
    addSimEventListener(dsurf); // link to the other parts of the repast gui

    dsurf.display();

    // set up sequence for pop size, etc, and graph to plot on
    class SeqAntPopSize implements Sequence {
      public double getSValue() {
        return getAntPopSize();
      }
    }
    class SeqAntPopAvgX implements Sequence {
      public double getSValue() {
        return getAntPopAvgX();
      }
    }
    class SeqAntPopAvgDistSource implements Sequence {
      public double getSValue() {
        return getAntAvgDistanceFromSource() * 10;
      }
    }

    graph = new OpenSequenceGraph("Population Stats", this);
    graph.setXRange(0, 200);
    graph.setYRange(0, 60);
    graph.setYIncrement(20);
    graph.setAxisTitles("time", "Pop Size");
    graph.addSequence("Ant Pop Size", new SeqAntPopSize(), Color.BLACK);
    graph.addSequence("Ant Avg X", new SeqAntPopAvgX(), Color.BLUE);
    graph.addSequence("Ant Avg Dist Source * 10", new SeqAntPopAvgDistSource(), Color.GREEN);
    graph.display();

    // a second graph!
    // lets create a graph for average bug number of neighbors at 1,2 cells away
    class AverageBugNbor1Count implements Sequence {
      public double getSValue() {
        return averageBugNbor1Count;
      }
    }
    class AverageBugNbor2Count implements Sequence {
      public double getSValue() {
        return averageBugNbor2Count;
      }
    }
    graphNbors = new OpenSequenceGraph("More Stats", this);
    graphNbors.setXRange(0, 200);
    graphNbors.setYRange(0, 10);
    graphNbors.setYIncrement(10);
    graphNbors.setAxisTitles("time", "Avg #Nbors");
    graphNbors.addSequence("Avg. Bug 1-Nbor Count", new AverageBugNbor1Count());
    graphNbors.addSequence("Avg. Bug 2-Nbor Count", new AverageBugNbor2Count());

    graphNbors.display();

    // graph showing number of food objects

    class SeqFoodListSize implements Sequence {
      public double getSValue() {
        return foodList.size();
      }
    }

    graphFood = new OpenSequenceGraph("Food Stats", this);
    graphFood.setXRange(0, 200);
    graphFood.setYRange(0, 250);
    graphFood.setYIncrement(20);
    graphFood.setAxisTitles("time", "Food List Size");
    graphFood.addSequence("Food List Size", new SeqFoodListSize(), Color.BLUE);

    graphFood.display();

    if (rDebug > 0) System.out.printf("<== GUIModel buildDisplay done.\n");
  }