Class CoupledModel<T extends Number & Comparable<T>>

java.lang.Object
org.djutils.event.LocalEventProducer
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:
  • Field Details

  • Constructor Details

    • CoupledModel

      public CoupledModel(String modelName)
      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

      public CoupledModel(String modelName, CoupledModel<T> parentModel)
      The constructor of a coupled model within another coupled model.
      Parameters:
      modelName - String; the name of this component
      parentModel - CoupledModel<T>; the parent coupled model for this model.
    • CoupledModel

      public CoupledModel(String modelName, DevsSimulatorInterface<T> simulator)
      Constructor of a high-level coupled model without a parent model.
      Parameters:
      modelName - String; the name of this component
      simulator - 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, SimRuntimeException
      The 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 place
      y - TYPE; the value being transferred
      Throws:
      RemoteException - remote exception
      SimRuntimeException - 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

      public void addModelComponent(AbstractDevsModel<T> model)
      Add a model component to this coupled model.
      Parameters:
      model - AbstractDevsModel<T>; the component to add.
    • removeModelComponent

      public void removeModelComponent(AbstractDevsModel<T> model)
      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

      public void removeInputPort(String name) throws PortNotFoundException
      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 class AbstractDevsPortModel<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

      public void removeOutputPort(String name) throws PortNotFoundException
      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 class AbstractDevsPortModel<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

      public Set<InternalCoupling<T,?>> getInternalCouplingSet()
      Returns:
      internalCouplingSet; the internal couplings (from internal models to internal models)
    • getExternalOutputCouplingSet

      public Set<ExternalOutputCoupling<T,?>> getExternalOutputCouplingSet()
      Returns:
      externalOutputCouplingSet; the couplings from the internal models to the output of this coupled model
    • getExternalInputCouplingSet

      public Set<ExternalInputCoupling<T,?>> getExternalInputCouplingSet()
      Returns:
      externalInputCouplingSet; the couplings from the outside world to the internal models of this coupled model
    • getModelComponents

      public Set<AbstractDevsModel<T>> getModelComponents()
      Returns:
      modelComponents; the models within the coupled model
    • printModel

      public void printModel(String space)
      Print the model, preceded by a user provided string.
      Specified by:
      printModel in class AbstractDevsModel<T extends Number & Comparable<T>>
      Parameters:
      space - String; the user provided string to print in front of the model (e.g. newlines, header).