Class RunController
Object
RunController
Controller for managing the execution and lifecycle of EvoLudo model
simulations.
The RunController handles the runtime behavior of evolutionary
models,
including starting, stopping, stepping through simulations, and notifying
listeners
of model state changes. It manages the execution flow, timing, and
coordination
between the model and its observers.
Key responsibilities include:
- Managing simulation execution state (running, stopped, suspended)
- Controlling update delays and timing between simulation steps
- Handling model initialization, reset, and relaxation
- Supporting time reversal and debugging capabilities
- Notifying registered
RunListeners of state changes - Processing pending actions and mode changes
- Collecting CPU performance statistics
The controller operates in conjunction with an EvoLudo engine
instance
and supports various execution modes including dynamics simulation,
statistics
sampling, and step-by-step debugging.
- Author:
- Christoph Hauert
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate doubleStarting time of CPU sampling (negative if not sampling).private doubleMean time of CPU sampling.private intNumber of CPU time samples.private doubleVariance of time of CPU sampling.protected intDelay between subsequent updates in milliseconds when model is running.private booleanFlag to indicate if a backstep is in progress.private final EvoLudoEngine whose execution is coordinated by this controller.protected List<RunListener> List of listeners that are notified about model run state changes. -
Constructor Summary
ConstructorsConstructorDescriptionRunController(EvoLudo engine) Constructs a new RunController for the specified EvoLudo engine. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(RunListener newListener) Add a run listener to the list of listeners that get notified about model run state changes.voiddebug()Advances the EvoLudo model by a single debugging step.voidDecrease delay between updates.protected voidComplete a CPU sampling measurement and log aggregated statistics.voidCalled after the model has been re-initialized.voidCalled after the model completed its relaxation.voidCalled after the model has been reset.voidCalled whenever the model starts its calculations.voidCalled after the population has reached an absorbing state (or has converged to an equilibrium state).voidCalled whenever the settings of the model have changed.intgetDelay()Get current delay between updates.voidIncrease delay between updates.voidInitialize all populations and notify listeners.voidmodelInit(boolean quiet) Initialize all populations and optionally notify listeners.booleanAdvance model by one step and notify listeners when done.booleanmodelNextDone(boolean cont) Called after model next step finished to handle continuation or stop.booleanRelax the model and notify listeners.booleanmodelRelax(boolean quiet) Relax the model and optionally notify listeners.voidReset all populations and notify listeners.voidmodelReset(boolean quiet) Reset all populations and optionally notify listeners.voidprev()Attempts to backtrack a single step of the EvoLudo model.(package private) booleanProcess change of mode request.(package private) voidHelper method for handling model changed events and processing pending actions.voidremoveListener(RunListener obsoleteListener) Remove the run listener from the list of listeners that get notified when the model run state changes.voidRequests aChangeListener.PendingActionto be processed on the next opportunity.voidrequestAction(ChangeListener.PendingAction action, boolean now) Requests aChangeListener.PendingActionto be processed on the next opportunity.protected voidReset collected CPU sampling statistics.voidsetDelay(int delay) Set delay between updates.protected voidStart a CPU sampling measurement if no sample is active.voidStart or stop EvoLudo model.voidstop()Requests halting of a runningModelon the next opportunity.
-
Field Details
-
engine
Engine whose execution is coordinated by this controller. -
delay
protected int delayDelay between subsequent updates in milliseconds when model is running. -
doPrev
private boolean doPrevFlag to indicate if a backstep is in progress. -
cpu
private double cpuStarting time of CPU sampling (negative if not sampling). -
cpuMean
private double cpuMeanMean time of CPU sampling. -
cpuVar
private double cpuVarVariance of time of CPU sampling. -
cpuSamples
private int cpuSamplesNumber of CPU time samples. -
runListeners
List of listeners that are notified about model run state changes.
-
-
Constructor Details
-
RunController
Constructs a new RunController for the specified EvoLudo engine.- Parameters:
engine- the EvoLudo engine instance to be controlled by this RunController
-
-
Method Details
-
addListener
Add a run listener to the list of listeners that get notified about model run state changes.- Parameters:
newListener- the new run listener- See Also:
-
removeListener
Remove the run listener from the list of listeners that get notified when the model run state changes.- Parameters:
obsoleteListener- the listener to remove from list of run listeners- See Also:
-
fireModelRunning
public void fireModelRunning()Called whenever the model starts its calculations. Fires only when starting to run. Notifies all registeredRunListeners.- See Also:
-
fireSettingsChanged
public void fireSettingsChanged()Called whenever the settings of the model have changed. For example, to trigger the range of values or markers in the GUI. Notifies all registeredRunListeners.- See Also:
-
fireModelInit
public void fireModelInit()Called after the model has been re-initialized. Notifies all registeredRunListeners.- See Also:
-
fireModelReset
public void fireModelReset()Called after the model has been reset. Notifies all registeredRunListeners.- See Also:
-
fireModelRelaxed
public void fireModelRelaxed()Called after the model completed its relaxation. Notifies all registeredRunListeners.- See Also:
-
fireModelStopped
public void fireModelStopped()Called after the population has reached an absorbing state (or has converged to an equilibrium state). Notifies all registeredRunListeners.- See Also:
-
startStop
public void startStop()Start or stop EvoLudo model. If model is running wait until next update is completed to prevent unexpected side effects.- See Also:
-
stop
-
prev
public void prev()Attempts to backtrack a single step of the EvoLudo model.- See Also:
-
debug
public void debug()Advances the EvoLudo model by a single debugging step.- See Also:
-
requestAction
Requests aChangeListener.PendingActionto be processed on the next opportunity.- Parameters:
action- the action requested- See Also:
-
requestAction
Requests aChangeListener.PendingActionto be processed on the next opportunity.- Parameters:
action- the action requestednow-trueto processes action immediately- See Also:
-
processPendingAction
void processPendingAction()Helper method for handling model changed events and processing pending actions.- See Also:
-
processChangeMode
Process change of mode request.- Parameters:
action- the pending action- Returns:
trueif mode unchanged
-
modelReset
public void modelReset()Reset all populations and notify listeners.- See Also:
-
modelReset
public void modelReset(boolean quiet) Reset all populations and optionally notify listeners.- Parameters:
quiet- set totrueto skip notifying listeners- See Also:
-
modelInit
public void modelInit()Initialize all populations and notify listeners.- See Also:
-
modelInit
public void modelInit(boolean quiet) Initialize all populations and optionally notify listeners.- Parameters:
quiet- set totrueto skip notifying listeners- See Also:
-
modelRelax
public boolean modelRelax()Relax the model and notify listeners.- Returns:
trueif converged- See Also:
-
modelRelax
public boolean modelRelax(boolean quiet) Relax the model and optionally notify listeners.- Parameters:
quiet- set totrueto skip notifying listeners- Returns:
trueif converged- See Also:
-
modelNext
public boolean modelNext()Advance model by one step and notify listeners when done.- Returns:
trueif the model should continue- See Also:
-
modelNextDone
public boolean modelNextDone(boolean cont) Called after model next step finished to handle continuation or stop.- Parameters:
cont-falseif converged or halting time reached- Returns:
trueif the model should continue- See Also:
-
setDelay
public void setDelay(int delay) Set delay between updates.- Parameters:
delay- in milliseconds- See Also:
-
getDelay
public int getDelay()Get current delay between updates.- Returns:
- delay in milliseconds
- See Also:
-
increaseDelay
public void increaseDelay()Increase delay between updates.- See Also:
-
decreaseDelay
public void decreaseDelay()Decrease delay between updates.- See Also:
-
resetCPUSample
protected void resetCPUSample()Reset collected CPU sampling statistics. -
startCPUSample
protected void startCPUSample()Start a CPU sampling measurement if no sample is active. -
endCPUSample
protected void endCPUSample()Complete a CPU sampling measurement and log aggregated statistics.
-