Eclipse SUMO - Simulation of Urban MObility
NBLoadedTLDef.h
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 /****************************************************************************/
15 // A loaded (complete) traffic light logic
16 /****************************************************************************/
17 #ifndef NBLoadedTLDef_h
18 #define NBLoadedTLDef_h
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include <vector>
27 #include <string>
28 #include <set>
30 #include "NBNode.h"
31 #include <utils/common/SUMOTime.h>
32 
33 
34 // ===========================================================================
35 // class definitions
36 // ===========================================================================
42 public:
46  class SignalGroup : public Named {
47  public:
51  SignalGroup(const std::string& id);
52 
54  ~SignalGroup();
55 
59  void addConnection(const NBConnection& c);
60 
65  void addPhaseBegin(SUMOTime time, TLColor color);
66 
71  void setYellowTimes(SUMOTime tRedYellowe, SUMOTime tYellow);
72 
77  std::vector<double> getTimes(SUMOTime cycleDuration) const;
78 
80  void sortPhases();
81 
85  int getLinkNo() const;
86 
91  bool mayDrive(SUMOTime time) const;
92 
97  bool hasYellow(SUMOTime time) const;
98 
104  bool containsConnection(NBEdge* from, NBEdge* to) const;
105 
110  bool containsIncoming(NBEdge* from) const;
111 
116  void remapIncoming(NBEdge* which, const EdgeVector& by);
117 
122  bool containsOutgoing(NBEdge* to) const;
123 
128  void remapOutgoing(NBEdge* which, const EdgeVector& by);
129 
134  const NBConnection& getConnection(int pos) const;
135 
140  void patchTYellow(int tyellow, bool forced);
141 
148  void remap(NBEdge* removed, int removedLane, NBEdge* by, int byLane);
149 
153  class PhaseDef {
154  public:
159  PhaseDef(SUMOTime time, TLColor color)
160  : myTime(time), myColor(color) { }
161 
166  };
167 
172  public:
174  explicit phase_by_time_sorter() { }
175 
180  int operator()(const PhaseDef& p1, const PhaseDef& p2) {
181  return p1.myTime < p2.myTime;
182  }
183  };
184 
185  private:
189  std::vector<PhaseDef> myPhases;
192  };
193 
194 
195 
197  typedef std::map<std::string, SignalGroup*> SignalGroupCont;
198 
199 
206  NBLoadedTLDef(const NBEdgeCont& ec, const std::string& id,
207  const std::vector<NBNode*>& junctions, SUMOTime offset,
208  TrafficLightType type);
209 
210 
217  NBLoadedTLDef(const NBEdgeCont& ec, const std::string& id, NBNode* junction, SUMOTime offset,
218  TrafficLightType type);
219 
220 
226  NBLoadedTLDef(const NBEdgeCont& ec, const std::string& id, SUMOTime offset,
227  TrafficLightType type);
228 
229 
231  ~NBLoadedTLDef();
232 
233 
239  SignalGroup* findGroup(NBEdge* from, NBEdge* to) const;
240 
241 
245  void setCycleDuration(int cycleDur);
246 
247 
251  void addSignalGroup(const std::string& id);
252 
253 
258  bool addToSignalGroup(const std::string& groupid,
259  const NBConnection& connection);
260 
261 
266  bool addToSignalGroup(const std::string& groupid,
267  const NBConnectionVector& connections);
268 
269 
275  void addSignalGroupPhaseBegin(const std::string& groupid,
276  SUMOTime time, TLColor color);
277 
278 
284  void setSignalYellowTimes(const std::string& groupid,
285  SUMOTime tRedYellow, SUMOTime tYellow);
286 
287 
290 
295  void setTLControllingInformation() const;
296 
297 
304  void remapRemoved(NBEdge* removed,
305  const EdgeVector& incoming, const EdgeVector& outgoing);
306 
307  /* initialize myNeedsContRelation and set myNeedsContRelationReady to true */
308  void initNeedsContRelation() const;
309 
311  int getMaxIndex();
312 
314 
315 
316 protected:
319 
325  NBTrafficLightLogic* myCompute(int brakingTimeSeconds);
326 
331 
332 
336  void collectNodes();
337 
338 
343  void collectLinks();
344 
345 
352  bool mustBrake(const NBConnection& possProhibited,
353  const std::string& state,
354  int strmpos) const;
355 
356 
364  void replaceRemoved(NBEdge* removed, int removedLane,
365  NBEdge* by, int byLane);
367 
368 private:
374  std::string buildPhaseState(int time) const;
375 
376  // pointer to the NBEdgeCont for checking edges
378 
379 
380 private:
383 
386 
387 
388 };
389 
390 
391 #endif
392 
393 /****************************************************************************/
394 
NBLoadedTLDef::SignalGroup::myTYellow
SUMOTime myTYellow
Definition: NBLoadedTLDef.h:191
NBLoadedTLDef::SignalGroup::PhaseDef::myTime
SUMOTime myTime
The begin time of this phase.
Definition: NBLoadedTLDef.h:163
SUMOTime.h
NBLoadedTLDef::SignalGroup::hasYellow
bool hasYellow(SUMOTime time) const
Returns whether controlled links have yellow at the given time.
Definition: NBLoadedTLDef.cpp:130
Named
Base class for objects which have an id.
Definition: Named.h:56
NBEdgeCont
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:60
NBLoadedTLDef::collectNodes
void collectNodes()
Collects the nodes participating in this traffic light.
Definition: NBLoadedTLDef.cpp:483
NBLoadedTLDef::SignalGroup::phase_by_time_sorter::phase_by_time_sorter
phase_by_time_sorter()
Constructor.
Definition: NBLoadedTLDef.h:174
NBLoadedTLDef::SignalGroup::addConnection
void addConnection(const NBConnection &c)
Inserts a controlled connection.
Definition: NBLoadedTLDef.cpp:50
NBLoadedTLDef::SignalGroup::PhaseDef::myColor
TLColor myColor
A signal's color from this time.
Definition: NBLoadedTLDef.h:165
NBLoadedTLDef::addSignalGroup
void addSignalGroup(const std::string &id)
Adds a signal group.
Definition: NBLoadedTLDef.cpp:594
NBLoadedTLDef::SignalGroup
A single signal group, may control several connections.
Definition: NBLoadedTLDef.h:46
NBLoadedTLDef::SignalGroup::patchTYellow
void patchTYellow(int tyellow, bool forced)
Sets the yellow time.
Definition: NBLoadedTLDef.cpp:76
NBLoadedTLDef::SignalGroup::PhaseDef::PhaseDef
PhaseDef(SUMOTime time, TLColor color)
Constructor.
Definition: NBLoadedTLDef.h:159
EdgeVector
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
Definition: NBCont.h:34
NBLoadedTLDef::SignalGroup::myPhases
std::vector< PhaseDef > myPhases
The phases of this signal.
Definition: NBLoadedTLDef.h:189
NBLoadedTLDef::SignalGroup::getLinkNo
int getLinkNo() const
Returns the number of links (connection) controlled by this signal.
Definition: NBLoadedTLDef.cpp:111
NBLoadedTLDef::SignalGroup::setYellowTimes
void setYellowTimes(SUMOTime tRedYellowe, SUMOTime tYellow)
Sets the times for redyellow and yellow.
Definition: NBLoadedTLDef.cpp:63
TrafficLightType
TrafficLightType
Definition: SUMOXMLDefinitions.h:1197
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
NBTrafficLightDefinition.h
NBLoadedTLDef::SignalGroup::phase_by_time_sorter::operator()
int operator()(const PhaseDef &p1, const PhaseDef &p2)
Sorts phases by their begin time.
Definition: NBLoadedTLDef.h:180
NBLoadedTLDef::addSignalGroupPhaseBegin
void addSignalGroupPhaseBegin(const std::string &groupid, SUMOTime time, TLColor color)
Sets the information about the begin of a phase.
Definition: NBLoadedTLDef.cpp:601
NBLoadedTLDef::mySignalGroups
SignalGroupCont mySignalGroups
Controlled signal groups.
Definition: NBLoadedTLDef.h:382
NBLoadedTLDef::SignalGroup::myConnections
NBConnectionVector myConnections
Connections controlled by this signal.
Definition: NBLoadedTLDef.h:187
NBLoadedTLDef::setCycleDuration
void setCycleDuration(int cycleDur)
Sets the duration of a cycle.
Definition: NBLoadedTLDef.cpp:616
NBEdge
The representation of a single edge during network building.
Definition: NBEdge.h:91
NBLoadedTLDef::setTLControllingInformation
void setTLControllingInformation() const
Informs edges about being controlled by a tls.
Definition: NBLoadedTLDef.cpp:368
NBLoadedTLDef::SignalGroup::containsOutgoing
bool containsOutgoing(NBEdge *to) const
Returns whether this signal controls a connection where the given edge is the destination.
Definition: NBLoadedTLDef.cpp:191
NBLoadedTLDef::SignalGroup::myTRedYellow
SUMOTime myTRedYellow
The times of redyellow and yellow.
Definition: NBLoadedTLDef.h:191
NBTrafficLightDefinition::TLColor
TLColor
An enumeration of possible tl-signal states.
Definition: NBTrafficLightDefinition.h:77
NBLoadedTLDef::setSignalYellowTimes
void setSignalYellowTimes(const std::string &groupid, SUMOTime tRedYellow, SUMOTime tYellow)
Sets the times the light is yellow or red/yellow.
Definition: NBLoadedTLDef.cpp:608
NBLoadedTLDef::SignalGroup::getConnection
const NBConnection & getConnection(int pos) const
Returns the connection at the given index.
Definition: NBLoadedTLDef.cpp:150
NBLoadedTLDef::remapRemoved
void remapRemoved(NBEdge *removed, const EdgeVector &incoming, const EdgeVector &outgoing)
Replaces occurences of the removed edge in incoming/outgoing edges of all definitions.
Definition: NBLoadedTLDef.cpp:622
NBLoadedTLDef::SignalGroup::mayDrive
bool mayDrive(SUMOTime time) const
Returns whether vehicles on controlled links may drive at the given time.
Definition: NBLoadedTLDef.cpp:117
NBLoadedTLDef::mustBrake
bool mustBrake(const NBConnection &possProhibited, const std::string &state, int strmpos) const
Returns the information whether a connection must brake, given a phase.
Definition: NBLoadedTLDef.cpp:434
NBConnection
Definition: NBConnection.h:43
NBLoadedTLDef::SignalGroup::containsIncoming
bool containsIncoming(NBEdge *from) const
Returns whether this signal controls the given edge.
Definition: NBLoadedTLDef.cpp:157
NBLoadedTLDef::myCycleDuration
int myCycleDuration
The duration of a single cycle.
Definition: NBLoadedTLDef.h:385
NBLoadedTLDef::collectLinks
void collectLinks()
Collects the links participating in this traffic light.
Definition: NBLoadedTLDef.cpp:501
NBLoadedTLDef::SignalGroup::~SignalGroup
~SignalGroup()
Destructor.
Definition: NBLoadedTLDef.cpp:47
NBLoadedTLDef::SignalGroup::SignalGroup
SignalGroup(const std::string &id)
Constructor.
Definition: NBLoadedTLDef.cpp:44
NBLoadedTLDef::SignalGroup::remapIncoming
void remapIncoming(NBEdge *which, const EdgeVector &by)
Replaces the given incoming edge by the others given.
Definition: NBLoadedTLDef.cpp:168
NBLoadedTLDef::SignalGroup::phase_by_time_sorter
Sorts phases by their begin time.
Definition: NBLoadedTLDef.h:171
NBLoadedTLDef::replaceRemoved
void replaceRemoved(NBEdge *removed, int removedLane, NBEdge *by, int byLane)
Replaces a removed edge/lane.
Definition: NBLoadedTLDef.cpp:638
NBLoadedTLDef::SignalGroup::remapOutgoing
void remapOutgoing(NBEdge *which, const EdgeVector &by)
Replaces the given outgoing edge by the others given.
Definition: NBLoadedTLDef.cpp:202
NBLoadedTLDef::setParticipantsInformation
void setParticipantsInformation()
Builds the list of participating nodes/edges/links.
Definition: NBLoadedTLDef.cpp:474
NBLoadedTLDef
A loaded (complete) traffic light logic.
Definition: NBLoadedTLDef.h:41
NBConnectionVector
std::vector< NBConnection > NBConnectionVector
Definition of a connection vector.
Definition: NBConnectionDefs.h:34
NBLoadedTLDef::SignalGroup::PhaseDef
Definition of a single, loaded phase.
Definition: NBLoadedTLDef.h:153
NBLoadedTLDef::initNeedsContRelation
void initNeedsContRelation() const
Definition: NBLoadedTLDef.cpp:650
NBLoadedTLDef::buildPhaseState
std::string buildPhaseState(int time) const
Builds the phase for a given time.
Definition: NBLoadedTLDef.cpp:380
NBLoadedTLDef::SignalGroup::addPhaseBegin
void addPhaseBegin(SUMOTime time, TLColor color)
Sets the begin of a phase.
Definition: NBLoadedTLDef.cpp:57
NBLoadedTLDef::~NBLoadedTLDef
~NBLoadedTLDef()
Destructor.
Definition: NBLoadedTLDef.cpp:275
config.h
NBLoadedTLDef::SignalGroup::remap
void remap(NBEdge *removed, int removedLane, NBEdge *by, int byLane)
Replaces a removed edge/lane.
Definition: NBLoadedTLDef.cpp:225
NBLoadedTLDef::myCompute
NBTrafficLightLogic * myCompute(int brakingTimeSeconds)
Computes the traffic light logic finally in dependence to the type.
Definition: NBLoadedTLDef.cpp:283
NBLoadedTLDef::myEdgeCont
const NBEdgeCont * myEdgeCont
Definition: NBLoadedTLDef.h:377
NBTrafficLightLogic
A SUMO-compliant built logic for a traffic light.
Definition: NBTrafficLightLogic.h:51
NBNode
Represents a single node (junction) during network building.
Definition: NBNode.h:67
NBLoadedTLDef::SignalGroup::sortPhases
void sortPhases()
Sorts the phases.
Definition: NBLoadedTLDef.cpp:70
NBLoadedTLDef::SignalGroup::containsConnection
bool containsConnection(NBEdge *from, NBEdge *to) const
Returns whether the given connection is controlled by this signal.
Definition: NBLoadedTLDef.cpp:138
NBLoadedTLDef::SignalGroup::getTimes
std::vector< double > getTimes(SUMOTime cycleDuration) const
Returns the times at which the signal switches.
Definition: NBLoadedTLDef.cpp:88
NBNode.h
NBLoadedTLDef::SignalGroupCont
std::map< std::string, SignalGroup * > SignalGroupCont
Definition of the container for signal groups.
Definition: NBLoadedTLDef.h:197
NBLoadedTLDef::getMaxIndex
int getMaxIndex()
Returns the maximum index controlled by this traffic light.
Definition: NBLoadedTLDef.cpp:658
NBLoadedTLDef::addToSignalGroup
bool addToSignalGroup(const std::string &groupid, const NBConnection &connection)
Adds a connection to a signal group.
Definition: NBLoadedTLDef.cpp:562
NBTrafficLightDefinition
The base class for traffic light logic definitions.
Definition: NBTrafficLightDefinition.h:67
NBLoadedTLDef::NBLoadedTLDef
NBLoadedTLDef(const NBEdgeCont &ec, const std::string &id, const std::vector< NBNode * > &junctions, SUMOTime offset, TrafficLightType type)
Constructor.
Definition: NBLoadedTLDef.cpp:256
NBLoadedTLDef::findGroup
SignalGroup * findGroup(NBEdge *from, NBEdge *to) const
Returns the signal group which is responsible for the given connection.
Definition: NBLoadedTLDef.cpp:551