yass.simulation
Class Simulator

java.lang.Object
  extended by yass.simulation.Simulator
Direct Known Subclasses:
PeriodicSimulator

public abstract class Simulator
extends java.lang.Object

Simulator framework component in which a given simulation scenario can be simulated until such time as all completion criteria are met.


Field Summary
protected  java.util.Set<CompletionCriterion> completionCriteria
          The criteria which must be satisfied before simulation activity can end
protected  Simulation simulation
          The current simulation state
 
Constructor Summary
protected Simulator(Simulation simulation, java.util.Set<CompletionCriterion> completionCriteria)
          Constructs a new instance of Simulator with the specified simulation state and completion criteria set (which can be empty)
 
Method Summary
 void addCompletionCriterion(CompletionCriterion criterion)
          Adds the specified completion criterion to those which must be satisfied prior to conclusion of simulation activity
abstract  void executeNextIteration()
          Executes the next iteration of the simulation, which should bring the simulation state closer to satisfying the registered simulation completion criteria.
 java.util.Set<CompletionCriterion> getCompletionCriteria()
          Obtains the set of simulation completion criteria
 Simulation getSimulation()
          Obtains the current simulation state
 void initialise()
          Initialises the simulator.
 boolean isComplete()
          Determines if the current simulation state satisfies all criteria for cessation of simulation activity.
 void removeCompletionCriterion(CompletionCriterion criterion)
          Removes the specified completion criterion from those which must be satisfied prior to conclusion of simulation activity
 void tidyup()
          Tidies up the simulator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

completionCriteria

protected java.util.Set<CompletionCriterion> completionCriteria
The criteria which must be satisfied before simulation activity can end


simulation

protected Simulation simulation
The current simulation state

Constructor Detail

Simulator

protected Simulator(Simulation simulation,
                    java.util.Set<CompletionCriterion> completionCriteria)
Constructs a new instance of Simulator with the specified simulation state and completion criteria set (which can be empty)

Parameters:
completionCriteria - the criteria by which simulation completion is to be judged
simulation - the simulation state
Method Detail

executeNextIteration

public abstract void executeNextIteration()
                                   throws SimulationException
Executes the next iteration of the simulation, which should bring the simulation state closer to satisfying the registered simulation completion criteria. It is required that the simulation state be initialised prior to the first call of executeNextIteration()

Throws:
SimulationException - if a problem is encountered while updating the simulation state

isComplete

public boolean isComplete()
Determines if the current simulation state satisfies all criteria for cessation of simulation activity. If no completion criteria are specified, it is assumed that simulation is complete. Otherwise, all registered completion criteria must be satisfied simultaneously for the simulation to be considered complete.

Returns:
true if simulation is complete, otherwise false

initialise

public void initialise()
                throws SimulationException
Initialises the simulator. Override this method if the default implementation is inadequate for the requirements of the concrete implementing class, and call super.initialise().

Throws:
SimulationException - if the simulation state cannot be initialised

tidyup

public void tidyup()
            throws SimulationException
Tidies up the simulator. Call this method after the final simulation thread has finished useful work, but before the final simulation thread terminates. Override this method if the default implementation is inadequate for the requirements of the concrete implementing class, and call super.tidyup().

Throws:
SimulationException - if tidyup cannot be completed

addCompletionCriterion

public void addCompletionCriterion(CompletionCriterion criterion)
Adds the specified completion criterion to those which must be satisfied prior to conclusion of simulation activity

Parameters:
criterion - the completion criterion

removeCompletionCriterion

public void removeCompletionCriterion(CompletionCriterion criterion)
Removes the specified completion criterion from those which must be satisfied prior to conclusion of simulation activity

Parameters:
criterion - the completion criterion

getCompletionCriteria

public java.util.Set<CompletionCriterion> getCompletionCriteria()
Obtains the set of simulation completion criteria

Returns:
the set of simulation completion criteria

getSimulation

public Simulation getSimulation()
Obtains the current simulation state

Returns:
the current simulation state