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

Public Member Functions

 TrafficLight (Id id)
 Construct a new TrafficLight object.
 
 TrafficLight (const NodeConcept< Id, Size > &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 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
 
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::Node< Id, Size >
 Node (Id id)
 Construct a new Node object.
 
 Node (Id id, std::pair< double, double > coords)
 Construct a new Node 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.
 
bool isFull () const override
 Returns true if the node is full.
 
virtual const std::set< Id > & streetPriorities () const
 Get the node's street priorities.
 
std::multimap< int16_t, Id > agents () const
 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::NodeConcept< Id, Size >
 NodeConcept (Id id)
 Construct a new Node object with capacity 1.
 
 NodeConcept (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.
 
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.
 
virtual bool isRoundabout () const noexcept
 

Additional Inherited Members

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

Constructor & Destructor Documentation

◆ TrafficLight() [1/2]

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

Construct a new TrafficLight object.

Parameters
idThe node's id

◆ TrafficLight() [2/2]

template<typename Id , typename Size , typename Delay >
requires (std::unsigned_integral<Id> && std::unsigned_integral<Size> && std::unsigned_integral<Delay>)
dsm::TrafficLight< Id, Size, Delay >::TrafficLight ( const NodeConcept< Id, Size > & node)

Construct a new TrafficLight object.

Parameters
nodeA Node object

Member Function Documentation

◆ delay()

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

Get the node's delay.

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

◆ increaseCounter()

template<typename Id , typename Size , typename Delay >
requires (std::unsigned_integral<Id> && std::unsigned_integral<Size> && std::unsigned_integral<Delay>)
void dsm::TrafficLight< Id, Size, 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 Id , typename Size , typename Delay >
requires (std::unsigned_integral<Id> && std::unsigned_integral<Size> && std::unsigned_integral<Delay>)
bool dsm::TrafficLight< Id, Size, Delay >::isGreen ( ) const

Returns true if the traffic light is green.

Returns
bool True if the traffic light is green

◆ isTrafficLight()

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

Reimplemented from dsm::NodeConcept< Id, Size >.

◆ setDelay() [1/2]

template<typename Id , typename Size , typename Delay >
requires (std::unsigned_integral<Id> && std::unsigned_integral<Size> && std::unsigned_integral<Delay>)
void dsm::TrafficLight< Id, Size, 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 Id , typename Size , typename Delay >
requires (std::unsigned_integral<Id> && std::unsigned_integral<Size> && std::unsigned_integral<Delay>)
void dsm::TrafficLight< Id, Size, 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

◆ setPhase()

template<typename Id , typename Size , typename Delay >
requires (std::unsigned_integral<Id> && std::unsigned_integral<Size> && std::unsigned_integral<Delay>)
void dsm::TrafficLight< Id, Size, 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 Id , typename Size , typename Delay >
requires (std::unsigned_integral<Id> && std::unsigned_integral<Size> && std::unsigned_integral<Delay>)
void dsm::TrafficLight< Id, Size, 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: