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

Public Member Functions

 TrafficLight (Id id)
 Construct a new TrafficLight object.
 
 TrafficLight (const Node &node)
 Construct a new TrafficLight object.
 
void setDelay (Delay delay)
 Set the node's delay.
 
void setDelay (std::pair< Delay, Delay > delay)
 Set the node's delay.
 
void setPhase (Delay phase)
 Set the node's phase.
 
void setLeftTurnRatio (std::pair< double, double > ratio)
 Set the node's left turn ratio.
 
void setLeftTurnRatio (double const first, double const second)
 Set the node's left turn ratio.
 
void setLeftTurnRatio (double const ratio)
 Set the node's left turn ratio as std::pair(ratio, ratio)
 
void increaseCounter ()
 Increase the node's counter.
 
void setPhaseAfterCycle (Delay phase)
 Set the phase of the node after the current red-green cycle has passed.
 
std::optional< std::pair< Delay, Delay > > delay () const
 Get the node's delay.
 
Delay counter () const
 
std::optional< std::pair< double, double > > leftTurnRatio () const
 Get the node's left turn ratio.
 
bool isGreen () const
 Returns true if the traffic light is green.
 
bool isGreen (Id streetId) const
 
bool isTrafficLight () const noexcept override
 
- 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.
 
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.
 
virtual bool isIntersection () const noexcept override 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.
 
void setId (Id id)
 Set the node's id.
 
void setCoords (std::pair< double, double > coords)
 Set the node's coordinates.
 
virtual void setTransportCapacity (Size 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.
 
Size capacity () const
 Get the node's capacity.
 
Size transportCapacity () const
 Get the node's transport capacity.
 
virtual bool isRoundabout () 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
 
Size m_capacity
 
Size m_transportCapacity
 

Constructor & Destructor Documentation

◆ TrafficLight() [1/2]

template<typename Delay >
dsm::TrafficLight< Delay >::TrafficLight ( Id id)
inlineexplicit

Construct a new TrafficLight object.

Parameters
idThe node's id

◆ TrafficLight() [2/2]

template<typename Delay >
requires (std::unsigned_integral<Delay>)
dsm::TrafficLight< Delay >::TrafficLight ( const Node & node)

Construct a new TrafficLight object.

Parameters
nodeAn Intersection object

Member Function Documentation

◆ delay()

template<typename Delay >
std::optional< std::pair< Delay, Delay > > dsm::TrafficLight< Delay >::delay ( ) const
inline

Get the node's delay.

Returns
std::optional<Delay> The node's delay

◆ increaseCounter()

template<typename Delay >
requires (std::unsigned_integral<Delay>)
void dsm::TrafficLight< Delay >::increaseCounter ( )

Increase the node's counter.

This function is used to increase the node's counter when the simulation is running. It automatically resets the counter when it reaches the double of the delay value.

Exceptions
std::runtime_errorif the delay is not set

◆ isGreen()

template<typename Delay >
requires (std::unsigned_integral<Delay>)
bool dsm::TrafficLight< Delay >::isGreen ( ) const

Returns true if the traffic light is green.

Returns
bool True if the traffic light is green

◆ isTrafficLight()

template<typename Delay >
bool dsm::TrafficLight< Delay >::isTrafficLight ( ) const
inlineoverridevirtualnoexcept

Reimplemented from dsm::Node.

◆ leftTurnRatio()

template<typename Delay >
std::optional< std::pair< double, double > > dsm::TrafficLight< Delay >::leftTurnRatio ( ) const
inline

Get the node's left turn ratio.

Returns
std::optional<std::pair<double, double>> The node's left turn ratio

◆ setDelay() [1/2]

template<typename Delay >
requires (std::unsigned_integral<Delay>)
void dsm::TrafficLight< Delay >::setDelay ( Delay delay)

Set the node's delay.

This function is used to set the node's delay. If the delay is already set, the function will check the counter:

  • if the counter is more than the sum of the new green and red delays, it will be set to the new sum minus one, i.e. one more red cycle.
  • if the counter is less than the old green delay but more than the new green delay, it will be set to the new green delay minus the difference between the old and the new delay.
    Parameters
    delayThe node's delay

◆ setDelay() [2/2]

template<typename Delay >
requires (std::unsigned_integral<Delay>)
void dsm::TrafficLight< Delay >::setDelay ( std::pair< Delay, Delay > delay)

Set the node's delay.

This function is used to set the node's delay. If the delay is already set, the function will check the counter:

  • if the counter is more than the sum of the new green and red delays, it will be set to the new sum minus one, i.e. one more red cycle.
  • if the counter is less than the old green delay but more than the new green delay, it will be set to the new green delay minus the difference between the old and the new delay.
    Parameters
    delayThe node's delay

◆ setLeftTurnRatio() [1/3]

template<typename Delay >
void dsm::TrafficLight< Delay >::setLeftTurnRatio ( double const first,
double const second )
inline

Set the node's left turn ratio.

Parameters
firstThe first component of the left turn ratio
secondThe second component of the left turn ratio

◆ setLeftTurnRatio() [2/3]

template<typename Delay >
void dsm::TrafficLight< Delay >::setLeftTurnRatio ( double const ratio)
inline

Set the node's left turn ratio as std::pair(ratio, ratio)

Parameters
ratioThe left turn ratio

◆ setLeftTurnRatio() [3/3]

template<typename Delay >
requires (std::unsigned_integral<Delay>)
void dsm::TrafficLight< Delay >::setLeftTurnRatio ( std::pair< double, double > ratio)

Set the node's left turn ratio.

Parameters
ratioA std::pair containing the left turn ratio

ratio.first * greentime is the green time for left turns while ratio.second * redtime is the red time for left turns This is useful for traffic lights when the input street has many lanes and, for example, one resevred for left turns.

◆ setPhase()

template<typename Delay >
requires (std::unsigned_integral<Delay>)
void dsm::TrafficLight< Delay >::setPhase ( Delay phase)

Set the node's phase.

Parameters
phaseThe node's phase
Exceptions
std::runtime_errorif the delay is not set

◆ setPhaseAfterCycle()

template<typename Delay >
requires (std::unsigned_integral<Delay>)
void dsm::TrafficLight< Delay >::setPhaseAfterCycle ( Delay phase)

Set the phase of the node after the current red-green cycle has passed.

Parameters
phaseThe new node phase

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