|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectuchicago.src.sim.engine.SimModelImpl
uchicago.src.repastdemos.mousetrap.MouseTrapModel
public class MouseTrapModel
A port of the mousetrap simulation from the Swarm simulation toolkit. This is a good example of dynamic scheduling and how to do discrete-event simulations using Schedule objects.
The simulation is as follows. A torus is populated with "mousetraps." These traps each contain some n number of balls. A ball is thrown from the "outside" onto the center mousetrap. This trap triggers and throws its n number of balls into the air. These balls then trigger other traps and so on and so on. In terms of implementation, the first trap has its trigger method scheduled at 0 with Schedule.scheduleActionAt. When a mousetrap is triggered it schedules a trigger method on n of its surrounding mousetraps, where n is the number of balls each mousetrap holds. The actual scheduling is done through the use of a TriggerAction class that extends BasicAction. This TriggerAction is passed the MouseTrap to schedule in its constructor, and its execute method calls trigger on this MouseTrap. See the source for details.
| Field Summary |
|---|
| Fields inherited from class uchicago.src.sim.engine.SimModelImpl |
|---|
descriptors, modelManipulator |
| Constructor Summary | |
|---|---|
MouseTrapModel()
|
|
| Method Summary | |
|---|---|
void |
addOneBall()
|
void |
addOneTriggered()
|
void |
begin()
Begins a simulation run. |
int |
getGridSize()
|
java.lang.String[] |
getInitParam()
Gets the names of the initial model parameters to set. |
int |
getMaxTriggerDistance()
|
int |
getMaxTriggerTime()
|
java.lang.String |
getName()
Gets the name of the model/simulation. |
int |
getNumBalls()
|
int |
getNumBallsInAir()
|
int |
getNumTriggered()
|
Schedule |
getSchedule()
Gets the Schedule created by the model. |
double |
getTrapDensity()
|
double |
getTriggerProbability()
|
static void |
main(java.lang.String[] args)
|
void |
removeOneBall()
|
void |
scheduleTrigger(double time,
MouseTrap mt)
|
void |
setGridSize(int size)
|
void |
setMaxTriggerDistance(int distance)
|
void |
setMaxTriggerTime(int time)
|
void |
setNumBalls(int balls)
|
void |
setTrapDensity(double density)
|
void |
setTriggerProbability(double prob)
|
void |
setup()
Prepares a model for a new run, typically by deallocating objects or setting them to some reasonable default. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public MouseTrapModel()
| Method Detail |
|---|
public void scheduleTrigger(double time,
MouseTrap mt)
public int getNumBalls()
public void setNumBalls(int balls)
public double getTriggerProbability()
public void setTriggerProbability(double prob)
public int getGridSize()
public void setGridSize(int size)
public int getMaxTriggerDistance()
public void setMaxTriggerDistance(int distance)
public int getMaxTriggerTime()
public void setMaxTriggerTime(int time)
public double getTrapDensity()
public void setTrapDensity(double density)
public java.lang.String[] getInitParam()
SimModel
public Schedule getSchedule()
SimModel
public java.lang.String getName()
SimModel
public void begin()
SimModel
public void setup()
SimModel
public int getNumTriggered()
public int getNumBallsInAir()
public void addOneTriggered()
public void addOneBall()
public void removeOneBall()
public static void main(java.lang.String[] args)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||