SyDEVS
v0.6.7
Multiscale Simulation and Systems Modeling Library
|
A data structure which supports the scheduling of future events. More...
#include <time_queue.h>
Public Types | |
using | event_id_set = std::set< int64 > |
The container used to store ids of events occurring at the same time. More... | |
Public Member Functions | |
time_queue () | |
Constructs an empty time queue with a current time of zero. More... | |
time_queue (duration dt0) | |
Constructs an empty time queue with a current time of dt0 More... | |
time_queue (const time_point &t0) | |
Constructs an empty time queue with a current time of t0 More... | |
time_queue (const time_queue &)=default | |
Copy constructor. More... | |
time_queue & | operator= (const time_queue &)=default |
Copy assignment. More... | |
time_queue (time_queue &&)=default | |
Move constructor. More... | |
time_queue & | operator= (time_queue &&)=default |
Move assignment. More... | |
~time_queue ()=default | |
Destructor. More... | |
bool | empty () const |
Returns true if the time queue is empty. More... | |
int64 | size () const |
Returns the number of events in the time queue. More... | |
int64 | time_count () const |
Returns the number of distinct event times in the time queue. More... | |
const time_point & | current_time () const |
Returns the current time. More... | |
const time_point & | advance_time () |
Advances the current time to that of the imminent events. More... | |
const time_point & | advance_time (duration dt) |
Advances the current time by dt . More... | |
const time_point & | advance_time (const time_point t) |
Advances the current time to t . More... | |
bool | can_advance_by (duration dt) |
Returns true if time can be advanced by the specified duration. More... | |
duration | imminent_duration () const |
Returns the duration until the imminent event(s). More... | |
duration | duration_until (int64 event_id) const |
Returns the duration until the event with id event_id , or infinity if no such event exists. More... | |
duration | duration_at (int64 time_index) const |
Returns the duration at time_index . More... | |
const event_id_set & | imminent_event_ids () const |
Returns the imminent events. More... | |
const event_id_set & | event_ids_at (int64 time_index) const |
Returns the events at time_index . More... | |
void | pop_imminent_event (int64 event_id) |
Pops the specified imminent event with id event_id . More... | |
void | pop_imminent_events () |
Pops the imminent events. More... | |
void | plan_event (int64 event_id, duration dt) |
Schedules an event with id event_id after a planned duration of dt . More... | |
bool | cancel_event (int64 event_id) |
Cancels the event with id event_id , returning true if successful. More... | |
A data structure which supports the scheduling of future events.
A time_queue
object represents a list of scheduled events and their associated times, saving space by storing duration
values instead of time_point
objects. All durations associated with the class interface are expressed relative to the current time, which is the only time point stored.
Each one of the stored phase durations is expressed relative to the start of one of two epochs associated with its precision: the epoch containing the current time or the subsequent epoch. Because the current time advances only forwards, and because the planned duration of event cannot exceed one epoch duration, it is always possible to determine which of the two epochs contains the scheduled event.
It is important to correctly interpret the durations used to plan events and report the remaining duration until these events. A duration dt
is assumed to advance
the current time (as per time_point::advance
), not add to it. Hence, for time_queue tq
, the actual time of a planned event is tq.current_time().advance(dt)
, not tq.current_time() + dt
.
using sydevs::time_queue::event_id_set = std::set<int64> |
The container used to store ids of events occurring at the same time.
sydevs::time_queue::time_queue | ( | ) |
Constructs an empty time queue with a current time of zero.
|
explicit |
Constructs an empty time queue with a current time of dt0
|
explicit |
Constructs an empty time queue with a current time of t0
|
default |
Copy constructor.
|
default |
Move constructor.
|
default |
Destructor.
const time_point & sydevs::time_queue::advance_time | ( | ) |
Advances the current time to that of the imminent events.
const time_point & sydevs::time_queue::advance_time | ( | duration | dt | ) |
Advances the current time by dt
.
const time_point & sydevs::time_queue::advance_time | ( | const time_point | t | ) |
Advances the current time to t
.
Returns true
if time can be advanced by the specified duration.
Cancels the event with id event_id
, returning true
if successful.
|
inline |
Returns the current time.
Returns the duration at time_index
.
Returns the duration until the event with id event_id
, or infinity if no such event exists.
|
inline |
Returns true
if the time queue is empty.
const time_queue::event_id_set & sydevs::time_queue::event_ids_at | ( | int64 | time_index | ) | const |
Returns the events at time_index
.
duration sydevs::time_queue::imminent_duration | ( | ) | const |
Returns the duration until the imminent event(s).
const time_queue::event_id_set & sydevs::time_queue::imminent_event_ids | ( | ) | const |
Returns the imminent events.
|
default |
Copy assignment.
|
default |
Move assignment.
Schedules an event with id event_id
after a planned duration of dt
.
void sydevs::time_queue::pop_imminent_event | ( | int64 | event_id | ) |
Pops the specified imminent event with id event_id
.
void sydevs::time_queue::pop_imminent_events | ( | ) |
Pops the imminent events.
|
inline |
Returns the number of events in the time queue.
|
inline |
Returns the number of distinct event times in the time queue.