Class FWSimModel
java.lang.Object
net.simplace.sim.model.FWSimModel
- All Implemented Interfaces:
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 Summary
ConstructorsConstructorDescriptionFWSimModel(HashMap<String, FWSimVariable<?>> aFieldMap, FWSimVarMap aVarMap, org.jdom2.Element aSimModelElement) Creates the template model from the solution: creates the SimComponents (also from groups), adds their variables to the field map and links the variables. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddSimComponent(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.call()Runs the simulation: callsstep()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.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.HashMap<String, FWSimVariable<?>> getSimComponent(String aComponentName) voidinit()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.voidreset(FWSimVarMap aNextVarMap) Resets all components for the next simulation.voidsetSimComponentOrder(List<FWSimComponent> aOrder) Changes the order of execution of the template model (e.g.booleanstep()Runs one time step (one day): updates the current date and the resource values, processes all components, callsIntegratableComponent.postIntegrate(), writes the outputs and advances the current date by one day.toString()
-
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 addedaVarMap- var map of the templateaSimModelElement- the XML element with thesimcomponentandgroupelements- 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
Runs the simulation: callsstep()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:
callin interfaceCallable<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, callsIntegratableComponent.postIntegrate(), writes the outputs and advances the current date by one day.- Returns:
trueif the simulation continues,falseif the end date has been reached
-
clone
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
Resets all components for the next simulation.- Parameters:
aNextVarMap- var map of the next simulation
-
toString
-
getCurrentDate
- Returns:
- the current model date
-
getStartDate
- Returns:
- start date
-
getEndDate
- Returns:
- end date
-
getSimComponent
- Parameters:
aComponentName- name of the component- Returns:
- the component with this name, or
nullif there is none
-
getFieldMap
- Returns:
- the global fieldMap - same for all model instances
-
getVarMap
- Returns:
- the individual VarMap - different for each model instance
-
getSimComponents
- Returns:
- all
FWSimComponentregistered within this model
-
addSimComponent
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
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
-