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 /****************************************************************************/
16 // A loaded (complete) traffic light logic
17 /****************************************************************************/
18 #ifndef NBLoadedTLDef_h
19 #define NBLoadedTLDef_h
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include <vector>
28 #include <string>
29 #include <set>
31 #include "NBNode.h"
32 #include <utils/common/SUMOTime.h>
33 
34 
35 // ===========================================================================
36 // class definitions
37 // ===========================================================================
43 public:
47  class SignalGroup : public Named {
48  public:
52  SignalGroup(const std::string& id);
53 
55  ~SignalGroup();
56 
60  void addConnection(const NBConnection& c);
61 
66  void addPhaseBegin(SUMOTime time, TLColor color);
67 
72  void setYellowTimes(SUMOTime tRedYellowe, SUMOTime tYellow);
73 
78  std::vector<double> getTimes(SUMOTime cycleDuration) const;
79 
81  void sortPhases();
82 
86  int getLinkNo() const;
87 
92  bool mayDrive(SUMOTime time) const;
93 
98  bool hasYellow(SUMOTime time) const;
99 
105  bool containsConnection(NBEdge* from, NBEdge* to) const;
106 
111  bool containsIncoming(NBEdge* from) const;
112 
117  void remapIncoming(NBEdge* which, const EdgeVector& by);
118 
123  bool containsOutgoing(NBEdge* to) const;
124 
129  void remapOutgoing(NBEdge* which, const EdgeVector& by);
130 
135  const NBConnection& getConnection(int pos) const;
136 
141  void patchTYellow(int tyellow, bool forced);
142 
149  void remap(NBEdge* removed, int removedLane, NBEdge* by, int byLane);
150 
154  class PhaseDef {
155  public:
160  PhaseDef(SUMOTime time, TLColor color)
161  : myTime(time), myColor(color) { }
162 
167  };
168 
173  public:
175  explicit phase_by_time_sorter() { }
176 
181  int operator()(const PhaseDef& p1, const PhaseDef& p2) {
182  return p1.myTime < p2.myTime;
183  }
184  };
185 
186  private:
190  std::vector<PhaseDef> myPhases;
193  };
194 
195 
196 
198  typedef std::map<std::string, SignalGroup*> SignalGroupCont;
199 
200 
207  NBLoadedTLDef(const NBEdgeCont& ec, const std::string& id,
208  const std::vector<NBNode*>& junctions, SUMOTime offset,
209  TrafficLightType type);
210 
211 
218  NBLoadedTLDef(const NBEdgeCont& ec, const std::string& id, NBNode* junction, SUMOTime offset,
219  TrafficLightType type);
220 
221 
227  NBLoadedTLDef(const NBEdgeCont& ec, const std::string& id, SUMOTime offset,
228  TrafficLightType type);
229 
230 
232  ~NBLoadedTLDef();
233 
234 
240  SignalGroup* findGroup(NBEdge* from, NBEdge* to) const;
241 
242 
246  void setCycleDuration(int cycleDur);
247 
248 
252  void addSignalGroup(const std::string& id);
253 
254 
259  bool addToSignalGroup(const std::string& groupid,
260  const NBConnection& connection);
261 
262 
267  bool addToSignalGroup(const std::string& groupid,
268  const NBConnectionVector& connections);
269 
270 
276  void addSignalGroupPhaseBegin(const std::string& groupid,
277  SUMOTime time, TLColor color);
278 
279 
285  void setSignalYellowTimes(const std::string& groupid,
286  SUMOTime tRedYellow, SUMOTime tYellow);
287 
288 
291 
296  void setTLControllingInformation() const;
297 
298 
305  void remapRemoved(NBEdge* removed,
306  const EdgeVector& incoming, const EdgeVector& outgoing);
307 
308  /* initialize myNeedsContRelation and set myNeedsContRelationReady to true */
309  void initNeedsContRelation() const;
310 
312  int getMaxIndex();
313 
315 
316 
317 protected:
320 
326  NBTrafficLightLogic* myCompute(int brakingTimeSeconds);
327 
332 
333 
337  void collectNodes();
338 
339 
344  void collectLinks();
345 
346 
353  bool mustBrake(const NBConnection& possProhibited,
354  const std::string& state,
355  int strmpos) const;
356 
357 
365  void replaceRemoved(NBEdge* removed, int removedLane,
366  NBEdge* by, int byLane);
368 
369 private:
375  std::string buildPhaseState(int time) const;
376 
377  // pointer to the NBEdgeCont for checking edges
379 
380 
381 private:
384 
387 
388 
389 };
390 
391 
392 #endif
393 
394 /****************************************************************************/
395 
NBLoadedTLDef::SignalGroup::myTYellow
SUMOTime myTYellow
Definition: NBLoadedTLDef.h:192
NBLoadedTLDef::SignalGroup::PhaseDef::myTime
SUMOTime myTime
The begin time of this phase.
Definition: NBLoadedTLDef.h:164
SUMOTime.h
NBLoadedTLDef::SignalGroup::hasYellow
bool hasYellow(SUMOTime time) const
Returns whether controlled links have yellow at the given time.
Definition: NBLoadedTLDef.cpp:131
Named
Base class for objects which have an id.
Definition: Named.h:57
NBEdgeCont
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:61
NBLoadedTLDef::collectNodes
void collectNodes()
Collects the nodes participating in this traffic light.
Definition: NBLoadedTLDef.cpp:484
NBLoadedTLDef::SignalGroup::phase_by_time_sorter::phase_by_time_sorter
phase_by_time_sorter()
Constructor.
Definition: NBLoadedTLDef.h:175
NBLoadedTLDef::SignalGroup::addConnection
void addConnection(const NBConnection &c)
Inserts a controlled connection.
Definition: NBLoadedTLDef.cpp:51
NBLoadedTLDef::SignalGroup::PhaseDef::myColor
TLColor myColor
A signal's color from this time.
Definition: NBLoadedTLDef.h:166
NBLoadedTLDef::addSignalGroup
void addSignalGroup(const std::string &id)
Adds a signal group.
Definition: NBLoadedTLDef.cpp:595
NBLoadedTLDef::SignalGroup
A single signal group, may control several connections.
Definition: NBLoadedTLDef.h:47
NBLoadedTLDef::SignalGroup::patchTYellow
void patchTYellow(int tyellow, bool forced)
Sets the yellow time.
Definition: NBLoadedTLDef.cpp:77
NBLoadedTLDef::SignalGroup::PhaseDef::PhaseDef
PhaseDef(SUMOTime time, TLColor color)
Constructor.
Definition: NBLoadedTLDef.h:160
EdgeVector
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
Definition: NBCont.h:35
NBLoadedTLDef::SignalGroup::myPhases
std::vector< PhaseDef > myPhases
The phases of this signal.
Definition: NBLoadedTLDef.h:190
NBLoadedTLDef::SignalGroup::getLinkNo
int getLinkNo() const
Returns the number of links (connection) controlled by this signal.
Definition: NBLoadedTLDef.cpp:112
NBLoadedTLDef::SignalGroup::setYellowTimes
void setYellowTimes(SUMOTime tRedYellowe, SUMOTime tYellow)
Sets the times for redyellow and yellow.
Definition: NBLoadedTLDef.cpp:64
TrafficLightType
TrafficLightType
Definition: SUMOXMLDefinitions.h:1192
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:35
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:181
NBLoadedTLDef::addSignalGroupPhaseBegin
void addSignalGroupPhaseBegin(const std::string &groupid, SUMOTime time, TLColor color)
Sets the information about the begin of a phase.
Definition: NBLoadedTLDef.cpp:602
NBLoadedTLDef::mySignalGroups
SignalGroupCont mySignalGroups
Controlled signal groups.
Definition: NBLoadedTLDef.h:383
NBLoadedTLDef::SignalGroup::myConnections
NBConnectionVector myConnections
Connections controlled by this signal.
Definition: NBLoadedTLDef.h:188
NBLoadedTLDef::setCycleDuration
void setCycleDuration(int cycleDur)
Sets the duration of a cycle.
Definition: NBLoadedTLDef.cpp:617
NBEdge
The representation of a single edge during network building.
Definition: NBEdge.h:86
NBLoadedTLDef::setTLControllingInformation
void setTLControllingInformation() const
Informs edges about being controlled by a tls.
Definition: NBLoadedTLDef.cpp:369
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:192
NBLoadedTLDef::SignalGroup::myTRedYellow
SUMOTime myTRedYellow
The times of redyellow and yellow.
Definition: NBLoadedTLDef.h:192
NBTrafficLightDefinition::TLColor
TLColor
An enumeration of possible tl-signal states.
Definition: NBTrafficLightDefinition.h:78
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:609
NBLoadedTLDef::SignalGroup::getConnection
const NBConnection & getConnection(int pos) const
Returns the connection at the given index.
Definition: NBLoadedTLDef.cpp:151
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:623
NBLoadedTLDef::SignalGroup::mayDrive
bool mayDrive(SUMOTime time) const
Returns whether vehicles on controlled links may drive at the given time.
Definition: NBLoadedTLDef.cpp:118
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:435
NBConnection
Definition: NBConnection.h:44
NBLoadedTLDef::SignalGroup::containsIncoming
bool containsIncoming(NBEdge *from) const
Returns whether this signal controls the given edge.
Definition: NBLoadedTLDef.cpp:158
NBLoadedTLDef::myCycleDuration
int myCycleDuration
The duration of a single cycle.
Definition: NBLoadedTLDef.h:386
NBLoadedTLDef::collectLinks
void collectLinks()
Collects the links participating in this traffic light.
Definition: NBLoadedTLDef.cpp:502
NBLoadedTLDef::SignalGroup::~SignalGroup
~SignalGroup()
Destructor.
Definition: NBLoadedTLDef.cpp:48
NBLoadedTLDef::SignalGroup::SignalGroup
SignalGroup(const std::string &id)
Constructor.
Definition: NBLoadedTLDef.cpp:45
NBLoadedTLDef::SignalGroup::remapIncoming
void remapIncoming(NBEdge *which, const EdgeVector &by)
Replaces the given incoming edge by the others given.
Definition: NBLoadedTLDef.cpp:169
NBLoadedTLDef::SignalGroup::phase_by_time_sorter
Sorts phases by their begin time.
Definition: NBLoadedTLDef.h:172
NBLoadedTLDef::replaceRemoved
void replaceRemoved(NBEdge *removed, int removedLane, NBEdge *by, int byLane)
Replaces a removed edge/lane.
Definition: NBLoadedTLDef.cpp:639
NBLoadedTLDef::SignalGroup::remapOutgoing
void remapOutgoing(NBEdge *which, const EdgeVector &by)
Replaces the given outgoing edge by the others given.
Definition: NBLoadedTLDef.cpp:203
NBLoadedTLDef::setParticipantsInformation
void setParticipantsInformation()
Builds the list of participating nodes/edges/links.
Definition: NBLoadedTLDef.cpp:475
NBLoadedTLDef
A loaded (complete) traffic light logic.
Definition: NBLoadedTLDef.h:42
NBConnectionVector
std::vector< NBConnection > NBConnectionVector
Definition of a connection vector.
Definition: NBConnectionDefs.h:35
NBLoadedTLDef::SignalGroup::PhaseDef
Definition of a single, loaded phase.
Definition: NBLoadedTLDef.h:154
NBLoadedTLDef::initNeedsContRelation
void initNeedsContRelation() const
Definition: NBLoadedTLDef.cpp:651
NBLoadedTLDef::buildPhaseState
std::string buildPhaseState(int time) const
Builds the phase for a given time.
Definition: NBLoadedTLDef.cpp:381
NBLoadedTLDef::SignalGroup::addPhaseBegin
void addPhaseBegin(SUMOTime time, TLColor color)
Sets the begin of a phase.
Definition: NBLoadedTLDef.cpp:58
NBLoadedTLDef::~NBLoadedTLDef
~NBLoadedTLDef()
Destructor.
Definition: NBLoadedTLDef.cpp:276
config.h
NBLoadedTLDef::SignalGroup::remap
void remap(NBEdge *removed, int removedLane, NBEdge *by, int byLane)
Replaces a removed edge/lane.
Definition: NBLoadedTLDef.cpp:226
NBLoadedTLDef::myCompute
NBTrafficLightLogic * myCompute(int brakingTimeSeconds)
Computes the traffic light logic finally in dependence to the type.
Definition: NBLoadedTLDef.cpp:284
NBLoadedTLDef::myEdgeCont
const NBEdgeCont * myEdgeCont
Definition: NBLoadedTLDef.h:378
NBTrafficLightLogic
A SUMO-compliant built logic for a traffic light.
Definition: NBTrafficLightLogic.h:52
NBNode
Represents a single node (junction) during network building.
Definition: NBNode.h:68
NBLoadedTLDef::SignalGroup::sortPhases
void sortPhases()
Sorts the phases.
Definition: NBLoadedTLDef.cpp:71
NBLoadedTLDef::SignalGroup::containsConnection
bool containsConnection(NBEdge *from, NBEdge *to) const
Returns whether the given connection is controlled by this signal.
Definition: NBLoadedTLDef.cpp:139
NBLoadedTLDef::SignalGroup::getTimes
std::vector< double > getTimes(SUMOTime cycleDuration) const
Returns the times at which the signal switches.
Definition: NBLoadedTLDef.cpp:89
NBNode.h
NBLoadedTLDef::SignalGroupCont
std::map< std::string, SignalGroup * > SignalGroupCont
Definition of the container for signal groups.
Definition: NBLoadedTLDef.h:198
NBLoadedTLDef::getMaxIndex
int getMaxIndex()
Returns the maximum index controlled by this traffic light.
Definition: NBLoadedTLDef.cpp:659
NBLoadedTLDef::addToSignalGroup
bool addToSignalGroup(const std::string &groupid, const NBConnection &connection)
Adds a connection to a signal group.
Definition: NBLoadedTLDef.cpp:563
NBTrafficLightDefinition
The base class for traffic light logic definitions.
Definition: NBTrafficLightDefinition.h:68
NBLoadedTLDef::NBLoadedTLDef
NBLoadedTLDef(const NBEdgeCont &ec, const std::string &id, const std::vector< NBNode * > &junctions, SUMOTime offset, TrafficLightType type)
Constructor.
Definition: NBLoadedTLDef.cpp:257
NBLoadedTLDef::findGroup
SignalGroup * findGroup(NBEdge *from, NBEdge *to) const
Returns the signal group which is responsible for the given connection.
Definition: NBLoadedTLDef.cpp:552