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 SimpleModel

    java.lang.Object
      uchicago.src.sim.engine.SimModelImpl
          uchicago.src.sim.engine.SimpleModel

All Implemented Interfaces:
  DescriptorContainer, SimEventProducer, SimModel

Direct Known Subclasses:
  AsynchAgentsModel, GeneticChangeModel, LifeModel, NeuralModel, RegressionOfficeModel

    public class SimpleModel

extends SimModelImpl

Encapsulates some simple model behavoir and hides the scheduling mechansim. Every time step of the simulation, SimpleModel will executes its preStep(), step() and postStep() methods. Classes that extends this class can provide the appropriate implementation of these methods. In addition, SimpleModel will execute the atPause and atEnd methods at a pause in or at the end of a simulation run.

If the protected ivar autoStep is true, then SimpleModel will executes preStep(), autoStep(), and postStep(). SimpleModel defines autoStep and child classes need only implement preStep() and postStep() if desired. autoStep() will optionaly shuffle the list of agents, and then call step() on each agent. Note that in the auto-step case, agents must implement the `Stepable` interface.

Child classes can make use of the following protected instance variables:

- name - the model's name.
- autoStep - whether the model should "autoStep" through the agents as described above.
- shuffle - whether the model should shuffle the list of agents before "autostepping".
- isGui - true if the model is running in gui mode, false if running in batch mode.

Version:
  $Revision: 1.12 $ $Date: 2004/11/03 19:50:57 $

Field Summary
`protected java.util.ArrayList` | `agentList`
`protected boolean` | `autoStep`
`protected boolean` | `isGui`
`protected java.lang.String` | `name`
`protected java.lang.String[]` | `params`
`protected Schedule` | `schedule`
`protected long` | `seed`
`protected boolean` | `shuffle`
`protected long` | `startAt`

Fields inherited from class uchicago.src.sim.engine.SimModelImpl
`descriptors, modelManipulator`

Constructor Summary
`SimpleModel()`

Method Summary
`void` | `atEnd()`
`void` | `atPause()`
`void` | `begin()` Begins a simulation run.
`void` | `buildModel()`
`void` | `buildSchedule()`
`java.lang.String[]` | `getInitParam()` Gets the names of the initial model parameters to set.
`java.lang.String` | `getName()` Gets the name of this model.
`double` | `getNextDoubleFromTo(double from, double to)` Returns the next random double between from and to, exclusive of from and to.
`int` | `getNextIntFromTo(int from, int to)` Returns the next random integer between from and to, inclusive of from and to.
`Schedule` | `getSchedule()` Gets the Schedule created by the model.
`protected void` | `postStep()`
`protected void` | `preStep()`
`void` | `run()`
`void` | `runAutoStep()`
`void` | `setRngSeed(long seed)` Sets the random number seed for this model, and recreates a uniform distribution with that seed.
`void` | `setStoppingTime(double time)` Sets the tick at which this model will stop.
`void` | `setStoppingTime(long time)` Sets the tick at which this model will stop.
`void` | `setup()` Prepares a model for a new run, typically by deallocating objects or setting them to some reasonable default.
`protected void` | `step()`

Methods inherited from class uchicago.src.sim.engine.SimModelImpl
`addPropertyListener, addSimEventListener, clearMediaProducers, clearPropertyListeners, fireBooleanPropertyEvent, fireEndSim, fireNumericPropertyEvent, fireObjectPropertyEvent, firePauseSim, fireSimEvent, fireStopSim, fireStringPropertyEvent, generateNewSeed, getController, getMediaProducers, getModelManipulator, getParameterDescriptors, getPropertiesValues, getRngSeed, getTickCount, pause, registerDisplaySurface, registerMediaProducer, removePropertyListener, removeSimEventListener, setController, stop`

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

Field Detail

### schedule

    protected Schedule schedule

### agentList

    protected java.util.ArrayList agentList

### name

    protected java.lang.String name

### params

    protected java.lang.String[] params

### autoStep

    protected boolean autoStep

### shuffle

    protected boolean shuffle

### seed

    protected long seed

### isGui

    protected boolean isGui

### startAt

    protected long startAt

Constructor Detail

### SimpleModel

    public SimpleModel()

Method Detail

### setStoppingTime

    public void setStoppingTime(long time)

  Sets the tick at which this model will stop.

### setStoppingTime

    public void setStoppingTime(double time)

  Sets the tick at which this model will stop.

### setup

    public void setup()

  Description copied from interface: `SimModel`
  Prepares a model for a new run, typically by deallocating objects or setting them to some reasonable default. Called whenever the setup button is clicked or if operating in batch mode whenever a single run has ended in preparation for the next. Also called when the model is first loaded.

### setRngSeed

    public void setRngSeed(long seed)

  Sets the random number seed for this model, and recreates a uniform distribution with that seed.

  Specified by:
    `setRngSeed` in interface `SimModel`
  Overrides:
    `setRngSeed` in class `SimModelImpl`
  Parameters:
    `seed` - the new rng seed
  See Also:
    `Random`

### getNextIntFromTo

    public int getNextIntFromTo(int from,
                                int to)

  Returns the next random integer between from and to, inclusive of from and to.

### getNextDoubleFromTo

    public double getNextDoubleFromTo(double from,
                                      double to)

  Returns the next random double between from and to, exclusive of from and to.

### begin

    public void begin()

  Description copied from interface: `SimModel`
  Begins a simulation run. All initialization, building the model, diplay, etc. should take place here. This method is called whenever the start button (or the step button if the run has not yet begun) is clicked. If running in batch mode this is called to kick off a new simulation run.

### getName

    public java.lang.String getName()

  Gets the name of this model.

  Returns:
    the name of the model/simulation

### getSchedule

    public Schedule getSchedule()

  Description copied from interface: `SimModel`
  Gets the Schedule created by the model.

  Returns:
    the schedule created by the model

### getInitParam

    public java.lang.String[] getInitParam()

  Description copied from interface: `SimModel`
  Gets the names of the initial model parameters to set. These names must have get and set methods supplied by the model. For example, for the parameter maxAge, the model must have getMaxAge and setMaxAge methods.

  Returns:
    a String[] of the initial parameter names

### buildModel

    public void buildModel()

### buildSchedule

    public void buildSchedule()

### atPause

    public void atPause()

### atEnd

    public void atEnd()

### runAutoStep

    public void runAutoStep()

### run

    public void run()

### preStep

    protected void preStep()

### step

    protected void step()

### postStep

    protected void postStep()

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