adevs
Public Member Functions | Friends | List of all members
adevs::Model< DataType, TimeType > Class Template Referenceabstract

A model in the simulation. More...

#include <adevs_base.h>

Inheritance diagram for adevs::Model< DataType, TimeType >:
adevs::Devs< DataType, TimeType > adevs::Atomic< DataType, TimeType > adevs::Network< DataType, TimeType > adevs::SimpleDigraph< DataType, TimeType >

Public Member Functions

virtual TimeType init (SimEnv< DataType, TimeType > *env)=0
 Called when the model is added to the simulation. More...
 
virtual void fini (TimeType now)=0
 Called after the model has been removed from the simulation. More...
 
virtual TimeType update (SimEnv< DataType, TimeType > *env, std::vector< DataType > &x)=0
 Called to assign a new state to the model at now() when input is present. More...
 
virtual TimeType update (SimEnv< DataType, TimeType > *env)=0
 Called to assign a new state to the model at now(). More...
 
virtual std::pair< Model< DataType, TimeType > *, DataType > relay (Model< DataType, TimeType > *src, DataType x)
 Relay a message to another model. More...
 
virtual std::string name ()
 Return a name for this model. More...
 
virtual ~Model ()
 Destructor.
 
void reset ()
 Reset simulation support to reuse the model in a new simulation context. More...
 

Friends

class Simulator< DataType, TimeType >
 

Detailed Description

template<typename DataType, typename TimeType = Time>
class adevs::Model< DataType, TimeType >

A model in the simulation.

The template argument is the data type to be communicated between models.

Member Function Documentation

◆ fini()

template<typename DataType, typename TimeType = Time>
virtual void adevs::Model< DataType, TimeType >::fini ( TimeType  now)
pure virtual

Called after the model has been removed from the simulation.

The model is being removed from a running simulation and has ceased to exist as an entity at time now().

Parameters
nowThe time at which the object no longer exists.

Implemented in adevs::Network< DataType, TimeType >, adevs::Network< port_value< DataType >, TimeType >, and adevs::Atomic< DataType, TimeType >.

Referenced by adevs::Simulator< DataType, TimeType >::exec_next_event().

◆ init()

template<typename DataType, typename TimeType = Time>
virtual TimeType adevs::Model< DataType, TimeType >::init ( SimEnv< DataType, TimeType > *  env)
pure virtual

Called when the model is added to the simulation.

The model has been added to a simulation by calling the SimEnv::add(Model*) method. The effect of calling init() should be to assign an initial state at time now and return the time of its event.

Parameters
envThe simulation context
Returns
The time of the next event

Implemented in adevs::Network< DataType, TimeType >, adevs::Network< port_value< DataType >, TimeType >, and adevs::Atomic< DataType, TimeType >.

Referenced by adevs::Simulator< DataType, TimeType >::add().

◆ name()

template<typename DataType, typename TimeType = Time>
virtual std::string adevs::Model< DataType, TimeType >::name ( )
inlinevirtual

Return a name for this model.

This is intended solely to facility debugging when ADEVS_ERROR_CHECK is enabled. The default implementation returns an empty string.

Returns
A name for the model

◆ relay()

template<typename DataType, typename TimeType = Time>
virtual std::pair<Model<DataType,TimeType>*,DataType> adevs::Model< DataType, TimeType >::relay ( Model< DataType, TimeType > *  src,
DataType  x 
)
inlinevirtual

Relay a message to another model.

When a message is sent to the model, its relay method is called immediately. If the method returns NULL then the message is discarded. If the method returns this then the message is delivered to this model. Otherwise, relay may return a model that will receive message as if send(this,relay(),msg) had been called at at the current time. The relay method will be called repeatedly with the same source and data until this or NULL is returned. the default behavior is to return this.

Parameters
srcThe model that sent this data.
xThe data.
Returns
A model and data pair indicating the model to receive the data and the data it should receive.

Reimplemented in adevs::Network< DataType, TimeType >, and adevs::Network< port_value< DataType >, TimeType >.

Referenced by adevs::Network< port_value< DataType >, TimeType >::fini(), and adevs::Simulator< DataType, TimeType >::send().

◆ reset()

template<typename DataType, typename TimeType = Time>
void adevs::Model< DataType, TimeType >::reset ( )
inline

Reset simulation support to reuse the model in a new simulation context.

Resets the internally used simulation variables as though the constructor had been called. Do this only if you want to reuse the model in a second, new simulation. You will probably use this rarely, if ever.

◆ update() [1/2]

template<typename DataType, typename TimeType = Time>
virtual TimeType adevs::Model< DataType, TimeType >::update ( SimEnv< DataType, TimeType > *  env,
std::vector< DataType > &  x 
)
pure virtual

Called to assign a new state to the model at now() when input is present.

Assign a state to the model at time now() and return the time of its next new state. Note that the input was generated in the previous simulation instant and so this calculates the new state using state information from the previous instant.

Parameters
envThe simulation context.
xMessages sent to the model.
Returns
The time of the next call to update.

Implemented in adevs::Network< DataType, TimeType >, adevs::Network< port_value< DataType >, TimeType >, and adevs::Atomic< DataType, TimeType >.

Referenced by adevs::Simulator< DataType, TimeType >::exec_next_event().

◆ update() [2/2]

template<typename DataType, typename TimeType = Time>
virtual TimeType adevs::Model< DataType, TimeType >::update ( SimEnv< DataType, TimeType > *  env)
pure virtual

Called to assign a new state to the model at now().

Assign a state to the model at time now() and return the time of its next new state. An update() will occur at most once per instant of simulation time.

Parameters
envThe simulation context.
Returns
The time of the next call to update.

Implemented in adevs::Network< DataType, TimeType >, adevs::Network< port_value< DataType >, TimeType >, and adevs::Atomic< DataType, TimeType >.


The documentation for this class was generated from the following file: