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-2019 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 /****************************************************************************/
16 // A traffic lights logic which represents a tls in an off-mode
17 /****************************************************************************/
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 #include <config.h>
22 
23 #include <utility>
24 #include <vector>
25 #include <bitset>
26 #include <sstream>
28 #include "MSTrafficLightLogic.h"
29 #include "MSOffTrafficLightLogic.h"
30 
31 
32 // ===========================================================================
33 // member method definitions
34 // ===========================================================================
36  const std::string& id) :
37  MSTrafficLightLogic(tlcontrol, id, "off", TLTYPE_OFF, 0, std::map<std::string, std::string>()) {
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  for (const MSLink* l : myLinks[i]) {
72  if (l->getOffState() == 'o') {
73  foundMinor = true;
74  } else if (l->getOffState() == 'O') {
75  foundMajor = true;
76  } else {
77  WRITE_WARNING("Invalid 'off'-state for link " + toString(l->getIndex()) + " at junction '" + l->getJunction()->getID() + "'");
78  }
79  }
80  if (foundMajor && foundMinor) {
81  WRITE_WARNING("Inconsistent 'off'-states for linkIndex " + toString(i) + " at tlLogic '" + getID() + "'");
82  }
83  state += foundMinor ? 'o' : 'O';
84  }
85  for (MSTrafficLightLogic::Phases::const_iterator i = myPhaseDefinition.begin(); i != myPhaseDefinition.end(); ++i) {
86  delete *i;
87  }
88  myPhaseDefinition.clear();
89  myPhaseDefinition.push_back(new MSPhaseDefinition(TIME2STEPS(120), state, -1));
90 }
91 
92 
93 // ------------ Static Information Retrieval
94 int
96  return 0;
97 }
98 
99 
102  return myPhaseDefinition;
103 }
104 
105 
106 const MSPhaseDefinition&
108  return *myPhaseDefinition[0];
109 }
110 
111 
112 // ------------ Dynamic Information Retrieval
113 int
115  return 0;
116 }
117 
118 
119 const MSPhaseDefinition&
121  return *myPhaseDefinition[0];
122 }
123 
124 
125 // ------------ Conversion between time and phase
126 SUMOTime
128  return 0;
129 }
130 
131 
132 SUMOTime
134  return 0;
135 }
136 
137 
138 int
140  return 0;
141 }
142 
143 
144 
145 /****************************************************************************/
146 
MSTrafficLightLogic::myLinks
LinkVectorVector myLinks
The list of LinkVectors; each vector contains the links that belong to the same link index.
Definition: MSTrafficLightLogic.h:417
MSOffTrafficLightLogic::getPhase
const MSPhaseDefinition & getPhase(int givenstep) const
Returns the definition of the phase from the given position within the plan.
Definition: MSOffTrafficLightLogic.cpp:107
WRITE_WARNING
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:275
MSOffTrafficLightLogic::~MSOffTrafficLightLogic
~MSOffTrafficLightLogic()
Destructor.
Definition: MSOffTrafficLightLogic.cpp:42
MSOffTrafficLightLogic::getCurrentPhaseIndex
int getCurrentPhaseIndex() const
Returns the current index within the program.
Definition: MSOffTrafficLightLogic.cpp:114
MSOffTrafficLightLogic.h
MSTrafficLightLogic::Phases
std::vector< MSPhaseDefinition * > Phases
Definition of a list of phases, being the junction logic.
Definition: MSTrafficLightLogic.h:61
MSOffTrafficLightLogic::getPhases
const Phases & getPhases() const
Returns the phases of this tls program.
Definition: MSOffTrafficLightLogic.cpp:101
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
MSTrafficLightLogic::adaptLinkInformationFrom
virtual void adaptLinkInformationFrom(const MSTrafficLightLogic &logic)
Applies information about controlled links and lanes from the given logic.
Definition: MSTrafficLightLogic.cpp:214
MSTrafficLightLogic.h
TIME2STEPS
#define TIME2STEPS(x)
Definition: SUMOTime.h:58
MSOffTrafficLightLogic::getPhaseIndexAtTime
SUMOTime getPhaseIndexAtTime(SUMOTime simStep) const
Returns the index of the logic at the given simulation step.
Definition: MSOffTrafficLightLogic.cpp:127
MSTrafficLightLogic
The parent class for traffic light logics.
Definition: MSTrafficLightLogic.h:55
MSOffTrafficLightLogic::myPhaseDefinition
MSTrafficLightLogic::Phases myPhaseDefinition
The phase definition (only one)
Definition: MSOffTrafficLightLogic.h:198
MSOffTrafficLightLogic::rebuildPhase
void rebuildPhase()
(Re)builds the internal phase definition
Definition: MSOffTrafficLightLogic.cpp:64
MSOffTrafficLightLogic::getIndexFromOffset
int getIndexFromOffset(SUMOTime offset) const
Returns the step (the phasenumber) of a given position of the cycle.
Definition: MSOffTrafficLightLogic.cpp:139
MSOffTrafficLightLogic::init
virtual void init(NLDetectorBuilder &nb)
Initialises the tls with information about incoming lanes.
Definition: MSOffTrafficLightLogic.cpp:50
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:47
MSTrafficLightLogic::getLinks
const LinkVectorVector & getLinks() const
Returns the list of lists of all affected links.
Definition: MSTrafficLightLogic.h:203
MSOffTrafficLightLogic::adaptLinkInformationFrom
void adaptLinkInformationFrom(const MSTrafficLightLogic &logic)
Applies information about controlled links and lanes from the given logic.
Definition: MSOffTrafficLightLogic.cpp:57
config.h
MSTrafficLightLogic::myDefaultCycleTime
SUMOTime myDefaultCycleTime
The cycle time (without changes)
Definition: MSTrafficLightLogic.h:432
TLTYPE_OFF
Definition: SUMOXMLDefinitions.h:1210
MSTLLogicControl
A class that stores and controls tls and switching of their programs.
Definition: MSTLLogicControl.h:59
MSEventControl.h
MSPhaseDefinition
The definition of a single phase of a tls logic.
Definition: MSPhaseDefinition.h:51
MSOffTrafficLightLogic::getCurrentPhaseDef
const MSPhaseDefinition & getCurrentPhaseDef() const
Returns the definition of the current phase.
Definition: MSOffTrafficLightLogic.cpp:120
MSOffTrafficLightLogic::MSOffTrafficLightLogic
MSOffTrafficLightLogic(MSTLLogicControl &tlcontrol, const std::string &id)
Constructor.
Definition: MSOffTrafficLightLogic.cpp:35
Named::getID
const std::string & getID() const
Returns the id.
Definition: Named.h:76
MSOffTrafficLightLogic::getOffsetFromIndex
SUMOTime getOffsetFromIndex(int index) const
Returns the position (start of a phase during a cycle) from of a given step.
Definition: MSOffTrafficLightLogic.cpp:133
NLDetectorBuilder
Builds detectors for microsim.
Definition: NLDetectorBuilder.h:55
MSOffTrafficLightLogic::getPhaseNumber
int getPhaseNumber() const
Returns the number of phases.
Definition: MSOffTrafficLightLogic.cpp:95