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.org/sumo
3 // Copyright (C) 2001-2022 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  const std::string& id) :
38  MSTrafficLightLogic(tlcontrol, id, "off", 0, TrafficLightType::OFF, 0, std::map<std::string, std::string>()) {
40 }
41 
42 
44  for (MSTrafficLightLogic::Phases::const_iterator i = myPhaseDefinition.begin(); i != myPhaseDefinition.end(); ++i) {
45  delete *i;
46  }
47 }
48 
49 
50 void
52  rebuildPhase();
53 }
54 
55 
56 // ----------- Handling of controlled links
57 void
60  rebuildPhase();
61 }
62 
63 
64 void
66  int no = (int)getLinks().size();
67  std::string state;
68  for (int i = 0; i < no; ++i) {
69  bool foundMajor = false;
70  bool foundMinor = false;
71  for (const MSLink* l : myLinks[i]) {
73  if (l->getOffState() == 'o') {
74  foundMinor = true;
75  } else if (l->getOffState() == 'O') {
76  foundMajor = true;
77  } else {
78  WRITE_WARNING("Invalid 'off'-state for link " + toString(l->getIndex()) + " at junction '" + l->getJunction()->getID() + "'");
79  }
80  }
81  if (foundMajor && foundMinor) {
82  WRITE_WARNING("Inconsistent 'off'-states for linkIndex " + toString(i) + " at tlLogic '" + getID() + "'");
83  }
84  state += foundMinor ? 'o' : 'O';
85  }
86  for (MSTrafficLightLogic::Phases::const_iterator i = myPhaseDefinition.begin(); i != myPhaseDefinition.end(); ++i) {
87  delete *i;
88  }
89  myPhaseDefinition.clear();
90  myPhaseDefinition.push_back(new MSPhaseDefinition(TIME2STEPS(120), state));
91 }
92 
93 
94 // ------------ Static Information Retrieval
95 int
97  return 0;
98 }
99 
100 
103  return myPhaseDefinition;
104 }
105 
106 
107 const MSPhaseDefinition&
109  return *myPhaseDefinition[0];
110 }
111 
112 
113 // ------------ Dynamic Information Retrieval
114 int
116  return 0;
117 }
118 
119 
120 const MSPhaseDefinition&
122  return *myPhaseDefinition[0];
123 }
124 
125 
126 // ------------ Conversion between time and phase
127 SUMOTime
129  return 0;
130 }
131 
132 
133 SUMOTime
135  return 0;
136 }
137 
138 
139 int
141  return 0;
142 }
143 
144 
145 /****************************************************************************/
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:280
#define TIME2STEPS(x)
Definition: SUMOTime.h:55
long long int SUMOTime
Definition: SUMOTime.h:32
TrafficLightType
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