adevs
|
#include <adevs_simulator.h>
Public Member Functions | |
Simulator (Devs< X, T > *model) | |
T | nextEventTime () |
void | execNextEvent () |
Execute the simulation cycle at time nextEventTime() | |
void | execUntil (T tend) |
Execute until nextEventTime() > tend. | |
void | computeNextOutput () |
void | computeNextOutput (Bag< Event< X, T > > &input, T t) |
void | computeNextState (Bag< Event< X, T > > &input, T t) |
void | computeNextState () |
~Simulator () | |
void | addModel (Atomic< X, T > *model) |
Simulator (LogicalProcess< X, T > *lp) | |
void | beginLookahead () |
void | endLookahead () |
void | lookNextEvent () |
![]() | |
void | addEventListener (EventListener< X, T > *l) |
void | removeEventListener (EventListener< X, T > *l) |
Remove an event listener. | |
virtual | ~AbstractSimulator () |
Destructor leaves the model intact. | |
void | notify_output_listeners (Devs< X, T > *model, const X &value, T t) |
Notify listeners of an output event. | |
void | notify_state_listeners (Atomic< X, T > *model, T t) |
Notify listeners of a state change. | |
This Simulator class implements the DEVS simulation algorithm. Its methods throw adevs::exception objects if any of the DEVS model constraints are violated (i.e., a negative time advance, a model attempting to send an input directly to itself, or coupled Mealy type systems).
|
inline |
Create a simulator for a model. The simulator constructor will fail and throw an adevs::exception if the time advance of any component atomic model is less than zero.
model | The model to simulate |
Referenced by adevs::Simulator< InternalType, T >::addModel().
adevs::Simulator< X, T >::~Simulator | ( | ) |
Deletes the simulator, but leaves the model intact. The model must exist when the simulator is deleted. Delete the model only after the Simulator is deleted.
References adevs::Bag< T >::begin(), and adevs::Bag< T >::end().
Referenced by adevs::Simulator< InternalType, T >::execUntil().
adevs::Simulator< X, T >::Simulator | ( | LogicalProcess< X, T > * | lp | ) |
Create a simulator that will be used by an LP as part of a parallel simulation. This method is used by the parallel simulator.
|
inline |
Assign a model to the simulator. This has the same effect as passing the model to the constructor.
void adevs::Simulator< X, T >::beginLookahead | ( | ) |
Call this method to indicate that all subsequent calls are part of a lookahead calculation. Lookahead calculations will cause the atomic models involved to save their states at the point that the lookahead calculation was begun. These states are restored when the lookahead calculation ends. At least one call to lookNextEvent() must be made between beginLookahead() and endLookahead().
Lookahead calculations are done with the lookNextEvent method, which may throw a lookahead_impossible_exception. This occurs when the simulator calculate a new state for an atomic model whose beginLookahead method is unsupported.
Referenced by adevs::Simulator< InternalType, T >::addModel().
void adevs::Simulator< X, T >::computeNextOutput | ( | ) |
Compute the output values of the imminent component models if these values have not already been computed. This will notify registered EventListeners as the outputs are produced.
Referenced by adevs::Simulator< X, T >::computeNextState(), adevs::Simulator< X, T >::endLookahead(), adevs::Simulator< InternalType, T >::execUntil(), and adevs::ModelWrapper< ExternalType, InternalType, T >::output_func().
void adevs::Simulator< X, T >::computeNextOutput | ( | Bag< Event< X, T > > & | input, |
T | t | ||
) |
Compute the output value of the model in response to an input at some time in lastEventTime() <= t <= nextEventTime(). This will notify registered EventListeners as the outputs are produced. If this is the first call since the prior state change with the given t, then the new output is computed. Subsequent calls for the same time t simply append to the input already supplied at time t.
input | A bag of (input target,value) pairs |
t | The time at which the input takes effect |
References adevs::Bag< T >::begin(), adevs::Bag< T >::end(), adevs::Devs< X, T >::getParent(), adevs::MealyAtomic< X, T >::output_func(), and adevs::Atomic< X, T >::typeIsAtomic().
void adevs::Simulator< X, T >::computeNextState | ( | Bag< Event< X, T > > & | input, |
T | t | ||
) |
Apply the bag of inputs at time t and then compute the next model states. Requires that lastEventTime() <= t <= nextEventTime(). This, in effect, implements the state transition function of the resultant model. If the output has already been computed at time t, then the new input at t is simply appended to the prior input. Otherwise, the old results are discarded and input is calculated at the given time.
input | A bag of (input target,value) pairs |
t | The time at which the input takes effect |
References adevs::Simulator< X, T >::computeNextOutput(), and adevs::Simulator< X, T >::computeNextState().
Referenced by adevs::ModelWrapper< ExternalType, InternalType, T >::delta_conf(), and adevs::ModelWrapper< ExternalType, InternalType, T >::delta_ext().
void adevs::Simulator< X, T >::computeNextState | ( | ) |
Compute the next state at the time at the time t and with input supplied at the prior call to computeNextOutput assuming no computeNextState has intervened. Assumes t = nextEventTime() and input an empty bag if there was no prior call to computeNextOutput.
The new states are in effect at t + eps so advance t
Compute model transitions and build up the prev (pre-transition) and next (post-transition) component sets. These sets are built up from only the models that have the model_transition function evaluated.
The model adds are processed first. This is done so that, if any of the added models are components something that was removed at a higher level, then the models will not have been deleted when trying to schedule them.
If this model has children, then remove them from the deletion set. This will avoid double delete problems.
References adevs::Bag< T >::begin(), adevs::Bag< T >::clear(), adevs::Simulator< X, T >::computeNextOutput(), adevs::Atomic< X, T >::delta_conf(), adevs::Atomic< X, T >::delta_ext(), adevs::Atomic< X, T >::delta_int(), adevs::Bag< T >::end(), adevs::Atomic< X, T >::gc_output(), adevs::Network< X, T >::getComponents(), adevs::Devs< X, T >::getParent(), adevs::Devs< X, T >::getProc(), adevs::Bag< T >::insert(), adevs::Devs< X, T >::model_transition(), adevs::AbstractSimulator< X, T >::notify_output_listeners(), adevs::AbstractSimulator< X, T >::notify_state_listeners(), adevs::Network< X, T >::route(), adevs::set_assign_diff(), adevs::Atomic< X, T >::ta(), adevs::Devs< X, T >::typeIsAtomic(), adevs::Atomic< X, T >::typeIsAtomic(), adevs::Devs< X, T >::typeIsMealyAtomic(), and adevs::Devs< X, T >::typeIsNetwork().
Referenced by adevs::Simulator< X, T >::computeNextState(), adevs::Simulator< InternalType, T >::execNextEvent(), and adevs::Simulator< InternalType, T >::execUntil().
void adevs::Simulator< X, T >::endLookahead | ( | ) |
This call terminates a lookahead calculation and restores the models to their states when beginLookahead was called.
References adevs::Atomic< X, T >::beginLookahead(), and adevs::Simulator< X, T >::computeNextOutput().
Referenced by adevs::Simulator< InternalType, T >::addModel().
void adevs::Simulator< X, T >::lookNextEvent | ( | ) |
Look at future events assuming a input trajector with only non-events. This has the same effect as calling execNextEvent but the simulator can be restored to its prior state by calling endLookahead.
References adevs::Simulator< X, T >::execNextEvent().
Referenced by adevs::Simulator< InternalType, T >::addModel().
|
inlinevirtual |
Get the model's next event time
Implements adevs::AbstractSimulator< X, T >.
Referenced by adevs::ModelWrapper< ExternalType, InternalType, T >::delta_conf(), adevs::ModelWrapper< ExternalType, InternalType, T >::delta_int(), adevs::Simulator< InternalType, T >::execUntil(), and adevs::ModelWrapper< ExternalType, InternalType, T >::ta().