package RandomMoveInGrid; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.Formatter; import uchicago.src.sim.engine.Schedule; import uchicago.src.sim.engine.SimModelImpl; import uchicago.src.sim.engine.*; import uchicago.src.sim.util.*; import uchicago.src.sim.gui.*; import uchicago.src.sim.gui.ColorMap; import uchicago.src.sim.gui.DisplaySurface; import uchicago.src.sim.gui.Object2DDisplay; import uchicago.src.sim.gui.Value2DDisplay; import uchicago.src.sim.space.Object2DTorus; import uchicago.src.sim.engine.AbstractGUIController; public class GUIModel extends Model { private Object2DDisplay worldDisplay; // 2D Object lattice -> display (Repast) private DisplaySurface dsurf; // display surface (RePast) public static ColorMap colorMap; public static final int colorMapSize = 64; public static final double colorMapMax = colorMapSize - 1.0; ///////////////////////////////////////////////////////////////////// // setup // // this runs automatically when the model starts // and when you click the reload button, to "tear down" any // existing display objects, and get ready to initialize // them at the start of the next 'run'. // 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; if ( dsurf != null ) dsurf.dispose(); // create the ColorMap for displayihg the amount of pheromone // as a degree of red-ness in the cells. // Note this probably should be in buildDisplay(), to allow // for parameterized control of the map creation. colorMap = new ColorMap (); for (int i = 0; i < colorMapSize; i++) { // we specify the position i, and a fraction of each of RGB shade colorMap.mapColor ( i, i / colorMapMax, 0, 0 ); } dsurf = null; if ( rDebug > 0 ) System.out.printf( "<== GUIModel setup() done.\n" ); } ///////////////////////////////////////////////////////////////////// // begin // // this runs when you click the "initialize" button // (the button with the single arrow that goes around in a circle) // public void begin() { DMSG(1, "==> enter GUIModel-begin()" ); buildModel(); // the base model does this buildDisplay(); buildSchedule(); DMSG(1, "<== leave GUIModel-begin() done." ); } ///////////////////////////////////////////////////////////////////// // buildDisplay // // builds the display and display related things // public void buildDisplay() { if ( rDebug > 0 ) System.out.printf( "==> GUIModel buildDisplay...\n" ); worldDisplay = new Object2DDisplay( world ); dsurf = new DisplaySurface( this, "Agent Display" ); registerDisplaySurface( "Main Display", dsurf ); dsurf.addDisplayable( worldDisplay, "Agents"); addSimEventListener( dsurf ); // link to the other parts of the repast gui dsurf.display(); if ( rDebug > 0 ) System.out.printf( "<== GUIModel buildDisplay done.\n" ); } //////////////////////////////////////////////////////////////// // buildSchedule // // This builds the entire schedule, i.e., // - the base model step (calls stepReport) // - display steps. public void buildSchedule() { if ( rDebug > 0 ) System.out.printf( "==> GUIModel buildSchedule...\n" ); // schedule the current GUIModel's step() function // to execute every time step starting with time step 0 schedule.scheduleActionBeginning( 0, this, "step" ); // schedule the current GUIModel's processEndOfRun() // function to execute at the end of the run schedule.scheduleActionAtEnd( this, "processEndOfRun" ); } /////////////////////////////////////////////////////////////////////////////// // 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(); } // processEndOfRun // called once, at end of run. public void processEndOfRun ( ) { if ( rDebug > 0 ) System.out.printf("\n\n===== GUIModel processEndOfRun =====\n\n" ); applyAnyStoredChanges(); endReportFile(); this.fireStopSim(); } ///////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////// // **** NO NEEd TO CHANGE THE REST OF THIS ***** //////////////////////////////////////////////////////////////////// // main entry point public static void main( String[] args ) { uchicago.src.sim.engine.SimInit init = new uchicago.src.sim.engine.SimInit(); GUIModel model = new GUIModel(); //System.out.printf("==> GUIMOdel main...\n" ); // set the type of model class, this is necessary // so the parameters object knows whether or not // to do GUI related updates of panels,etc when a // parameter is changed model.setModelType("GUIModel"); // Do this to set the Update Probes option to true in the // Repast Actions panel Controller.UPDATE_PROBES = true; model.setCommandLineArgs( args ); init.loadModel( model, null, false ); // does setup() // this new function calls ProbeUtilities.updateProbePanels() and // ProbeUtilities.updateModelProbePanel() model.updateAllProbePanels(); } }