Class RunController

Object
RunController

class RunController extends Object
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

    Fields
    Modifier and Type
    Field
    Description
    private double
    Starting time of CPU sampling (negative if not sampling).
    private double
    Mean time of CPU sampling.
    private int
    Number of CPU time samples.
    private double
    Variance of time of CPU sampling.
    protected int
    Delay between subsequent updates in milliseconds when model is running.
    private boolean
    Flag to indicate if a backstep is in progress.
    private final EvoLudo
    Engine whose execution is coordinated by this controller.
    protected List<RunListener>
    List of listeners that are notified about model run state changes.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new RunController for the specified EvoLudo engine.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addListener(RunListener newListener)
    Add a run listener to the list of listeners that get notified about model run state changes.
    void
    Advances the EvoLudo model by a single debugging step.
    void
    Decrease delay between updates.
    protected void
    Complete a CPU sampling measurement and log aggregated statistics.
    void
    Called after the model has been re-initialized.
    void
    Called after the model completed its relaxation.
    void
    Called after the model has been reset.
    void
    Called whenever the model starts its calculations.
    void
    Called after the population has reached an absorbing state (or has converged to an equilibrium state).
    void
    Called whenever the settings of the model have changed.
    int
    Get current delay between updates.
    void
    Increase delay between updates.
    void
    Initialize all populations and notify listeners.
    void
    modelInit(boolean quiet)
    Initialize all populations and optionally notify listeners.
    boolean
    Advance model by one step and notify listeners when done.
    boolean
    modelNextDone(boolean cont)
    Called after model next step finished to handle continuation or stop.
    boolean
    Relax the model and notify listeners.
    boolean
    modelRelax(boolean quiet)
    Relax the model and optionally notify listeners.
    void
    Reset all populations and notify listeners.
    void
    modelReset(boolean quiet)
    Reset all populations and optionally notify listeners.
    void
    Attempts to backtrack a single step of the EvoLudo model.
    (package private) boolean
    Process change of mode request.
    (package private) void
    Helper method for handling model changed events and processing pending actions.
    void
    removeListener(RunListener obsoleteListener)
    Remove the run listener from the list of listeners that get notified when the model run state changes.
    void
    Requests a ChangeListener.PendingAction to be processed on the next opportunity.
    void
    Requests a ChangeListener.PendingAction to be processed on the next opportunity.
    protected void
    Reset collected CPU sampling statistics.
    void
    setDelay(int delay)
    Set delay between updates.
    protected void
    Start a CPU sampling measurement if no sample is active.
    void
    Start or stop EvoLudo model.
    void
    Requests halting of a running Model on the next opportunity.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • engine

      private final EvoLudo engine
      Engine whose execution is coordinated by this controller.
    • delay

      protected int delay
      Delay between subsequent updates in milliseconds when model is running.
    • doPrev

      private boolean doPrev
      Flag to indicate if a backstep is in progress.
    • cpu

      private double cpu
      Starting time of CPU sampling (negative if not sampling).
    • cpuMean

      private double cpuMean
      Mean time of CPU sampling.
    • cpuVar

      private double cpuVar
      Variance of time of CPU sampling.
    • cpuSamples

      private int cpuSamples
      Number of CPU time samples.
    • runListeners

      protected List<RunListener> runListeners
      List of listeners that are notified about model run state changes.
  • Constructor Details

    • RunController

      public RunController(EvoLudo engine)
      Constructs a new RunController for the specified EvoLudo engine.
      Parameters:
      engine - the EvoLudo engine instance to be controlled by this RunController
  • Method Details

    • addListener

      public void addListener(RunListener newListener)
      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

      public void removeListener(RunListener obsoleteListener)
      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 registered RunListeners.
      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 registered RunListeners.
      See Also:
    • fireModelInit

      public void fireModelInit()
      Called after the model has been re-initialized. Notifies all registered RunListeners.
      See Also:
    • fireModelReset

      public void fireModelReset()
      Called after the model has been reset. Notifies all registered RunListeners.
      See Also:
    • fireModelRelaxed

      public void fireModelRelaxed()
      Called after the model completed its relaxation. Notifies all registered RunListeners.
      See Also:
    • fireModelStopped

      public void fireModelStopped()
      Called after the population has reached an absorbing state (or has converged to an equilibrium state). Notifies all registered RunListeners.
      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

      public void stop()
      Requests halting of a running Model on the next opportunity.
      See Also:
    • 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

      public void requestAction(ChangeListener.PendingAction action)
      Requests a ChangeListener.PendingAction to be processed on the next opportunity.
      Parameters:
      action - the action requested
      See Also:
    • requestAction

      public void requestAction(ChangeListener.PendingAction action, boolean now)
      Requests a ChangeListener.PendingAction to be processed on the next opportunity.
      Parameters:
      action - the action requested
      now - true to processes action immediately
      See Also:
    • processPendingAction

      void processPendingAction()
      Helper method for handling model changed events and processing pending actions.
      See Also:
    • processChangeMode

      boolean processChangeMode(ChangeListener.PendingAction action)
      Process change of mode request.
      Parameters:
      action - the pending action
      Returns:
      true if 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 to true to 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 to true to skip notifying listeners
      See Also:
    • modelRelax

      public boolean modelRelax()
      Relax the model and notify listeners.
      Returns:
      true if converged
      See Also:
    • modelRelax

      public boolean modelRelax(boolean quiet)
      Relax the model and optionally notify listeners.
      Parameters:
      quiet - set to true to skip notifying listeners
      Returns:
      true if converged
      See Also:
    • modelNext

      public boolean modelNext()
      Advance model by one step and notify listeners when done.
      Returns:
      true if 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 - false if converged or halting time reached
      Returns:
      true if 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.