Class CoupledModel<T extends Number & Comparable<T>>
java.lang.Object
org.djutils.event.LocalEventProducer
nl.tudelft.simulation.dsol.formalisms.devs.esdevs.AbstractDevsModel<T>
nl.tudelft.simulation.dsol.formalisms.devs.esdevs.AbstractDevsPortModel<T>
nl.tudelft.simulation.dsol.formalisms.devs.esdevs.CoupledModel<T>
- Type Parameters:
T
- the time type
- All Implemented Interfaces:
Serializable
,Remote
,org.djutils.event.EventProducer
public abstract class CoupledModel<T extends Number & Comparable<T>>
extends AbstractDevsPortModel<T>
CoupledModel class. This class implements the classic parallel DEVS coupled model with ports conform Zeigler et al. (2000),
section 4.3.
Copyright (c) 2009-2024 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://simulation.tudelft.nl. The DSOL project is distributed under a three-clause BSD-style license, which can be found at https://https://simulation.tudelft.nl/dsol/docs/latest/license.html.
- Since:
- 1.5
- Author:
- Mamadou Seck
, Alexander Verbraeck - See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class nl.tudelft.simulation.dsol.formalisms.devs.esdevs.AbstractDevsModel
AbstractDevsModel.StateUpdate
-
Field Summary
Modifier and TypeFieldDescriptionprotected Set<ExternalInputCoupling<T,
?>> the couplings from the outside world to the internal models of this coupled model.protected Set<ExternalOutputCoupling<T,
?>> the couplings from the internal models to the output of this coupled model.protected Set<InternalCoupling<T,
?>> the internal couplings (from internal models to internal models).protected Set<AbstractDevsModel<T>>
the models within this coupled model.Fields inherited from class nl.tudelft.simulation.dsol.formalisms.devs.esdevs.AbstractDevsPortModel
inputPortMap, outputPortMap
Fields inherited from class nl.tudelft.simulation.dsol.formalisms.devs.esdevs.AbstractDevsModel
fullName, modelName, parentModel, simulator, STATE_UPDATE
Fields inherited from interface org.djutils.event.EventProducer
FIRST_POSITION, LAST_POSITION
-
Constructor Summary
ConstructorDescriptionCoupledModel
(String modelName) The constructor of the top model when the simulator is still unknown (e.g.CoupledModel
(String modelName, CoupledModel<T> parentModel) The constructor of a coupled model within another coupled model.CoupledModel
(String modelName, DevsSimulatorInterface<T> simulator) Constructor of a high-level coupled model without a parent model. -
Method Summary
Modifier and TypeMethodDescription<TYPE> void
addExternalInputCoupling
(InputPortInterface<T, TYPE> fromPort, InputPortInterface<T, TYPE> toPort) Add an IOC within this coupled model.<TYPE> void
addExternalOutputCoupling
(OutputPortInterface<T, TYPE> fromPort, OutputPortInterface<T, TYPE> toPort) Add an EOC within this coupled model.boolean
addHierarchicalListener
(org.djutils.event.EventListener eli, org.djutils.event.EventType et) Add a listener recursively to the model and all its submodels.<TYPE> void
addInternalCoupling
(OutputPortInterface<T, TYPE> fromPort, InputPortInterface<T, TYPE> toPort) void
addModelComponent
(AbstractDevsModel<T> model) Add a model component to this coupled model.Set<InternalCoupling<T,
?>> void
printModel
(String space) Print the model, preceded by a user provided string.<TYPE> void
removeExternalInputCoupling
(InputPortInterface<T, TYPE> fromPort, InputPortInterface<T, TYPE> toPort) Remove an IOC within this coupled model.<TYPE> void
removeExternalOutputCoupling
(OutputPortInterface<T, TYPE> fromPort, OutputPortInterface<T, TYPE> toPort) Remove an EOC within this coupled model.void
removeInputPort
(String name) Remove an input port from the model.<TYPE> void
removeInternalCoupling
(OutputPortInterface<T, TYPE> fromPort, InputPortInterface<T, TYPE> toPort) void
removeModelComponent
(AbstractDevsModel<T> model) Remove a model component from a coupled model, including all its couplings (internal, external in, and external out).void
removeOutputPort
(String name) Remove an output port from the model.<TYPE> void
transfer
(OutputPortInterface<T, TYPE> x, TYPE y) The transfer function takes care of transferring a value from this coupled model to the outside world.Methods inherited from class nl.tudelft.simulation.dsol.formalisms.devs.esdevs.AbstractDevsPortModel
addInputPort, addOutputPort, getInputPortMap, getOutputPortMap
Methods inherited from class nl.tudelft.simulation.dsol.formalisms.devs.esdevs.AbstractDevsModel
fireUpdatedState, getFullName, getModelName, getParentModel, getSimulator, setSimulator, toString
Methods inherited from class org.djutils.event.LocalEventProducer
addListener, addListener, addListener, addListener, fireEvent, fireEvent, fireEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, getEventListenerMap, getEventTypesWithListeners, getListenerReferences, hasListeners, numberOfListeners, removeAllListeners, removeAllListeners, removeListener
-
Field Details
-
internalCouplingSet
the internal couplings (from internal models to internal models). -
externalOutputCouplingSet
the couplings from the internal models to the output of this coupled model. -
externalInputCouplingSet
the couplings from the outside world to the internal models of this coupled model. -
modelComponents
the models within this coupled model.
-
-
Constructor Details
-
CoupledModel
The constructor of the top model when the simulator is still unknown (e.g. in the constructModel() method).- Parameters:
modelName
- String; the name of this component
-
CoupledModel
The constructor of a coupled model within another coupled model.- Parameters:
modelName
- String; the name of this componentparentModel
- CoupledModel<T>; the parent coupled model for this model.
-
CoupledModel
Constructor of a high-level coupled model without a parent model.- Parameters:
modelName
- String; the name of this componentsimulator
- DevsSimulatorInterface<T>; the simulator to schedule events on.
-
-
Method Details
-
addHierarchicalListener
public boolean addHierarchicalListener(org.djutils.event.EventListener eli, org.djutils.event.EventType et) Add a listener recursively to the model and all its submodels. Delegate it for this coupled model to the embedded event producer.- Parameters:
eli
- EventListener; the event listener.et
- EventType; the event type.- Returns:
- success or failure of adding the listener to all submodels.
-
transfer
public <TYPE> void transfer(OutputPortInterface<T, TYPE> x, TYPE y) throws RemoteException, SimRuntimeExceptionThe transfer function takes care of transferring a value from this coupled model to the outside world.- Type Parameters:
TYPE
- the type of message / event being transferred- Parameters:
x
- OutputPortInterface<T,TYPE>; the output port through which the transfer takes placey
- TYPE; the value being transferred- Throws:
RemoteException
- remote exceptionSimRuntimeException
- simulation run time exception
-
addInternalCoupling
public <TYPE> void addInternalCoupling(OutputPortInterface<T, TYPE> fromPort, InputPortInterface<T, TYPE> toPort) - Type Parameters:
TYPE
- the type of message / event for which the coupling is added.- Parameters:
fromPort
- OutputPortInterface<T,TYPE>; the output port of an internal component that transfers the message / event to another internal component (start of the coupling)toPort
- InputPortInterface<T,TYPE>; the input port of an internal component that receives a message / event from the other componet (end of the coupling)
-
removeInternalCoupling
public <TYPE> void removeInternalCoupling(OutputPortInterface<T, TYPE> fromPort, InputPortInterface<T, TYPE> toPort) - Type Parameters:
TYPE
- the type of message / event for which the coupling is removed.- Parameters:
fromPort
- OutputPortInterface<T,TYPE>; the output port of an internal component that transfers the message / event to another internal component (start of the coupling)toPort
- InputPortInterface<T,TYPE>; the input port of an internal component that receives a message / event from the other componet (end of the coupling)
-
addExternalInputCoupling
public <TYPE> void addExternalInputCoupling(InputPortInterface<T, TYPE> fromPort, InputPortInterface<T, TYPE> toPort) Add an IOC within this coupled model.- Type Parameters:
TYPE
- the type of message / event for which the coupling is added.- Parameters:
fromPort
- InputPortInterface<T,TYPE>; the input port of this coupled model that transfers the message / event to the internal component (start of the coupling)toPort
- InputPortInterface<T,TYPE>; the input port of the internal component that receives a message / event from the overarching coupled model (end of the coupling)
-
removeExternalInputCoupling
public <TYPE> void removeExternalInputCoupling(InputPortInterface<T, TYPE> fromPort, InputPortInterface<T, TYPE> toPort) Remove an IOC within this coupled model.- Type Parameters:
TYPE
- the type of message / event for which the coupling is removed.- Parameters:
fromPort
- InputPortInterface<T,TYPE>; the input port of this coupled model that transfers the message / event to the internal component (start of the coupling)toPort
- InputPortInterface<T,TYPE>; the input port of the internal component that receives a message / event from the overarching coupled model (end of the coupling)
-
addExternalOutputCoupling
public <TYPE> void addExternalOutputCoupling(OutputPortInterface<T, TYPE> fromPort, OutputPortInterface<T, TYPE> toPort) Add an EOC within this coupled model.- Type Parameters:
TYPE
- the type of message / event for which the coupling is added.- Parameters:
fromPort
- OutputPortInterface<T,TYPE>; the output port of the internal component that produces an event for the outside of the overarching coupled model (start of the coupling)toPort
- OutputPortInterface<T,TYPE>; the output port of this coupled model that transfers the message / event to the outside (end of the coupling)
-
removeExternalOutputCoupling
public <TYPE> void removeExternalOutputCoupling(OutputPortInterface<T, TYPE> fromPort, OutputPortInterface<T, TYPE> toPort) Remove an EOC within this coupled model.- Type Parameters:
TYPE
- the type of message / event for which the coupling is removed.- Parameters:
fromPort
- OutputPortInterface<T,TYPE>; the output port of the internal component that produces an event for the outside of the overarching coupled model (start of the coupling)toPort
- OutputPortInterface<T,TYPE>; the output port of this coupled model that transfers the message / event to the outside (end of the coupling)
-
addModelComponent
Add a model component to this coupled model.- Parameters:
model
- AbstractDevsModel<T>; the component to add.
-
removeModelComponent
Remove a model component from a coupled model, including all its couplings (internal, external in, and external out).- Parameters:
model
- AbstractDevsModel<T>; the component to remove.
-
removeInputPort
Remove an input port from the model. Note: override this method in classes that extend the behavior, e.g. to remove couplings from this port in case it is removed.- Overrides:
removeInputPort
in classAbstractDevsPortModel<T extends Number & Comparable<T>>
- Parameters:
name
- String; the name of the input port to be removed- Throws:
PortNotFoundException
- in case the port name does not exist for the model
-
removeOutputPort
Remove an output port from the model. Note: override this method in classes that extend the behavior, e.g. to remove couplings from this port in case it is removed.- Overrides:
removeOutputPort
in classAbstractDevsPortModel<T extends Number & Comparable<T>>
- Parameters:
name
- String; the name of the output port to be removed- Throws:
PortNotFoundException
- in case the port name does not exist for the model
-
getInternalCouplingSet
- Returns:
- internalCouplingSet; the internal couplings (from internal models to internal models)
-
getExternalOutputCouplingSet
- Returns:
- externalOutputCouplingSet; the couplings from the internal models to the output of this coupled model
-
getExternalInputCouplingSet
- Returns:
- externalInputCouplingSet; the couplings from the outside world to the internal models of this coupled model
-
getModelComponents
- Returns:
- modelComponents; the models within the coupled model
-
printModel
Print the model, preceded by a user provided string.- Specified by:
printModel
in classAbstractDevsModel<T extends Number & Comparable<T>>
- Parameters:
space
- String; the user provided string to print in front of the model (e.g. newlines, header).
-