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 CoupledmodelThe model to simulate.protected LinkedList<AbstractSimulator>simulatorsThe 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 voidbuildHierarchy()Builds the hierarchy of simulators for the model.voidclear()Empties the event list at the ports of the associated model.voiddeltfcn()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.voidexit()This is a special function, out of the DEVS formalism, that allows to realize some actions when the simulation ends.CoupledgetModel()Gets the associated model of the simulator.Collection<AbstractSimulator>getSimulators()Returns the simulators of the components of the model.voidinitialize()Initializes the simulator and the associated model.voidlambda()Executes the output function of the DEVS simulation.static voidmain(String[] args)voidpropagateInput()Propagates the input of the model.voidpropagateOutput()Propagates the output of the model.voidsimInject(double e, Port<Object> port, Object value)Injects a single value in the given input port with elapsed time e.voidsimInject(double e, Port<Object> port, Collection<Object> values)Injects a value into the port "port", calling the transition function.voidsimInject(Port<Object> port, Object value)Injects a single value in the given input port with elapsed time e equal to 0.voidsimInject(Port<Object> port, Collection<Object> values)Injects a set of values in the given input port with elapsed time e equal to 0.voidsimulate(double timeInterval)This function is used to simulate the model for a given time interval.voidsimulate(long numIterations)This function is used to simulate the model for a given number of iterations.doubleta()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:AbstractSimulatorInitializes 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:
initializein classAbstractSimulator
-
exit
public void exit()
Description copied from class:AbstractSimulatorThis is a special function, out of the DEVS formalism, that allows to realize some actions when the simulation ends.- Specified by:
exitin 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:AbstractSimulatorExecutes the time advance mechanism of the DEVS simulation.- Specified by:
tain classAbstractSimulator- Returns:
- the new DEVS sigma.
-
lambda
public void lambda()
Description copied from class:AbstractSimulatorExecutes the output function of the DEVS simulation.- Specified by:
lambdain 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:AbstractSimulatorExecutes 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:
deltfcnin 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:AbstractSimulatorEmpties the event list at the ports of the associated model.- Specified by:
clearin 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:AbstractSimulatorGets the associated model of the simulator.- Specified by:
getModelin classAbstractSimulator- Returns:
- the associated model of the simulator.
-
main
public static void main(String[] args)
-
-