Пример #1
0
  public void buildDisplay() {
    if (layoutType.equals("KK")) {
      graphLayout = new KamadaGraphLayout(agentList, worldXSize, worldYSize, surface, updateEveryN);
    } else if (layoutType.equals("Fruch")) {
      graphLayout = new FruchGraphLayout(agentList, worldXSize, worldYSize, surface, updateEveryN);
    } else if (layoutType.equals("CircleLayout")) {
      graphLayout = new CircularGraphLayout(agentList, worldXSize, worldYSize);
    }

    // these four lines hook up the graph layouts to the stop, pause, and
    // exit buttons on the toolbar. When stop, pause, or exit is clicked
    // the graph layouts will interrupt their layout as soon as possible.
    Controller c = (Controller) getController();
    c.addStopListener(graphLayout);
    c.addPauseListener(graphLayout);
    c.addExitListener(graphLayout);

    Network2DDisplay display = new Network2DDisplay(graphLayout);
    surface.addDisplayableProbeable(display, "JinGirNew Display");

    // add the display as a Zoomable. This means we can "zoom" in on
    // various parts of the network.
    surface.addZoomable(display);
    surface.setBackground(java.awt.Color.white);
    addSimEventListener(surface);
  }
Пример #2
0
 public void initialAction() {
   randomMeeting();
   neighborMeeting();
   graphLayout.updateLayout();
   surface.updateDisplay();
   if (showHist) degreeDist.step();
   if (showPlot) graph.step();
 }
Пример #3
0
 public void begin() {
   buildModel();
   buildDisplay();
   buildSchedule();
   graphLayout.updateLayout();
   surface.display();
   if (showHist) degreeDist.display();
   if (showPlot) graph.display();
 }
Пример #4
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();
  }
Пример #5
0
  public void mainAction() {
    randomMeeting();
    neighborMeeting();
    removeRandomFriendship();
    graphLayout.updateLayout();
    surface.updateDisplay();
    if (showHist) degreeDist.step();
    if (showPlot) graph.step();

    // System.out.println(NetUtilities.getComponents(agentList).size());

  }
Пример #6
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");
  }
Пример #7
0
  public void setup() {
    Random.createUniform();
    if (surface != null) surface.dispose();
    if (degreeDist != null) degreeDist.dispose();
    if (graph != null) graph.dispose();

    surface = null;
    schedule = null;
    degreeDist = null;
    graph = null;

    System.gc();

    surface = new DisplaySurface(this, "JinGirModelII Display");
    registerDisplaySurface("Main Display", surface);
    schedule = new Schedule();
    agentList = new ArrayList();
    worldXSize = 500;
    worldYSize = 500;
  }
Пример #8
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");
  }