Example #1
0
 public void begin() {
   buildModel();
   buildDisplay();
   buildSchedule();
   graphLayout.updateLayout();
   surface.display();
   if (showHist) degreeDist.display();
   if (showPlot) graph.display();
 }
Example #2
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");
  }