Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSOffTrafficLightLogic.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2026 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
20// A traffic lights logic which represents a tls in an off-mode
21/****************************************************************************/
22#include <config.h>
23
24#include <utility>
25#include <vector>
26#include <bitset>
27#include <sstream>
29#include "MSTrafficLightLogic.h"
31
32
33// ===========================================================================
34// member method definitions
35// ===========================================================================
37 MSTrafficLightLogic(tlcontrol, id, "off", 0, TrafficLightType::OFF, 0, Parameterised::Map()) {
39}
40
41
43 for (MSTrafficLightLogic::Phases::const_iterator i = myPhaseDefinition.begin(); i != myPhaseDefinition.end(); ++i) {
44 delete *i;
45 }
46}
47
48
49void
53
54
55// ----------- Handling of controlled links
56void
61
62
63void
65 int no = (int)getLinks().size();
66 std::string state;
67 for (int i = 0; i < no; ++i) {
68 bool foundMajor = false;
69 bool foundMinor = false;
70 bool foundAllwayStop = false;
71 for (const MSLink* l : myLinks[i]) {
73 if (l->getOffState() == LINKSTATE_TL_OFF_BLINKING) {
74 foundMinor = true;
75 } else if (l->getOffState() == LINKSTATE_TL_OFF_NOSIGNAL) {
76 foundMajor = true;
77 } else if (l->getOffState() == LINKSTATE_ALLWAY_STOP) {
78 foundAllwayStop = true;
79 } else {
80 WRITE_WARNINGF(TL("Invalid 'off'-state for link % at junction '%'"), toString(l->getIndex()), l->getJunction()->getID());
81 }
82 }
83 if (foundMajor && foundMinor) {
84 WRITE_WARNINGF(TL("Inconsistent 'off'-states for linkIndex % at tlLogic '%'"), toString(i), getID());
85 }
86 state += toString(foundAllwayStop ? LINKSTATE_ALLWAY_STOP : (foundMinor ? LINKSTATE_TL_OFF_BLINKING : LINKSTATE_TL_OFF_NOSIGNAL));
87 }
88 for (MSTrafficLightLogic::Phases::const_iterator i = myPhaseDefinition.begin(); i != myPhaseDefinition.end(); ++i) {
89 delete *i;
90 }
91 myPhaseDefinition.clear();
92 myPhaseDefinition.push_back(new MSPhaseDefinition(TIME2STEPS(120), state));
93}
94
95
96// ------------ Static Information Retrieval
97int
99 return 0;
100}
101
102
107
108
111 return *myPhaseDefinition[0];
112}
113
114
115// ------------ Dynamic Information Retrieval
116int
120
121
126
127
128void
132
133
134// ------------ Conversion between time and phase
139
140
143 return 0;
144}
145
146
147int
151
152
153/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:287
#define TL(string)
Definition MsgHandler.h:304
#define TIME2STEPS(x)
Definition SUMOTime.h:60
@ LINKSTATE_ALLWAY_STOP
This is an uncontrolled, all-way stop link.
@ LINKSTATE_TL_OFF_BLINKING
The link is controlled by a tls which is off and blinks, has to brake.
@ LINKSTATE_TL_OFF_NOSIGNAL
The link is controlled by a tls which is off, not blinking, may pass.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:49
void resetLastSwitch(SUMOTime t) override
SUMOTime getPhaseIndexAtTime(SUMOTime simStep) const override
Returns the index of the logic at the given simulation step.
SUMOTime getOffsetFromIndex(int index) const override
Returns the position (start of a phase during a cycle) from of a given step.
MSOffTrafficLightLogic(MSTLLogicControl &tlcontrol, const std::string &id)
Constructor.
const MSPhaseDefinition & getCurrentPhaseDef() const override
Returns the definition of the current phase.
const MSPhaseDefinition & getPhase(int givenstep) const override
Returns the definition of the phase from the given position within the plan.
int getIndexFromOffset(SUMOTime offset) const override
Returns the step (the phasenumber) of a given position of the cycle.
void adaptLinkInformationFrom(const MSTrafficLightLogic &logic) override
Applies information about controlled links and lanes from the given logic.
const Phases & getPhases() const override
Returns the phases of this tls program.
int getPhaseNumber() const override
Returns the number of phases.
MSTrafficLightLogic::Phases myPhaseDefinition
The phase definition (only one)
int getCurrentPhaseIndex() const override
Returns the current index within the program.
void rebuildPhase()
(Re)builds the internal phase definition
virtual void init(NLDetectorBuilder &nb) override
Initialises the tls with information about incoming lanes.
The definition of a single phase of a tls logic.
SUMOTime myLastSwitch
Stores the timestep of the last on-switched of the phase.
A class that stores and controls tls and switching of their programs.
The parent class for traffic light logics.
const LinkVectorVector & getLinks() const
Returns the list of lists of all affected links.
virtual void adaptLinkInformationFrom(const MSTrafficLightLogic &logic)
Applies information about controlled links and lanes from the given logic.
SUMOTime myDefaultCycleTime
The cycle time (without changes)
std::vector< MSPhaseDefinition * > Phases
Definition of a list of phases, being the junction logic.
LinkVectorVector myLinks
The list of LinkVectors; each vector contains the links that belong to the same link index.
Builds detectors for microsim.
const std::string & getID() const
Returns the id.
Definition Named.h:74
An upper class for objects with additional parameters.
std::map< std::string, std::string > Map
parameters map