Class SimModel

java.lang.Object
  |
  +--SimModel

public class SimModel
extends java.lang.Object

A SimModel is a basic simulation framework for simulations of collections of objects. SimThings can be added to the model, and SimViewers can ask to be notified regularly so they can display the world.

The simulation repeats the following cycle as many times as requested:
Birth - anything added to the simulation on the previous cycle is added to the world.
Action - all SimThings are asked to perform their action() method in some unpredictable order.
View - all SimViewers are notified

The birth and action operations are separated so new things added to the simulation in the middle of one cycle don't affect other actions on the same cycle (i.e., all actions on one cycle should be carried out with the existing population of things, without newly created things interacting with old ones in unexpected ways). Based on simulation framework developed by Ben Dugan for CSE142/3. Simplified to illustrate key points. CSE143 demo Au01, Sp03

Version:
10/18/01, 4/16/03
Author:
Hal Perkins

Constructor Summary
SimModel()
          Constructor for objects of class SimModel
 
Method Summary
 void add(SimThing t)
          Add the given SimThing to the world after this cycle is complete.
 void addView(SimView v)
          Add the given SimView to the list of viewers to be notified each cycle.
 java.util.List getThings()
          Return a copy of the list of Things in the simulation at the beginning of the current cycle.
 void go()
          Run the simulation indefinitey
 void go(int nCycles)
          Run the simulation for the requested number of cycles
 void pause()
          Pause the simulation
 void resume()
          Resume the simulation
 void stop()
          Stop the simulation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimModel

public SimModel()
Constructor for objects of class SimModel

Method Detail

add

public void add(SimThing t)
Add the given SimThing to the world after this cycle is complete.

Parameters:
t - the SimThing to be added

addView

public void addView(SimView v)
Add the given SimView to the list of viewers to be notified each cycle.

Parameters:
v - the new viewer

getThings

public java.util.List getThings()
Return a copy of the list of Things in the simulation at the beginning of the current cycle.

Returns:
a new list with a copy of all things currently in the simulation

go

public void go()
Run the simulation indefinitey


go

public void go(int nCycles)
Run the simulation for the requested number of cycles

Parameters:
nCycles - number of cycles to run

pause

public void pause()
Pause the simulation


resume

public void resume()
Resume the simulation


stop

public void stop()
Stop the simulation



Generated by BlueJ