public class SimState
extends java.lang.Object
implements java.io.Serializable
A SimState contains the random number generator and the simulator's schedule. You should not change the schedule to another Schedule object.
When a simulation is begun, SimState's start() method is called. Then the schedule is stepped some N times. Last, the SimState's finish() method is called, and the simulation is over.
SimStates are serializable; if you wish to be able to checkpoint your simulation and read from checkpoints, you should endeavor to make all objects in the simulation serializable as well. Prior to serializing to a checkpoint, preCheckpoint() is called. Then after serialization, postCheckpoint() is called. When a SimState is loaded from a checkpoint, awakeFromCheckpoint() is called to give you a chance to make any adjustments. SimState also implements several methods which call these methods and then serialize the SimState to files and to streams.
SimState also maintains a private registry of AsynchronousSteppable objects, and handles pausing and resuming them during the checkpointing process, and killing them during finish() in case they had not completed yet.
If you override any of the methods foo() in SimState, should remember to always call super.foo() for any such method foo().
Modifier and Type | Field and Description |
---|---|
MersenneTwisterFast |
random
The SimState's random number generator
|
Schedule |
schedule
SimState's schedule
|
Modifier | Constructor and Description |
---|---|
|
SimState(long seed)
Creates a SimState with a new random number generator initialized to the given seed,
plus a new, empty schedule.
|
protected |
SimState(long seed,
Schedule schedule)
Creates a SimState with the schedule, creating a new random number generator.
|
protected |
SimState(MersenneTwisterFast random)
Creates a SimState with a new schedule, the provided random number generator,
and a bogus seed (0).
|
protected |
SimState(MersenneTwisterFast random,
Schedule schedule)
Creates a SimState with the given random number generator and schedule, and
sets the seed to a bogus value (0).
|
Modifier and Type | Method and Description |
---|---|
boolean |
addToAsynchronousRegistry(AsynchronousSteppable stop)
Registers an AsynchronousSteppable to get its pause() method called prior to checkpointing,
its resume() method to be called after checkpointing or recovery, and its stop()
method to be called at finish() time.
|
AsynchronousSteppable[] |
asynchronousRegistry()
Returns all the AsynchronousSteppable items presently in the registry.
|
void |
awakeFromCheckpoint()
Called after the SimState was created by reading from a checkpointed object.
|
static void |
doLoop(java.lang.Class c,
java.lang.String[] args)
Calls doLoop(MakesSimState,args), passing in a MakesSimState which creates
SimStates of the provided Class c, using the constructor new
|
static void |
doLoop(MakesSimState generator,
java.lang.String[] args)
A convenient top-level loop for the simulation command-line.
|
void |
finish()
Called either at the proper or a premature end to the simulation.
|
long |
job()
Returns the job number set by the doLoop(...) facility.
|
void |
kill()
A Steppable on the schedule can call this method to cancel the simulation.
|
void |
nameThread()
Deprecated.
|
void |
postCheckpoint()
Called just after the SimState was checkpointed (serialized out to a file to be
unserialized and fired up at a future time).
|
void |
postSchedule()
Hook for distributed MASON, called immediately after stepping the schedule.
|
void |
preCheckpoint()
Called just before the SimState is being checkpointed (serialized out to a file to be
unserialized and fired up at a future time).
|
void |
preSchedule()
Hook for distributed MASON, called immediately before stepping the schedule.
|
static MersenneTwisterFast |
primeGenerator(MersenneTwisterFast generator)
Primes the generator.
|
static void |
printlnSynchronized(java.lang.String val) |
static SimState |
readFromCheckpoint(java.io.File file)
Creates a SimState from checkpoint.
|
static SimState |
readFromCheckpoint(java.io.InputStream stream)
Creates and returns a new SimState object read in from the provided stream.
|
void |
removeFromAsynchronousRegistry(AsynchronousSteppable stop)
Unregisters an AsynchronousSteppable from the asynchronous registry.
|
long |
seed()
Returns the seed set by the doLoop(...) facility and by the constructor.
|
void |
setJob(long job) |
void |
setSeed(long seed) |
void |
start()
Called immediately prior to starting the simulation, or in-between
simulation runs.
|
static double |
version()
Returns MASON's Version
|
SimState |
writeToCheckpoint(java.io.File file)
Writes the state to a checkpoint and returns the state.
|
void |
writeToCheckpoint(java.io.OutputStream stream)
Serializes out the SimState, and the entire simulation state (not including the graphical interfaces)
to the provided stream.
|
public MersenneTwisterFast random
public Schedule schedule
public SimState(long seed)
protected SimState(MersenneTwisterFast random, Schedule schedule)
protected SimState(long seed, Schedule schedule)
protected SimState(MersenneTwisterFast random)
public void setSeed(long seed)
public static MersenneTwisterFast primeGenerator(MersenneTwisterFast generator)
public void start()
public void finish()
public void kill()
public boolean addToAsynchronousRegistry(AsynchronousSteppable stop)
An AsynchronousSteppable cannot be added multiple times to the same registry -- if it's there it's there. Returns false if the AsynchronousSteppable could not be added, either because the simulation is stopped or in the process of finish()ing.
public void removeFromAsynchronousRegistry(AsynchronousSteppable stop)
public AsynchronousSteppable[] asynchronousRegistry()
public void preCheckpoint()
public void postCheckpoint()
public void awakeFromCheckpoint()
public void writeToCheckpoint(java.io.OutputStream stream) throws java.io.IOException
java.io.IOException
public SimState writeToCheckpoint(java.io.File file)
public static SimState readFromCheckpoint(java.io.File file)
public static SimState readFromCheckpoint(java.io.InputStream stream) throws java.io.IOException, java.lang.ClassNotFoundException, java.io.OptionalDataException, java.lang.ClassCastException
java.io.IOException
java.lang.ClassNotFoundException
java.io.OptionalDataException
java.lang.ClassCastException
public long seed()
public void setJob(long job)
public long job()
public static void doLoop(java.lang.Class c, java.lang.String[] args)
public static void doLoop(MakesSimState generator, java.lang.String[] args)
public static void printlnSynchronized(java.lang.String val)
public void nameThread()
public static double version()
public void preSchedule()
public void postSchedule()