Dynamical System Framework
Loading...
Searching...
No Matches
dsf::mobility::TrafficLight Class Referencefinal
Inheritance diagram for dsf::mobility::TrafficLight:
dsf::mobility::Intersection dsf::mobility::RoadJunction dsf::Node

Public Member Functions

 TrafficLight (Id const id)
 Construct a new Traffic Light object.
 TrafficLight (Id const id, geometry::Point point)
 Construct a new Traffic Light object with a location.
 TrafficLight (RoadJunction const &node)
 Construct a new Traffic Light object from a road junction.
TrafficLightoperator++ ()
 Advance by one simulation tick. When the counter reaches the current phase's duration the machine moves to the next phase (wrapping) and resets the counter to 0.
void setAllowFreeTurns (bool const allow)
 When true, a street absent from the active phase's green set is treated as green (free turn).
void addPhase (TrafficLightPhase phase)
 Append one phase to the sequence and update stored defaults. Resets the state machine to phase 0, counter 0.
void setPhases (std::vector< TrafficLightPhase > phases)
 Replace the entire phase sequence and update stored defaults. Resets the state machine to phase 0, counter 0.
void clearPhases ()
 Remove all phases and clear all stored defaults/snapshots.
void snapshot ()
 Save the current phase sequence as a restore point. Does NOT reset the running counter or current phase index.
void restore ()
 Restore the phase sequence to the last snapshot(). Resets m_currentPhaseIndex and m_counter to 0. Logs a warning and is a no-op if no snapshot exists.
void reset ()
 Restore the phase sequence to construction-time defaults (the state after the last setPhases() / addPhase() chain). Resets m_currentPhaseIndex and m_counter to 0.
bool isGreen (Id const streetId, Direction const direction) const
 Returns true if the light is currently green for (streetId, direction), applying the fallback ladder: exact direction → ANY → compound (RIGHTANDSTRAIGHT/LEFTANDSTRAIGHT). Returns m_allowFreeTurns when streetId is absent from the active phase.
Delay cycleTime () const
 Total cycle time = sum of all phase durations.
double meanGreenTime (bool priorityStreets) const
 Mean green time (ticks) across priority or non-priority streets. A street's green time = sum of durations of phases that list it.
bool isDefault () const
 True if the live phase sequence equals the stored defaults.
void advanceBy (Delay offset)
 Fast-forward the state machine by offset ticks. offset is taken modulo cycleTime() so large values are safe. Used by the DOUBLE_TAIL optimiser.
Delay counter () const
std::size_t currentPhaseIndex () const
std::vector< TrafficLightPhase > const & phases () const
 Read-only view of the live phase sequence.
std::vector< TrafficLightPhase > const & defaultPhases () const
 Read-only view of the default (baseline) phase sequence. Used by the optimiser to access baseline durations without mutating the live sequence.
TrafficLightPhasephase (std::size_t index)
 Mutable access to one live phase (intended for optimiser only).
constexpr bool isTrafficLight () const noexcept
Public Member Functions inherited from dsf::mobility::Intersection
 Intersection (Id id)
 Construct a new Intersection object.
 Intersection (Id id, geometry::Point coords)
 Construct a new Intersection object.
 Intersection (RoadJunction const &node)
 Intersection (Intersection const &)=delete
void setCapacity (std::size_t const capacity) override
 Set the node's capacity.
void addAgent (double angle, std::unique_ptr< Agent > pAgent)
 Put an agent in the node.
void addAgent (std::unique_ptr< Agent > pAgent)
 Put an agent in 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.
auto nAgents () const noexcept
 Returns the number of agents currently in the node.
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.
std::multimap< int16_t, std::unique_ptr< Agent > > & agents ()
 Get the node's agent ids.
constexpr bool isIntersection () const noexcept final
Public Member Functions inherited from dsf::mobility::RoadJunction
 RoadJunction (Id id)
 RoadJunction (Id id, geometry::Point coords)
 RoadJunction (RoadJunction const &other)
RoadJunction & operator= (RoadJunction const &other)
void setTransportCapacity (double capacity)
 Set the junction's transport capacity.
std::size_t capacity () const
 Get the junction's capacity.
double transportCapacity () const
 Get the junction's transport capacity.
virtual constexpr bool isRoundabout () const noexcept
Public Member Functions inherited from dsf::Node
 Node (Id id)
 Construct a new Node object with capacity 1.
 Node (Id id, geometry::Point point)
 Construct a new Node object with capacity 1.
 Node (Node const &other)
Nodeoperator= (Node const &other)
void setId (Id id) noexcept
 Set the node's id.
void setGeometry (geometry::Point point) noexcept
 Set the node's geometry.
void setName (const std::string &name) noexcept
 Set the node's name.
void addIngoingEdge (Id edgeId)
 Add an ingoing edge to the node.
void addOutgoingEdge (Id edgeId)
 Add an outgoing edge to the node.
void setAttribute (std::string const &name, std::variant< std::monostate, bool, std::int64_t, double, std::string > const &value)
 Set an attribute for the node.
auto id () const
 Get the node's id.
auto const & geometry () const noexcept
 Get the node's geometry.
auto const & name () const noexcept
 Get the node's name.
auto const & ingoingEdges () const noexcept
 Get the node's ingoing edges.
auto const & outgoingEdges () const noexcept
 Get the node's outgoing edges.
auto const & attributes () const noexcept
 Get the node's attributes.
template<typename T>
std::optional< T > getAttribute (std::string const &name) const
 Get a specific attribute of the node.

Additional Inherited Members

Protected Attributes inherited from dsf::mobility::Intersection
std::multimap< int16_t, std::unique_ptr< Agent > > m_agents
std::set< Id > m_streetPriorities
Protected Attributes inherited from dsf::Node
Id m_id
std::optional< geometry::Pointm_geometry
std::string m_name
std::vector< Id > m_ingoingEdges
std::vector< Id > m_outgoingEdges
std::unordered_map< std::string, std::variant< std::monostate, bool, std::int64_t, double, std::string > > m_attributes

Constructor & Destructor Documentation

◆ TrafficLight() [1/3]

dsf::mobility::TrafficLight::TrafficLight ( Id const id)
inlineexplicit

Construct a new Traffic Light object.

Parameters
idThe node's id

◆ TrafficLight() [2/3]

dsf::mobility::TrafficLight::TrafficLight ( Id const id,
geometry::Point point )
inline

Construct a new Traffic Light object with a location.

Parameters
idThe node's id
pointThe location of the traffic light

◆ TrafficLight() [3/3]

dsf::mobility::TrafficLight::TrafficLight ( RoadJunction const & node)
inlineexplicit

Construct a new Traffic Light object from a road junction.

Parameters
nodeThe road junction to convert into a traffic light

Member Function Documentation

◆ isGreen()

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

Returns true if the light is currently green for (streetId, direction), applying the fallback ladder: exact direction → ANY → compound (RIGHTANDSTRAIGHT/LEFTANDSTRAIGHT). Returns m_allowFreeTurns when streetId is absent from the active phase.

Parameters
streetIdStreet identifier.
directionDirection of the movement.
Returns
True if the light is currently green for the given street and direction.

◆ isTrafficLight()

bool dsf::mobility::TrafficLight::isTrafficLight ( ) const
inlineconstexprvirtualnoexcept

Reimplemented from dsf::mobility::RoadJunction.

◆ setAllowFreeTurns()

void dsf::mobility::TrafficLight::setAllowFreeTurns ( bool const allow)
inline

When true, a street absent from the active phase's green set is treated as green (free turn).

Note
Default is false.

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