Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## uchicago.src.sim.engine
Class BaseController

    java.lang.Object
      uchicago.src.sim.engine.BaseController

All Implemented Interfaces:
  IController, SimEventListener, TickCounter

Direct Known Subclasses:
  AbstractGUIController, BatchController, ThinController

    public abstract class BaseController

extends java.lang.Object
implements SimEventListener, IController

Abstract base class implementing IController. This provides methods for controlling the execution of a SimModel, firing SimEvents and minimal parameter handling abilities. Child classes are expected to add more sophisticated parameter handling.

Version:
  $Revision: 1.28 $ $Date: 2002/11/25 16:37:33
Author:
  Nick Collier (Modified by Michael J. North)

Field Summary
`protected boolean` | `done` when true the simulation has stopped
`protected boolean` | `doStep` when true the simulation should execute all actions for the next tick and then pause.
`protected boolean` | `executeBegin` Tracks whether model.begin() has been called and so whether startSim should call model.begin().
`protected boolean` | `exitOnExit` Flag for whether the simulation should exit the JVM on exiting the simulation.
`protected boolean` | `go` when true the simulation runs, when false it stops
`protected boolean` | `isGui` true if this is a gui controller - i.e. toolbar is displayed
`protected java.util.ArrayList` | `listenerList` List of listeners listening for SimEvents broadcast by this BaseController.
`protected SimModel` | `model` the model (simulation) to run with this `BaseController`
`protected java.lang.Object` | `monitor` Monitor object used in guarded suspension pause check.
`protected ParameterSetter` | `params` Default model parameters read from a parameter file
`protected boolean` | `pauseActionsExecuted` true if the actions scheduled to be run when the simulation is paused have been run, false if not
`protected int` | `pauseAt`
`protected BasicAction` | `pauseAtAction`
`protected boolean` | `pauseSim` when true the sim pauses, when false it runs
`protected java.util.Hashtable` | `persistentObj` Persistent objects store.
`protected boolean` | `runFinished` when true a a single run of simulation has finished.
`protected java.lang.Thread` | `runThread` The actual run thread that runs the Runnable simRun
`protected Schedule` | `schedule` The master schedule
`protected java.lang.Runnable` | `simRun` The runnable that encapsulates the schedule and allows for threaded execution of the schedule
`protected int` | `sleepValue` The amount to pause while simRun is running, allowing other processing to occur.
`protected double` | `time` the tick count

Constructor Summary
`BaseController()` Constructs a BaseController.

Method Summary
`void` | `addSimEventListener(SimEventListener l)` Adds a SimEventListener to listen for SimEvents broadcast from this BaseController.
`protected void` | `beginModel()`
`void` | `fireSimEvent(SimEvent evt)` Fires a SimEvent to the registered listeners.
`int` | `getCellDepth()` Gets the display cell depth.
`int` | `getCellHeight()` Gets the display cell height.
`int` | `getCellWidth()` Gets the display cell width.
`double` | `getCurrentTime()` Gets the current simulation time (tick count) - the current number of execution cycles completed by main schedule.
`java.util.Hashtable` | `getDefaultModelParameters()` Gets a Hashtable of the default model parameters.
`boolean` | `getExitOnExit()` Gets whether the simulation application should exit with a System.exit(0) call on exit (pressing the exit button), or dispose of all windows, release the model without killing this instance of the virtual machine.
`SimModel` | `getModel()` Returns the SimModel currently associated with this BaseController.
`java.util.Hashtable` | `getModelParameters()` Deprecated. replaced by ParameterUtilities.#getModelProperties(SimModel)
`int` | `getPauseAt()`
`java.lang.Object` | `getPersistentObj(java.lang.Object key)` Gets a stored persistent (over the life of many runs) object.
`long` | `getRandomSeed()` Gets the current random seed for the current model
`Schedule` | `getSchedule()` Returns the Schedule associated with BaseController
`boolean` | `isBatch()` Is this a BatchController.
`protected void` | `notifyMonitor()` Notifies object monitor that controlls pausing.
`protected abstract void` | `onTickCountUpdate()` Called whenever the tick count is incremented.
`void` | `pauseSim()` Pauses the simulation
`void` | `putPersistentObj(java.lang.Object key, java.lang.Object val)` Allows for the storage of objects to persist beyond the life of a single run by objects that do not so persist.
`void` | `removeSimEventListener(SimEventListener l)` Removes a SimEventListener from the list of listeners listening for SimEvents broadcast from this BaseController.
`void` | `setCellDepth(int cellSize)` Sets the display cell depth.
`void` | `setCellHeight(int cellSize)` Sets the display cell height.
`void` | `setCellWidth(int cellSize)` Sets the display cell width.
`void` | `setExitOnExit(boolean val)` Sets whether the simulation application should exit with a System.exit(0) call on exit (pressing the exit button), or dispose of all windows, release the model without killing this instance of the virtual machine.
`void` | `setModel(SimModel model)` Sets the model associated with this controller.
`void` | `setPauseAt(int val)`
`void` | `setRandomSeed(long seed)` Sets the random seed for the current model.
`void` | `setSchedule(Schedule schedule)` Sets the schedule to be run by the controller.
`protected void` | `setupSchedule()` Sets up the schedule thread.
`void` | `startSim()` Starts the simulation.
`void` | `stopSim()` Stops the simulation.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Methods inherited from interface uchicago.src.sim.engine.SimEventListener
`simEventPerformed`

Methods inherited from interface uchicago.src.sim.engine.IController
`exitSim, getRunCount, isGUI`

Field Detail

### schedule

    protected Schedule schedule

  The master schedule

### simRun

    protected java.lang.Runnable simRun

  The runnable that encapsulates the schedule and allows for threaded execution of the schedule

### time

    protected double time

  the tick count

### runThread

    protected volatile java.lang.Thread runThread

  The actual run thread that runs the Runnable simRun

### go

    protected volatile boolean go

  when true the simulation runs, when false it stops

### pauseSim

    protected volatile boolean pauseSim

  when true the sim pauses, when false it runs

### done

    protected boolean done

  when true the simulation has stopped

### doStep

    protected volatile boolean doStep

  when true the simulation should execute all actions for the next tick and then pause.

### runFinished

    protected volatile boolean runFinished

  when true a a single run of simulation has finished. Used by the `BatchController`

### sleepValue

    protected int sleepValue

  The amount to pause while simRun is running, allowing other processing to occur.

### model

    protected SimModel model

  the model (simulation) to run with this `BaseController`

### pauseActionsExecuted

    protected boolean pauseActionsExecuted

  true if the actions scheduled to be run when the simulation is paused have been run, false if not

### isGui

    protected boolean isGui

  true if this is a gui controller - i.e. toolbar is displayed

### persistentObj

    protected java.util.Hashtable persistentObj

  Persistent objects store. For anything that might need to persist over the life of a batch run, although the object that created it may disappear.

### params

    protected ParameterSetter params

  Default model parameters read from a parameter file

### pauseAt

    protected int pauseAt

### executeBegin

    protected boolean executeBegin

  Tracks whether model.begin() has been called and so whether startSim should call model.begin().

### monitor

    protected java.lang.Object monitor

  Monitor object used in guarded suspension pause check.

### listenerList

    protected java.util.ArrayList listenerList

  List of listeners listening for SimEvents broadcast by this BaseController.

### exitOnExit

    protected boolean exitOnExit

  Flag for whether the simulation should exit the JVM on exiting the simulation.

### pauseAtAction

    protected BasicAction pauseAtAction

Constructor Detail

### BaseController

    public BaseController()

  Constructs a BaseController.

Method Detail

### setModel

    public void setModel(SimModel model)

  Sets the model associated with this controller.

  Specified by:
    `setModel` in interface `IController`
  Parameters:
    `model` - the model associated with this BaseController

### getModel

    public SimModel getModel()

  Returns the SimModel currently associated with this BaseController.

  Specified by:
    `getModel` in interface `IController`

### getCellWidth

    public int getCellWidth()

  Gets the display cell width. The display cell size is the size in pixels of the cells in which agents, environments and so forth are drawn.

  Returns:
    the display cell size

### setCellWidth

    public void setCellWidth(int cellSize)

  Sets the display cell width. The display cell size is the size in pixels of the cells in which agents, environments and so forth are drawn. Values between 5 and 50 work well depending on the size of the "space" being displayed.

  Parameters:
    `cellSize` - the new display cell size
  See Also:
    `getCellWidth()`

### getCellHeight

    public int getCellHeight()

  Gets the display cell height. The display cell size is the size in pixels of the cells in which agents, environments and so forth are drawn.

  Returns:
    the display cell size

### setCellHeight

    public void setCellHeight(int cellSize)

  Sets the display cell height. The display cell size is the size in pixels of the cells in which agents, environments and so forth are drawn. Values between 5 and 50 work well depending on the size of the "space" being displayed.

  Parameters:
    `cellSize` - the new display cell size
  See Also:
    `getCellHeight()`

### getCellDepth

    public int getCellDepth()

  Gets the display cell depth. The display cell size is the size in pixels of the cells in which agents, environments and so forth are drawn.

  Returns:
    the display cell size

### setCellDepth

    public void setCellDepth(int cellSize)

  Sets the display cell depth. The display cell size is the size in pixels of the cells in which agents, environments and so forth are drawn. Values between 5 and 50 work well depending on the size of the "space" being displayed.

  Parameters:
    `cellSize` - the new display cell size
  See Also:
    `getCellDepth()`

### setSchedule

    public void setSchedule(Schedule schedule)

  Sets the schedule to be run by the controller.

  Specified by:
    `setSchedule` in interface `IController`
  Parameters:
    `schedule` - the schedule to be run by this BaseController.
  See Also:
    `Schedule`

### getSchedule

    public Schedule getSchedule()

  Returns the Schedule associated with BaseController

  Specified by:
    `getSchedule` in interface `IController`

### getCurrentTime

    public double getCurrentTime()

  Gets the current simulation time (tick count) - the current number of execution cycles completed by main schedule.

  Specified by:
    `getCurrentTime` in interface `IController`
  Specified by:
    `getCurrentTime` in interface `TickCounter`
  Returns:
    the current simulation time

### onTickCountUpdate

    protected abstract void onTickCountUpdate()

  Called whenever the tick count is incremented. Allows subclasses to update a display, data point etc. when the tick count is updated.

### setRandomSeed

    public void setRandomSeed(long seed)

  Sets the random seed for the current model. The random number generator will be reset each time the model is run.

  Parameters:
    `seed` - the new random seed
  See Also:
    `SimModelImpl.setRngSeed(long)`

### getRandomSeed

    public long getRandomSeed()

  Gets the current random seed for the current model

### beginModel

    protected void beginModel()

### startSim

    public void startSim()

  Starts the simulation. Fires a START_EVENT before the simulation thread is actually started.

  Specified by:
    `startSim` in interface `IController`

### notifyMonitor

    protected void notifyMonitor()

  Notifies object monitor that controlls pausing.

### setupSchedule

    protected void setupSchedule()

  Sets up the schedule thread.

### getModelParameters

    public java.util.Hashtable getModelParameters()

  Deprecated. replaced by ParameterUtilities.#getModelProperties(SimModel)

  Gets the parameters of the current loaded model.

### getDefaultModelParameters

    public java.util.Hashtable getDefaultModelParameters()

  Gets a Hashtable of the default model parameters. The key is the parameter name, and the value is the default value. This is done in the BaseController heirarchy as parameters loaded from a file might effect this. Returns an empty `Hashtable` if no model has been loaded. Note that this creates no distinction between batch parameters that are dynamic and those that are constant.

  If any default values have been loaded from a file this will return those values. To get the current parameter values, use getModelParameters();

### pauseSim

    public void pauseSim()

  Pauses the simulation

  Specified by:
    `pauseSim` in interface `IController`

### stopSim

    public void stopSim()

  Stops the simulation.

  Specified by:
    `stopSim` in interface `IController`

### isBatch

    public boolean isBatch()

  Is this a BatchController. Returns false.

  Specified by:
    `isBatch` in interface `IController`

### addSimEventListener

    public void addSimEventListener(SimEventListener l)

  Adds a SimEventListener to listen for SimEvents broadcast from this BaseController.

  Specified by:
    `addSimEventListener` in interface `IController`
  Parameters:
    `l` - the SimEventListener to add
  See Also:
    `SimEventListener`

### removeSimEventListener

    public void removeSimEventListener(SimEventListener l)

  Removes a SimEventListener from the list of listeners listening for SimEvents broadcast from this BaseController.

  Specified by:
    `removeSimEventListener` in interface `IController`
  Parameters:
    `l` - the SimEventListener to remove.
  See Also:
    `SimEventListener`

### fireSimEvent

    public void fireSimEvent(SimEvent evt)

  Fires a SimEvent to the registered listeners.

  Parameters:
    `evt` - the SimEvent to fire

### putPersistentObj

    public void putPersistentObj(java.lang.Object key,
                                 java.lang.Object val)

  Allows for the storage of objects to persist beyond the life of a single run by objects that do not so persist.

  Specified by:
    `putPersistentObj` in interface `IController`
  Parameters:
    `key` - a unique identifier for the object to store
    `val` - the actual object to store

### getPersistentObj

    public java.lang.Object getPersistentObj(java.lang.Object key)

  Gets a stored persistent (over the life of many runs) object.

  Specified by:
    `getPersistentObj` in interface `IController`
  Parameters:
    `key` - the unique identifier for the persistent object

### setPauseAt

    public void setPauseAt(int val)

### getPauseAt

    public int getPauseAt()

### setExitOnExit

    public void setExitOnExit(boolean val)

  Sets whether the simulation application should exit with a System.exit(0) call on exit (pressing the exit button), or dispose of all windows, release the model without killing this instance of the virtual machine.

  Specified by:
    `setExitOnExit` in interface `IController`

### getExitOnExit

    public boolean getExitOnExit()

  Gets whether the simulation application should exit with a System.exit(0) call on exit (pressing the exit button), or dispose of all windows, release the model without killing this instance of the virtual machine.

  Specified by:
    `getExitOnExit` in interface `IController`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD