Dynamical system model
Loading...
Searching...
No Matches
dsm::TrafficLight Class Reference
Inheritance diagram for dsm::TrafficLight:
dsm::Intersection dsm::Node

Public Member Functions

 TrafficLight (Id id, Delay cycleTime)
 Construct a new TrafficLight object.
 
 TrafficLight (Id id, Delay cycleTime, std::pair< double, double > coords)
 
 TrafficLight (Node const &node, Delay const cycleTime, Delay const counter=0)
 
TrafficLightoperator++ ()
 
Delay maxGreenTime (bool priorityStreets) const
 Get the maximum green time over every cycle.
 
Delay minGreenTime (bool priorityStreets) const
 Get the minimum green time over every cycle.
 
double meanGreenTime (bool priorityStreets) const
 Get the mean green time over every cycle.
 
Delay cycleTime () const
 Get the traffic light's total cycle time.
 
void setCycle (Id const streetId, Direction direction, TrafficLightCycle const &cycle)
 Set the cycle for a street and a direction.
 
void setCycles (std::unordered_map< Id, std::vector< TrafficLightCycle > > cycles)
 Set the traffic light's cycles.
 
void setComplementaryCycle (Id const streetId, Id const existingCycle)
 Set the complementary cycle for a street.
 
void moveCycle (Id const oldStreetId, Id const newStreetId)
 Move a cycle from one street to another.
 
void increaseGreenTimes (Delay const delta)
 Increase the green times of the traffic light for priority streets and decrease the green times for non-priority streets.
 
void decreaseGreenTimes (Delay const delta)
 Decrease the green times of the traffic light for priority streets and increase the green times for non-priority streets.
 
std::unordered_map< Id, std::vector< TrafficLightCycle > > const & cycles () const
 Get the traffic light's cycles.
 
bool isDefault () const
 Returns true if all the cycles are set to their default values.
 
bool isGreen (Id const streetId, Direction direction) const
 Returns true if the traffic light is green for a street and a direction.
 
bool isFavouringDirection (bool const priority) const
 Returns true if the traffic light has green increased for all the cycles with priority.
 
void resetCycles ()
 Resets all traffic light cycles.
 
bool isTrafficLight () const noexcept final
 
- Public Member Functions inherited from dsm::Intersection
 Intersection (Id id)
 Construct a new Intersection object.
 
 Intersection (Id id, std::pair< double, double > coords)
 Construct a new Intersection object.
 
 Intersection (Node const &node)
 
void setCapacity (Size capacity) override
 Set the node's capacity.
 
void addAgent (double angle, Id agentId)
 Put an agent in the node.
 
void addAgent (Id agentId)
 Put an agent in the node.
 
void removeAgent (Id agentId)
 Removes an agent from the node.
 
void setStreetPriorities (std::set< Id > streetPriorities)
 Set the node streets with priority.
 
void addStreetPriority (Id streetId)
 Add a street to the node street priorities.
 
double density () const override
 Returns the node's density.
 
bool isFull () const override
 Returns true if the node is full.
 
virtual const std::set< Id > & streetPriorities () const
 Get the node's street priorities.
 
const std::multimap< int16_t, Id > & agents ()
 Get the node's agent ids.
 
Size agentCounter ()
 Returns the number of agents that have passed through the node.
 
bool isIntersection () const noexcept final
 
- Public Member Functions inherited from dsm::Node
 Node (Id id)
 Construct a new Node object with capacity 1.
 
 Node (Id id, std::pair< double, double > coords)
 Construct a new Node object with capacity 1.
 
 Node (Node const &other)
 
Nodeoperator= (Node const &other)
 
void setId (Id id)
 Set the node's id.
 
void setCoords (std::pair< double, double > coords)
 Set the node's coordinates.
 
void setName (const std::string &name)
 Set the node's name.
 
virtual void setTransportCapacity (int capacity)
 Set the node's transport capacity.
 
Id id () const
 Get the node's id.
 
const std::optional< std::pair< double, double > > & coords () const
 Get the node's coordinates.
 
const std::string & name () const
 Get the node's name.
 
Size capacity () const
 Get the node's capacity.
 
int transportCapacity () const
 Get the node's transport capacity.
 
virtual bool isRoundabout () const noexcept
 
virtual bool isStation () const noexcept
 

Additional Inherited Members

- Protected Attributes inherited from dsm::Intersection
std::multimap< int16_t, Id > m_agents
 
std::set< Id > m_streetPriorities
 
Size m_agentCounter
 
- Protected Attributes inherited from dsm::Node
Id m_id
 
std::optional< std::pair< double, double > > m_coords
 
std::string m_name
 
Size m_capacity
 
int m_transportCapacity
 

Constructor & Destructor Documentation

◆ TrafficLight()

dsm::TrafficLight::TrafficLight ( Id id,
Delay cycleTime )
inline

Construct a new TrafficLight object.

Parameters
idThe node's id
cycleTimeThe node's cycle time

Member Function Documentation

◆ cycles()

std::unordered_map< Id, std::vector< TrafficLightCycle > > const & dsm::TrafficLight::cycles ( ) const
inline

Get the traffic light's cycles.

Returns
std::unordered_map<Id, std::vector<TrafficLightCycle>> const& The traffic light's cycles

◆ cycleTime()

Delay dsm::TrafficLight::cycleTime ( ) const
inline

Get the traffic light's total cycle time.

Returns
Delay The traffic light's cycle time

◆ decreaseGreenTimes()

void dsm::TrafficLight::decreaseGreenTimes ( Delay const delta)

Decrease the green times of the traffic light for priority streets and increase the green times for non-priority streets.

Parameters
deltaDelay, the time to increase or decrease the green times

◆ increaseGreenTimes()

void dsm::TrafficLight::increaseGreenTimes ( Delay const delta)

Increase the green times of the traffic light for priority streets and decrease the green times for non-priority streets.

Parameters
deltaDelay, the time to increase or decrease the green times

◆ isFavouringDirection()

bool dsm::TrafficLight::isFavouringDirection ( bool const priority) const

Returns true if the traffic light has green increased for all the cycles with priority.

Parameters
prioritybool, if true, only the priority streets are considered; else, only the non-priority streets are considered
Returns
true if the traffic light has green increased for all the cycles with priority

◆ isGreen()

bool dsm::TrafficLight::isGreen ( Id const streetId,
Direction direction ) const

Returns true if the traffic light is green for a street and a direction.

Parameters
streetIdId, the street's id
directionDirection, the direction
Returns
true if the traffic light is green for the street and direction

◆ isTrafficLight()

bool dsm::TrafficLight::isTrafficLight ( ) const
inlinefinalvirtualnoexcept

Reimplemented from dsm::Node.

◆ maxGreenTime()

Delay dsm::TrafficLight::maxGreenTime ( bool priorityStreets) const

Get the maximum green time over every cycle.

Parameters
priorityStreetsbool, if true, only the priority streets are considered; if false, only the non-priority streets are considered
Returns
Delay The maximum green time

The maximum green time is the maximum green time of all the cycles for the priority streets if priorityStreets is true, or for the non-priority streets if priorityStreets is false.

◆ meanGreenTime()

double dsm::TrafficLight::meanGreenTime ( bool priorityStreets) const

Get the mean green time over every cycle.

Parameters
priorityStreetsbool, if true, only the priority streets are considered; if false, only the non-priority streets are considered
Returns
double The mean green time

The mean green time is the mean green time of all the cycles for the priority streets if priorityStreets is true, or for the non-priority streets if priorityStreets is false.

◆ minGreenTime()

Delay dsm::TrafficLight::minGreenTime ( bool priorityStreets) const

Get the minimum green time over every cycle.

Parameters
priorityStreetsbool, if true, only the priority streets are considered; if false, only the non-priority streets are considered
Returns
Delay The minimum green time

The minimum green time is the minimum green time of all the cycles for the priority streets if priorityStreets is true, or for the non-priority streets if priorityStreets is false.

◆ moveCycle()

void dsm::TrafficLight::moveCycle ( Id const oldStreetId,
Id const newStreetId )

Move a cycle from one street to another.

Parameters
oldStreetIdId, the old street id
newStreetIdId, the new street id

◆ resetCycles()

void dsm::TrafficLight::resetCycles ( )

Resets all traffic light cycles.

For more info, see TrafficLightCycle::reset()

◆ setComplementaryCycle()

void dsm::TrafficLight::setComplementaryCycle ( Id const streetId,
Id const existingCycle )

Set the complementary cycle for a street.

Parameters
streetIdId, The street's id
existingCycleId, The street's id associated with the existing cycle
Exceptions
std::invalid_argumentif the street id does not exist
std::invalid_argumentif the cycle does not exist

The complementary cycle is a cycle that has as green time the total cycle time minus the green time of the existing cycle. The phase is the total cycle time minus the green time of the existing cycle, plus the phase of the existing cycle.

◆ setCycle()

void dsm::TrafficLight::setCycle ( Id const streetId,
Direction direction,
TrafficLightCycle const & cycle )

Set the cycle for a street and a direction.

Parameters
streetIdThe street's id
directionThe direction
cycleThe traffic light cycle

◆ setCycles()

void dsm::TrafficLight::setCycles ( std::unordered_map< Id, std::vector< TrafficLightCycle > > cycles)
inline

Set the traffic light's cycles.

Parameters
cyclesstd::unordered_map<Id, std::vector<TrafficLightCycle>> The traffic light's cycles

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