Class DefaultController

java.lang.Object
repast.simphony.engine.controller.DefaultController
All Implemented Interfaces:
Controller, IAction

public class DefaultController extends Object implements Controller
A default implementation of a Controller. This performs all the functionality specified in the Controller interface.
Author:
Jerry Vos
  • Constructor Details

    • DefaultController

      public DefaultController(RunEnvironmentBuilder runEnvironmentBuilder)
      TODO: fill this in
      Parameters:
      runEnvironmentBuilder -
    • DefaultController

      public DefaultController(RunEnvironmentBuilder runEnvironmentBuilder, int runNumber)
  • Method Details

    • setControllerRegistry

      public void setControllerRegistry(ControllerRegistry controllerRegistry)
      Sets the registry of ControllerActions that the controller will run.
      Specified by:
      setControllerRegistry in interface Controller
      Parameters:
      controllerRegistry - a registry used to find actions to run
    • getControllerRegistry

      public ControllerRegistry getControllerRegistry()
      Retrieves the registry of ControllerActions that the controller will run.
      Specified by:
      getControllerRegistry in interface Controller
      Returns:
      a registry used to find actions to run
    • setScheduleRunner

      public void setScheduleRunner(Runner scheduleRunner)
      Sets the ScheduleRunner that will be used to execute the model's schedule found through the RunState. This is used in the execute() phase of the controller.
      Specified by:
      setScheduleRunner in interface Controller
      Parameters:
      scheduleRunner - the ScheduleRunner that will execute the model's schedule
    • getScheduleRunner

      public Runner getScheduleRunner()
      Description copied from interface: Controller
      Gets the ScheduleRunner that will be used to execute the model's schedule found through the RunState. This is used in the execute() phase of the controller.
      Specified by:
      getScheduleRunner in interface Controller
      Returns:
      the ScheduleRunner that will be used to execute the model's schedule.
    • batchCleanup

      public void batchCleanup(RunState runState, Object contextId)
      Calls the batchCleanup method on all the actions this registry contains, with runState as an argument.
      Parameters:
      runState - the state to pass to the actions
    • runCleanup

      public void runCleanup(RunState runState, Object contextId)
      Calls the runCleanup method on all the actions this registry contains, with runState as an argument.
      Parameters:
      runState - the state to pass to the actions
    • execute

      public void execute(RunState toExecuteOn)
      Executes the specified RunState with the ScheduleRunner.
      Parameters:
      toExecuteOn - the RunState to execute
      See Also:
    • execute

      public void execute()
      Executes the current RunState of the controller. The current RunState is created when the batchInitialize() or runInitialize(repast.simphony.parameter.Parameters) methods are called.
      Specified by:
      execute in interface IAction
    • batchInitialize

      public void batchInitialize()
      Calls the runInitialize method of this class with all the contexts in the controller registry in the order they are returned by that registry.

      This will prepare the controller, creating a new run state object for the next set of runs (batch or not) if the RunState has been invalidated. Calling the batchCleanup() or cleanup() method is required to invalidate the RunState in prepartion for another set of runs.

      Specified by:
      batchInitialize in interface Controller
    • runInitialize

      public RunState runInitialize(Parameters params)
      Calls the runInitialize method of this class with all the contexts in the controller registry in the order they are returned by that registry.

      This will prepare the controller, creating a new run state object for the next set of runs (batch or not) if the RunState has been invalidated. Calling the runCleanup() or cleanup() method is required to invalidate the RunState in prepartion for another set of runs.

      Specified by:
      runInitialize in interface Controller
      Returns:
      the current initialized RunState.
    • loadRandomLoader

      protected void loadRandomLoader()
    • runParameterSetters

      public Parameters runParameterSetters(Parameters params)
      Description copied from interface: Controller
      Initializes the parameters for the current run.
      Specified by:
      runParameterSetters in interface Controller
      Parameters:
      params - an optional parameters object that will have the parameters loaded into it
      Returns:
      the parameters object that the parameters were loaded into
    • runCleanup

      public void runCleanup()
      Calls the runCleanup method of this class with all the contexts in the controller registry in the order they are returned by that registry.

      If the RunState object of this controller was created by the runInitialize method, this method will then invalidate the RunState object.

      Specified by:
      runCleanup in interface Controller
    • batchCleanup

      public void batchCleanup()
      Calls the batchCleanup method of this class with all the contexts in the controller registry in the order they are returned by that registry.

      This method will invalidate the RunState object.

      Specified by:
      batchCleanup in interface Controller
    • prepare

      protected boolean prepare()
      If the RunState object is invalidated (null) this will create a new RunState object, using the next*Number fields and the model name of this class. If the RunState is still valid (non-null) this will just return false.
      Returns:
      true if a new RunState object was created.
    • prepareForNextRun

      protected void prepareForNextRun()
    • cleanup

      public void cleanup()
      Invalidates the current RunState.
    • getNextRunNumber

      public int getNextRunNumber()
      Gets the next run number. The next run number is the number assigned to the next run when runInitialize is called.
      Specified by:
      getNextRunNumber in interface Controller
      Returns:
      the next run number. The next run number is the number assigned to the next run when runInitialize is called.
    • getNextBatchNumber

      public int getNextBatchNumber()
      Gets the next batch number. The next batch number is the number assigned to the next batch when batchInitialize is called.
      Specified by:
      getNextBatchNumber in interface Controller
      Returns:
      the next batch number. The next batch number is the number assigned to the next batch when batchInitialize is called.
    • getCurrentRunState

      public RunState getCurrentRunState()
      Retrieves the current RunState the controller is using.
      Specified by:
      getCurrentRunState in interface Controller
      Returns:
      the RunState the controller is currently using
    • setup

      public void setup()
      Specified by:
      setup in interface Controller