Sim
Class Simulation

java.lang.Object
  extended by Sim.Simulation

public class Simulation
extends java.lang.Object

Simulation is the core of the discrete event simulation. It holds the current simulation time and all of the events. Events are scheduled through the scheduleEvent(double, SimulationEvent) method.

The Simulation also provides the common source of randomness, so that runs of the same Simulation can be reproducable.


Constructor Summary
Simulation(SimulationParameters p)
          Constructs a new Simulation with the given parameters.
 
Method Summary
 void cancelEvents(java.lang.Class eventType)
          Cancels all events in the Simulation that match a certain type.
 java.lang.String getName()
          Returns the name of this Simulation.
 SimulationParameters getParams()
          Returns global simulation parameters that are set at the beginning of the simulation and never change throughout the execution.
 java.util.Random getRng()
          Returns the source of randomness for this Simulation.
 double getTime()
          Returns the current simulation time, which can stand still but never go backwards.
 World getWorld()
          Returns the World associated with this Simulation.
 boolean next()
          Performs the next event in this Simulation.
 void scheduleEvent(double t, SimulationEvent event)
          Schedules a new event to take place in the future.
 void setName(java.lang.String name)
          Sets this Simulation's name
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Simulation

public Simulation(SimulationParameters p)
Constructs a new Simulation with the given parameters.

Parameters:
p - non-null SimulationParameters
Method Detail

getWorld

public World getWorld()
Returns the World associated with this Simulation.

Returns:
non-null World

getRng

public java.util.Random getRng()
Returns the source of randomness for this Simulation.


getParams

public SimulationParameters getParams()
Returns global simulation parameters that are set at the beginning of the simulation and never change throughout the execution.


getName

public java.lang.String getName()
Returns the name of this Simulation. The default name for a Simulation is "Sim".


setName

public void setName(java.lang.String name)
Sets this Simulation's name


next

public boolean next()
Performs the next event in this Simulation. After processing a single event, returns true or false depending if there are more events. If there were no events to process, then false is returned and the simulation time is not modified.

Returns:
true if there are any more events to process, or false otherwise.

getTime

public double getTime()
Returns the current simulation time, which can stand still but never go backwards. A Simulation starts with the time equal to 0.


cancelEvents

public void cancelEvents(java.lang.Class eventType)
Cancels all events in the Simulation that match a certain type.

Parameters:
eventType - non-null event type class

scheduleEvent

public void scheduleEvent(double t,
                          SimulationEvent event)
Schedules a new event to take place in the future. Once an event has been scheduled, it cannot be cancelled or rescheduled.

Parameters:
t - event time greater than or equal to the current simulation time
event - non-null SimulationEvent