public abstract class StochasticSimulator extends Object
performStep
which gets invoked as long as the simulation is running. They also may override
init
but should in that case call
super.init()
to avoid unwanted effects. Simulators also should handle the special time
theta
: is is a moment in time when
doThetaEvent
is supposed to be invoked (e.g. to measure species populations at this moment). Consider
this, if you want to implement a simulator.
Observer
can be registered at a simulator and observe certain aspects of the simulation (see the
Observer
s javadoc for more information).
Note that this class is NOT thread-safe. Consequently, if a simulation program uses multiple threads, it should
acquire a lock on a simulator (using a synchronized block) before accessing its state. Note however, that
one can launch many simulations in parallel with as many threads, as long as each thread has its
own Simulator.
This class is mostly copied from the FERN projects stochastic classes and modified to fit into this framework.http://www.bio.ifi.lmu.de/FERN/
Modifier and Type | Class and Description |
---|---|
private class |
StochasticSimulator.ThetaQueue
Manages the registered theta events.
|
Modifier and Type | Field and Description |
---|---|
private AmountManager |
amountManager |
private SimulationController |
controller |
private double |
currentTime |
private Set<Observer> |
observers |
protected boolean |
reverseTime |
private int |
startTime |
private StochasticSimulator.ThetaQueue |
thetaQueue |
private TransitionKernel |
transitionKernel |
Constructor and Description |
---|
StochasticSimulator(AmountManager amountManager,
TransitionKernel transitionKernel)
Creates a new simulator using a given amount manager.
|
StochasticSimulator(AmountManager amountManager,
TransitionKernel transitionKernel,
boolean reverseTime)
Creates a new simulator.
|
Modifier and Type | Method and Description |
---|---|
void |
addObserver(Observer observer)
Add an observer to the engines list of observers.
|
protected void |
doEvent(SimulationEvent mu,
double t)
Fires a reaction.
|
protected void |
doEvent(SimulationEvent event,
double t,
int n)
Perform an event by informing the subscribed observers and the amountManager.
|
protected void |
doThetaEvent()
Gets called when the simulator reaches the predetermined time of a theta event.
|
Observer |
getDefaultObserver()
Get the default observer for the stochastic process.
|
abstract String |
getName()
Gets the name of the algorithm.
|
double |
getNextThetaEventTime()
Theta defines a moment, where the simulator has to invoke theta of a observers.
|
void |
init()
Initializes the algorithm.
|
abstract void |
performStep()
Performs one simulation step.
|
void |
registerNewTheta(Observer obs,
double thetaTime,
Object event)
Register a new theta event that is triggered at a given time.
|
abstract void |
reinitialize()
Reset propensities when a event has been executed.
|
void |
run()
Start the simulation with the given
SimulationController . |
void |
run(double time)
Starts the simulation up to a given time.
|
abstract void |
setRngSeed(int seed)
Seed the RNG if required.
|
private int startTime
private TransitionKernel transitionKernel
private AmountManager amountManager
private double currentTime
private SimulationController controller
private StochasticSimulator.ThetaQueue thetaQueue
protected boolean reverseTime
public StochasticSimulator(AmountManager amountManager, TransitionKernel transitionKernel)
amountManager
- the amount manager used in the simulator.transitionKernel
- the transition kernel to be used with the stochastic solver.public StochasticSimulator(AmountManager amountManager, TransitionKernel transitionKernel, boolean reverseTime)
amountManager
- the amount manager used in the simulator.transitionKernel
- the transition kernel to be used with the stochastic solver.reverseTime
- true if we wish to go backwards in time.public final void run(double time)
DefaultController
and calls
StochasticSimulator#start(SimulationController)
.time
- simulation timepublic final void run()
SimulationController
.public final void init()
AmountManager
start
protected final void doEvent(SimulationEvent mu, double t)
AmountManager
.mu
- reaction to be fired.t
- time at which the firing occurs.protected final void doEvent(SimulationEvent event, double t, int n)
event
- event to be performed.t
- time at which the firing occurs.n
- the number of times mu is to be fired.protected final void doThetaEvent()
public final void addObserver(Observer observer)
observer
- the observer.public final double getNextThetaEventTime()
Simulator#doThetaEvent()
which basically calls the observers.public final void registerNewTheta(Observer obs, double thetaTime, Object event)
obs
- the observers which is registering.thetaTime
- the time the theta event occurs.event
- the theta event.public final Observer getDefaultObserver()
public abstract void reinitialize()
public abstract void performStep()
Simulator#setAmount(int, long)
and Simulator#setVolume(double)
if they need correct values!public abstract String getName()
public abstract void setRngSeed(int seed)
seed
- the RNG seed.Copyright © 2015 University of Glasgow. All rights reserved.