uchicago.src.repastdemos.mousetrap
Class MouseTrapModel

java.lang.Object
  extended by uchicago.src.sim.engine.SimModelImpl
      extended by uchicago.src.repastdemos.mousetrap.MouseTrapModel
All Implemented Interfaces:
DescriptorContainer, SimEventProducer, SimModel

public class MouseTrapModel
extends SimModelImpl

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.

Version:
$Revision: 1.1 $ $Date: 2005/08/12 20:04:58 $
Author:
Nick Collier (Modified by Michael J. North)

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 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, setRngSeed, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MouseTrapModel

public MouseTrapModel()
Method Detail

scheduleTrigger

public void scheduleTrigger(double time,
                            MouseTrap mt)

getNumBalls

public int getNumBalls()

setNumBalls

public void setNumBalls(int balls)

getTriggerProbability

public double getTriggerProbability()

setTriggerProbability

public void setTriggerProbability(double prob)

getGridSize

public int getGridSize()

setGridSize

public void setGridSize(int size)

getMaxTriggerDistance

public int getMaxTriggerDistance()

setMaxTriggerDistance

public void setMaxTriggerDistance(int distance)

getMaxTriggerTime

public int getMaxTriggerTime()

setMaxTriggerTime

public void setMaxTriggerTime(int time)

getTrapDensity

public double getTrapDensity()

setTrapDensity

public void setTrapDensity(double density)

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

getSchedule

public Schedule getSchedule()
Description copied from interface: SimModel
Gets the Schedule created by the model.

Returns:
the schedule created by the model

getName

public java.lang.String getName()
Description copied from interface: SimModel
Gets the name of the model/simulation.

Returns:
the name of the model/simulation

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.


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.


getNumTriggered

public int getNumTriggered()

getNumBallsInAir

public int getNumBallsInAir()

addOneTriggered

public void addOneTriggered()

addOneBall

public void addOneBall()

removeOneBall

public void removeOneBall()

main

public static void main(java.lang.String[] args)