Eclipse SUMO - Simulation of Urban MObility
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-2024 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"
30 #include "MSOffTrafficLightLogic.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 
49 void
51  rebuildPhase();
52 }
53 
54 
55 // ----------- Handling of controlled links
56 void
59  rebuildPhase();
60 }
61 
62 
63 void
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
97 int
99  return 0;
100 }
101 
102 
105  return myPhaseDefinition;
106 }
107 
108 
109 const MSPhaseDefinition&
111  return *myPhaseDefinition[0];
112 }
113 
114 
115 // ------------ Dynamic Information Retrieval
116 int
118  return 0;
119 }
120 
121 
122 const MSPhaseDefinition&
124  return *myPhaseDefinition[0];
125 }
126 
127 
128 // ------------ Conversion between time and phase
129 SUMOTime
131  return 0;
132 }
133 
134 
135 SUMOTime
137  return 0;
138 }
139 
140 
141 int
143  return 0;
144 }
145 
146 
147 /****************************************************************************/
long long int SUMOTime
Definition: GUI.h:35
#define WRITE_WARNINGF(...)
Definition: MsgHandler.h:296
#define TL(string)
Definition: MsgHandler.h:315
#define TIME2STEPS(x)
Definition: SUMOTime.h:57
TrafficLightType
@ 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:46
const Phases & getPhases() const
Returns the phases of this tls program.
MSOffTrafficLightLogic(MSTLLogicControl &tlcontrol, const std::string &id)
Constructor.
const MSPhaseDefinition & getCurrentPhaseDef() const
Returns the definition of the current phase.
int getPhaseNumber() const
Returns the number of phases.
void adaptLinkInformationFrom(const MSTrafficLightLogic &logic)
Applies information about controlled links and lanes from the given logic.
SUMOTime getPhaseIndexAtTime(SUMOTime simStep) const
Returns the index of the logic at the given simulation step.
int getIndexFromOffset(SUMOTime offset) const
Returns the step (the phasenumber) of a given position of the cycle.
int getCurrentPhaseIndex() const
Returns the current index within the program.
SUMOTime getOffsetFromIndex(int index) const
Returns the position (start of a phase during a cycle) from of a given step.
MSTrafficLightLogic::Phases myPhaseDefinition
The phase definition (only one)
const MSPhaseDefinition & getPhase(int givenstep) const
Returns the definition of the phase from the given position within the plan.
void rebuildPhase()
(Re)builds the internal phase definition
virtual void init(NLDetectorBuilder &nb)
Initialises the tls with information about incoming lanes.
The definition of a single phase of a tls logic.
A class that stores and controls tls and switching of their programs.
The parent class for traffic light logics.
virtual void adaptLinkInformationFrom(const MSTrafficLightLogic &logic)
Applies information about controlled links and lanes from the given logic.
const LinkVectorVector & getLinks() const
Returns the list of lists of all affected links.
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.
Definition: Parameterised.h:41
std::map< std::string, std::string > Map
parameters map
Definition: Parameterised.h:45