Package xdevs.core.simulation
Class Coordinator
- java.lang.Object
-
- xdevs.core.simulation.AbstractSimulator
-
- xdevs.core.simulation.Coordinator
-
- Direct Known Subclasses:
CoordinatorDistributed
,CoordinatorDynamic
,CoordinatorParallel
,CoordinatorProfile
public class Coordinator extends AbstractSimulator
This class represents a parallel DEVS coordinator, in xDEVS style. The coordinator is responsible for the simulation of a DEVS model, and it is composed of a simulation clock and the model to simulate. The coordinator is responsible for the initialization, execution and termination of the simulation.
-
-
Field Summary
Fields Modifier and Type Field Description protected Coupled
model
The model to simulate.protected LinkedList<AbstractSimulator>
simulators
The simulators of the components of the model.-
Fields inherited from class xdevs.core.simulation.AbstractSimulator
clock, tL, tN
-
-
Constructor Summary
Constructors Constructor Description Coordinator(Coupled model)
Creates a new coordinator with the given model, not flattened.Coordinator(Coupled model, boolean flatten)
Creates a new coordinator with the given model and whether to flatten it or not.Coordinator(SimulationClock clock, Coupled model)
Creates a new coordinator with the given simulation clock and model, not flattened.Coordinator(SimulationClock clock, Coupled model, boolean flatten)
Creates a new coordinator with the given simulation clock and model.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
buildHierarchy()
Builds the hierarchy of simulators for the model.void
clear()
Empties the event list at the ports of the associated model.void
deltfcn()
Executes one of the transition functions of the DEVS simulation, depending on the current state of the model and whether there are new events or not.void
exit()
This is a special function, out of the DEVS formalism, that allows to realize some actions when the simulation ends.Coupled
getModel()
Gets the associated model of the simulator.Collection<AbstractSimulator>
getSimulators()
Returns the simulators of the components of the model.void
initialize()
Initializes the simulator and the associated model.void
lambda()
Executes the output function of the DEVS simulation.static void
main(String[] args)
void
propagateInput()
Propagates the input of the model.void
propagateOutput()
Propagates the output of the model.void
simInject(double e, Port<Object> port, Object value)
Injects a single value in the given input port with elapsed time e.void
simInject(double e, Port<Object> port, Collection<Object> values)
Injects a value into the port "port", calling the transition function.void
simInject(Port<Object> port, Object value)
Injects a single value in the given input port with elapsed time e equal to 0.void
simInject(Port<Object> port, Collection<Object> values)
Injects a set of values in the given input port with elapsed time e equal to 0.void
simulate(double timeInterval)
This function is used to simulate the model for a given time interval.void
simulate(long numIterations)
This function is used to simulate the model for a given number of iterations.double
ta()
Executes the time advance mechanism of the DEVS simulation.
-
-
-
Field Detail
-
model
protected Coupled model
The model to simulate.
-
simulators
protected LinkedList<AbstractSimulator> simulators
The simulators of the components of the model.
-
-
Constructor Detail
-
Coordinator
public Coordinator(SimulationClock clock, Coupled model, boolean flatten)
Creates a new coordinator with the given simulation clock and model.- Parameters:
clock
- the simulation clock of the coordinator.model
- the model to simulate.flatten
- if true, the model is flattened before simulation.
-
Coordinator
public Coordinator(SimulationClock clock, Coupled model)
Creates a new coordinator with the given simulation clock and model, not flattened.- Parameters:
clock
- the simulation clock of the coordinator.model
- the model to simulate.
-
Coordinator
public Coordinator(Coupled model, boolean flatten)
Creates a new coordinator with the given model and whether to flatten it or not.- Parameters:
model
- the model to simulate.flatten
- if true, the model is flattened before simulation.
-
Coordinator
public Coordinator(Coupled model)
Creates a new coordinator with the given model, not flattened.- Parameters:
model
- the model to simulate.
-
-
Method Detail
-
buildHierarchy
protected void buildHierarchy()
Builds the hierarchy of simulators for the model.
-
initialize
public void initialize()
Description copied from class:AbstractSimulator
Initializes the simulator and the associated model. This is not part of the DEVS formalism, but it is a necessary step to prepare the simulator for the simulation.- Specified by:
initialize
in classAbstractSimulator
-
exit
public void exit()
Description copied from class:AbstractSimulator
This is a special function, out of the DEVS formalism, that allows to realize some actions when the simulation ends.- Specified by:
exit
in classAbstractSimulator
-
getSimulators
public Collection<AbstractSimulator> getSimulators()
Returns the simulators of the components of the model.- Returns:
- the simulators of the components of the model.
-
ta
public double ta()
Description copied from class:AbstractSimulator
Executes the time advance mechanism of the DEVS simulation.- Specified by:
ta
in classAbstractSimulator
- Returns:
- the new DEVS sigma.
-
lambda
public void lambda()
Description copied from class:AbstractSimulator
Executes the output function of the DEVS simulation.- Specified by:
lambda
in classAbstractSimulator
-
propagateOutput
public void propagateOutput()
Propagates the output of the model. This method is called after the lambda function of the simulators, and it propagates the output of the models to the input of the components connected to the previuous output ports.
-
deltfcn
public void deltfcn()
Description copied from class:AbstractSimulator
Executes one of the transition functions of the DEVS simulation, depending on the current state of the model and whether there are new events or not.- Specified by:
deltfcn
in classAbstractSimulator
-
propagateInput
public void propagateInput()
Propagates the input of the model. This method is called before the delta function of the simulators, and it propagates the input of the models to the input of the components connected to the previuous input ports.
-
clear
public void clear()
Description copied from class:AbstractSimulator
Empties the event list at the ports of the associated model.- Specified by:
clear
in classAbstractSimulator
-
simInject
public void simInject(double e, Port<Object> port, Collection<Object> values)
Injects a value into the port "port", calling the transition function.- Parameters:
e
- elapsed timeport
- input port to inject the set of valuesvalues
- set of values to inject
-
simInject
public void simInject(Port<Object> port, Collection<Object> values)
Injects a set of values in the given input port with elapsed time e equal to 0.- Parameters:
port
- input port to inject the set of valuesvalues
- set of values to inject
-
simInject
public void simInject(double e, Port<Object> port, Object value)
Injects a single value in the given input port with elapsed time e.- Parameters:
e
- elapsed timeport
- input port to inject the valuevalue
- value to inject
-
simInject
public void simInject(Port<Object> port, Object value)
Injects a single value in the given input port with elapsed time e equal to 0.- Parameters:
port
- input port to inject the valuevalue
- value to inject
-
simulate
public void simulate(long numIterations)
This function is used to simulate the model for a given number of iterations.- Parameters:
numIterations
- the number of iterations to simulate.
-
simulate
public void simulate(double timeInterval)
This function is used to simulate the model for a given time interval.- Parameters:
timeInterval
- the time interval to simulate.
-
getModel
public Coupled getModel()
Description copied from class:AbstractSimulator
Gets the associated model of the simulator.- Specified by:
getModel
in classAbstractSimulator
- Returns:
- the associated model of the simulator.
-
main
public static void main(String[] args)
-
-