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-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // A traffic lights logic which represents a tls in an off-mode
18 /****************************************************************************/
19 // ===========================================================================
20 // included modules
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", TLTYPE_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, -1));
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 
146 /****************************************************************************/
147 
MSTrafficLightLogic::Phases myPhaseDefinition
The phase definition (only one)
Builds detectors for microsim.
long long int SUMOTime
Definition: SUMOTime.h:36
virtual void init(NLDetectorBuilder &nb)
Initialises the tls with information about incoming lanes.
void adaptLinkInformationFrom(const MSTrafficLightLogic &logic)
Applies information about controlled links and lanes from the given logic.
void rebuildPhase()
(Re)builds the internal phase definition
int getIndexFromOffset(SUMOTime offset) const
Returns the step (the phasenumber) of a given position of the cycle.
const std::string & getID() const
Returns the id.
Definition: Named.h:78
#define TIME2STEPS(x)
Definition: SUMOTime.h:60
const LinkVectorVector & getLinks() const
Returns the list of lists of all affected links.
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:241
A class that stores and controls tls and switching of their programs.
int getPhaseNumber() const
Returns the number of phases.
const MSPhaseDefinition & getCurrentPhaseDef() const
Returns the definition of the current phase.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
MSOffTrafficLightLogic(MSTLLogicControl &tlcontrol, const std::string &id)
Constructor.
SUMOTime myDefaultCycleTime
The cycle time (without changes)
SUMOTime getOffsetFromIndex(int index) const
Returns the position (start of a phase during a cycle) from of a given step.
virtual void adaptLinkInformationFrom(const MSTrafficLightLogic &logic)
Applies information about controlled links and lanes from the given logic.
const MSPhaseDefinition & getPhase(int givenstep) const
Returns the definition of the phase from the given position within the plan.
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...
int getCurrentPhaseIndex() const
Returns the current index within the program.
const Phases & getPhases() const
Returns the phases of this tls program.
The parent class for traffic light logics.
The definition of a single phase of a tls logic.
SUMOTime getPhaseIndexAtTime(SUMOTime simStep) const
Returns the index of the logic at the given simulation step.