SyDEVS  v0.6.4
Multiscale Simulation and Systems Modeling Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sydevs::time_queue Class Reference

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_queueoperator= (const time_queue &)=default
 Copy assignment. More...
 
 time_queue (time_queue &&)=default
 Move constructor. More...
 
time_queueoperator= (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_pointcurrent_time () const
 Returns the current time. More...
 
const time_pointadvance_time ()
 Advances the current time to that of the imminent events. More...
 
const time_pointadvance_time (duration dt)
 Advances the current time by dt. More...
 
const time_pointadvance_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_setimminent_event_ids () const
 Returns the imminent events. More...
 
const event_id_setevent_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...
 

Detailed Description

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.

Member Typedef Documentation

The container used to store ids of events occurring at the same time.

Constructor & Destructor Documentation

sydevs::time_queue::time_queue ( )

Constructs an empty time queue with a current time of zero.

sydevs::time_queue::time_queue ( duration  dt0)
explicit

Constructs an empty time queue with a current time of dt0

sydevs::time_queue::time_queue ( const time_point t0)
explicit

Constructs an empty time queue with a current time of t0

sydevs::time_queue::time_queue ( const time_queue )
default

Copy constructor.

sydevs::time_queue::time_queue ( time_queue &&  )
default

Move constructor.

sydevs::time_queue::~time_queue ( )
default

Destructor.

Member Function Documentation

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.

bool sydevs::time_queue::can_advance_by ( duration  dt)

Returns true if time can be advanced by the specified duration.

bool sydevs::time_queue::cancel_event ( int64  event_id)

Cancels the event with id event_id, returning true if successful.

const time_point & sydevs::time_queue::current_time ( ) const
inline

Returns the current time.

duration sydevs::time_queue::duration_at ( int64  time_index) const

Returns the duration at time_index.

duration sydevs::time_queue::duration_until ( int64  event_id) const

Returns the duration until the event with id event_id, or infinity if no such event exists.

bool sydevs::time_queue::empty ( ) const
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.

time_queue& sydevs::time_queue::operator= ( const time_queue )
default

Copy assignment.

time_queue& sydevs::time_queue::operator= ( time_queue &&  )
default

Move assignment.

void sydevs::time_queue::plan_event ( int64  event_id,
duration  dt 
)

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.

int64 sydevs::time_queue::size ( ) const
inline

Returns the number of events in the time queue.

int64 sydevs::time_queue::time_count ( ) const
inline

Returns the number of distinct event times in the time queue.


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