Class FWSimModel

java.lang.Object
net.simplace.sim.model.FWSimModel
All Implemented Interfaces:
Callable<FWSimVarMap>

public class FWSimModel extends Object implements Callable<FWSimVarMap>
A model run of one simulation: holds the SimComponents of the solution and the var map of the simulation, and runs the simulation day by day.

A template model is created from the solution; for each simulation it is cloned with a new var map (see clone(FWSimVarMap)). The model is a Callable, so several simulations can run in parallel. In each time step (step()) the current date and resource values are updated, all components are processed, the integratable components are integrated and the outputs are written. Resources and outputs are accessed via the resource and output manager of the session.

Author:
Andreas Enders
  • Constructor Details

    • FWSimModel

      public FWSimModel(HashMap<String, FWSimVariable<?>> aFieldMap, FWSimVarMap aVarMap, org.jdom2.Element aSimModelElement) throws SimLinkInvalidException
      Creates the template model from the solution: creates the SimComponents (also from groups), adds their variables to the field map and links the variables.
      Parameters:
      aFieldMap - the global field map; the variables of the components are added
      aVarMap - var map of the template
      aSimModelElement - the XML element with the simcomponent and group elements
      Throws:
      SimLinkInvalidException - if a component cannot be created
  • Method Details

    • init

      public void init()
      Initializes the model: loads the resource values, checks the skip rule of the solution, calculates solution variables with rules that have no value yet, and initializes all components.
      Throws:
      AbortSimulationException - if the skip rule of the solution is true for this simulation
    • call

      public FWSimVarMap call()
      Runs the simulation: calls step() until the end date is reached, waits for the other simulations of the project if they are synchronized, and calculates the statistics at the end. Errors are logged and reported to the session, not thrown.
      Specified by:
      call in interface Callable<FWSimVarMap>
      Returns:
      the var map of the simulation after the run
    • step

      public boolean step()
      Runs one time step (one day): updates the current date and the resource values, processes all components, calls IntegratableComponent.postIntegrate(), writes the outputs and advances the current date by one day.
      Returns:
      true if the simulation continues, false if the end date has been reached
    • clone

      public FWSimModel clone(FWSimVarMap aMap)
      Creates the model of a new simulation from this (template) model: the components are cloned with the given var map and the current date is set to the start date.
      Parameters:
      aMap - the (already cloned) var map of the new simulation
      Returns:
      the new model
    • reset

      public void reset(FWSimVarMap aNextVarMap)
      Resets all components for the next simulation.
      Parameters:
      aNextVarMap - var map of the next simulation
    • toString

      public String toString()
      Overrides:
      toString in class Object
      See Also:
    • getCurrentDate

      public LocalDateTime getCurrentDate()
      Returns:
      the current model date
    • getStartDate

      public LocalDateTime getStartDate()
      Returns:
      start date
    • getEndDate

      public LocalDateTime getEndDate()
      Returns:
      end date
    • getSimComponent

      public FWSimComponent getSimComponent(String aComponentName)
      Parameters:
      aComponentName - name of the component
      Returns:
      the component with this name, or null if there is none
    • getFieldMap

      public HashMap<String, FWSimVariable<?>> getFieldMap()
      Returns:
      the global fieldMap - same for all model instances
    • getVarMap

      public FWSimVarMap getVarMap()
      Returns:
      the individual VarMap - different for each model instance
    • getSimComponents

      public List<FWSimComponent> getSimComponents()
      Returns:
      all FWSimComponent registered within this model
    • addSimComponent

      public void addSimComponent(FWSimComponent aComponent)
      Adds a new component to the template model at the end of the order of execution and registers its variables in the global field map, like the components read from the solution (e.g. a component added in the graph panel of the GUI, Redmine #62).
      Parameters:
      aComponent - the component created with this model and its var map
    • setSimComponentOrder

      public void setSimComponentOrder(List<FWSimComponent> aOrder)
      Changes the order of execution of the template model (e.g. in the graph panel of the GUI, Redmine #62): the components are executed in the given order, their order numbers are set new (100, 101, ... as when reading the solution). Simulations created afterwards use the new order.
      Parameters:
      aOrder - all components of the model in the new order
      Throws:
      IllegalArgumentException - if the list does not contain exactly the components of the model
    • getSimLinks

      Returns:
      all links between variables, grouped by the component owning the target variable