Eclipse SUMO - Simulation of Urban MObility
MSLink.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2002-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 connnection between lanes
17 /****************************************************************************/
18 #ifndef MSLink_h
19 #define MSLink_h
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include <vector>
28 #include <set>
29 #include <utils/common/SUMOTime.h>
33 
34 
35 // ===========================================================================
36 // class declarations
37 // ===========================================================================
38 class MSLane;
39 class MSJunction;
40 class MSVehicle;
41 class MSPerson;
42 class OutputDevice;
44 
45 
46 // ===========================================================================
47 // class definitions
48 // ===========================================================================
69 class MSLink {
70 public:
71 
72  // distance to link in m below which adaptation for zipper-merging should take place
73  static const double ZIPPER_ADAPT_DIST;
74 
75  struct LinkLeader {
76  LinkLeader(MSVehicle* _veh, double _gap, double _distToCrossing, bool _fromLeft = true) :
77  vehAndGap(std::make_pair(_veh, _gap)),
78  distToCrossing(_distToCrossing),
79  fromLeft(_fromLeft) {
80  }
81 
82  std::pair<MSVehicle*, double> vehAndGap;
84  bool fromLeft;
85  };
86 
87  typedef std::vector<LinkLeader> LinkLeaders;
88 
98  ApproachingVehicleInformation(const SUMOTime _arrivalTime, const SUMOTime _leavingTime,
99  const double _arrivalSpeed, const double _leaveSpeed,
100  const bool _willPass,
101  const SUMOTime _arrivalTimeBraking,
102  const double _arrivalSpeedBraking,
103  const SUMOTime _waitingTime,
104  const double _dist,
105  const double _speed
106  ) :
107  arrivalTime(_arrivalTime), leavingTime(_leavingTime),
108  arrivalSpeed(_arrivalSpeed), leaveSpeed(_leaveSpeed),
109  willPass(_willPass),
110  arrivalTimeBraking(_arrivalTimeBraking),
111  arrivalSpeedBraking(_arrivalSpeedBraking),
112  waitingTime(_waitingTime),
113  dist(_dist),
114  speed(_speed) {
115  }
116 
122  const double arrivalSpeed;
124  const double leaveSpeed;
126  const bool willPass;
130  const double arrivalSpeedBraking;
134  const double dist;
136  const double speed;
137 
138  private:
141 
142  };
143 
144  typedef std::map<const SUMOVehicle*, const ApproachingVehicleInformation, ComparatorNumericalIdLess> ApproachInfos;
145  typedef std::vector<const SUMOVehicle*> BlockingFoes;
146 
155  MSLink(MSLane* predLane, MSLane* succLane, MSLane* via, LinkDirection dir, LinkState state, double length, double foeVisibilityDistance, bool keepClear, MSTrafficLightLogic* logic, int tlLinkIdx);
156 
157 
159  ~MSLink();
160 
161 
169  void setRequestInformation(int index, bool hasFoes, bool isCont,
170  const std::vector<MSLink*>& foeLinks, const std::vector<MSLane*>& foeLanes,
171  MSLane* internalLaneBefore = 0);
172 
174  void addWalkingAreaFoe(const MSLane* lane) {
175  myWalkingAreaFoe = lane;
176  }
177 
179  void addWalkingAreaFoeExit(const MSLane* lane) {
180  myWalkingAreaFoeExit = lane;
181  }
182 
185  return myWalkingAreaFoe;
186  }
188  return myWalkingAreaFoeExit;
189  }
190 
195  void setApproaching(const SUMOVehicle* approaching, const SUMOTime arrivalTime,
196  const double arrivalSpeed, const double leaveSpeed, const bool setRequest,
197  const SUMOTime arrivalTimeBraking, const double arrivalSpeedBraking,
198  const SUMOTime waitingTime, double dist);
199 
201  void setApproaching(const SUMOVehicle* approaching, ApproachingVehicleInformation ai);
202 
204  void removeApproaching(const SUMOVehicle* veh);
205 
206  void addBlockedLink(MSLink* link);
207 
208  /* @brief return information about this vehicle if it is registered as
209  * approaching (dummy values otherwise)
210  * @note used for visualisation of link items */
211  ApproachingVehicleInformation getApproaching(const SUMOVehicle* veh) const;
212 
214  const ApproachInfos& getApproaching() const {
215  return myApproachingVehicles;
216  }
217 
225  bool opened(SUMOTime arrivalTime, double arrivalSpeed, double leaveSpeed, double vehicleLength,
226  double impatience, double decel, SUMOTime waitingTime,
227  double posLat = 0,
228  BlockingFoes* collectFoes = nullptr,
229  bool ignoreRed = false,
230  const SUMOVehicle* ego = nullptr) const;
231 
246  bool blockedAtTime(SUMOTime arrivalTime, SUMOTime leaveTime, double arrivalSpeed, double leaveSpeed,
247  bool sameTargetLane, double impatience, double decel, SUMOTime waitingTime,
248  BlockingFoes* collectFoes = nullptr, const SUMOVehicle* ego = nullptr) const;
249 
250 
251  bool isBlockingAnyone() const {
252  return myApproachingVehicles.size() != 0;
253  }
254 
255  bool willHaveBlockedFoe() const;
256 
257 
258 
268  bool hasApproachingFoe(SUMOTime arrivalTime, SUMOTime leaveTime, double speed, double decel) const;
269 
271  std::pair<const SUMOVehicle*, const MSLink*> getFirstApproachingFoe() const;
272 
274  return myJunction;
275  }
276 
277 
282  LinkState getState() const {
283  return myState;
284  }
285 
286 
292  return myOffState;
293  }
294 
295 
296  //@brief Returns the time of the last state change
297  inline SUMOTime getLastStateChange() const {
298  return myLastStateChange;
299  }
300 
301 
306  LinkDirection getDirection() const;
307 
308 
314  void setTLState(LinkState state, SUMOTime t);
315 
316 
321  MSLane* getLane() const;
322 
323 
328  inline int getIndex() const {
329  return myIndex;
330  }
331 
333  inline int getTLIndex() const {
334  return myTLIndex;
335  }
336 
338  inline const MSTrafficLightLogic* getTLLogic() const {
339  return myLogic;
340  }
341 
345  inline bool havePriority() const {
346  return myState >= 'A' && myState <= 'Z';
347  }
348 
352  inline bool haveRed() const {
354  }
355 
356  inline bool haveYellow() const {
358  }
359 
360  inline bool isTLSControlled() const {
361  return myLogic != 0;
362  }
363 
368  double getLength() const {
369  return myLength;
370  }
371 
372 
379  double getFoeVisibilityDistance() const {
381  }
382 
383 
388  bool hasFoes() const {
389  return myHasFoes;
390  }
391 
392  // @brief return whether the vehicle may continute past this link to wait within the intersection
393  bool isCont() const;
394 
395 
397  bool keepClear() const {
398  return myKeepClear;
399  }
400 
402  bool lastWasContMajor() const;
403 
407  double getInternalLengthsAfter() const;
408 
412  double getInternalLengthsBefore() const;
413 
419  double getLengthsBeforeCrossing(const MSLane* foeLane) const;
420 
421 
427  double getLengthBeforeCrossing(const MSLane* foeLane) const;
428 
429 
434  MSLane* getViaLane() const;
435 
444  LinkLeaders getLeaderInfo(const MSVehicle* ego, double dist, std::vector<const MSPerson*>* collectBlockers = 0, bool isShadowLink = false) const;
445 
447  void checkWalkingAreaFoe(const MSVehicle* ego, const MSLane* foeLane, std::vector<const MSPerson*>* collectBlockers, LinkLeaders& result) const;
448 
450  double getZipperSpeed(const MSVehicle* ego, const double dist, double vSafe,
451  SUMOTime arrivalTime,
452  BlockingFoes* collectFoes) const;
453 
455  MSLane* getViaLaneOrLane() const;
456 
458  const MSLane* getLaneBefore() const;
459 
461  const MSLane* getInternalLaneBefore() const;
462 
464  SUMOTime getLeaveTime(const SUMOTime arrivalTime, const double arrivalSpeed, const double leaveSpeed, const double vehicleLength) const;
465 
467  void writeApproaching(OutputDevice& od, const std::string fromLaneID) const;
468 
470  MSLink* getParallelLink(int direction) const;
471 
473  bool fromInternalLane() const;
474 
476  bool isEntryLink() const;
477 
479  bool isConflictEntryLink() const;
480 
482  bool isExitLink() const;
483 
485  bool isExitLinkAfterInternalJunction() const;
486 
489 
491  bool isInternalJunctionLink() const;
492 
495  return myMesoTLSPenalty;
496  }
497 
499  double getGreenFraction() const {
500  return myGreenFraction;
501  }
502 
504  void setMesoTLSPenalty(const SUMOTime penalty) {
505  myMesoTLSPenalty = penalty;
506  }
507 
509  void setGreenFraction(const double fraction) {
510  myGreenFraction = fraction;
511  }
512 
513  const std::vector<const MSLane*>& getFoeLanes() const {
514  return myFoeLanes;
515  }
516 
517  const std::vector<std::pair<double, double> >& getLengthsBehindCrossing() const {
519  }
520 
521  const std::vector<MSLink*>& getFoeLinks() const {
522  return myFoeLinks;
523  }
524 
526  void initParallelLinks();
527 
529  double getLateralShift() {
530  return myLateralShift;
531  }
532 
534  std::string getDescription() const;
535 
536 private:
538  static inline bool unsafeMergeSpeeds(double leaderSpeed, double followerSpeed, double leaderDecel, double followerDecel) {
539  // XXX mismatch between continuous an discrete deceleration
540  return (leaderSpeed * leaderSpeed / leaderDecel) <= (followerSpeed * followerSpeed / followerDecel);
541  }
542 
544  static bool couldBrakeForLeader(double followDist, double leaderDist, const MSVehicle* follow, const MSVehicle* leader);
545 
546  MSLink* computeParallelLink(int direction);
547 
548  bool blockedByFoe(const SUMOVehicle* veh, const ApproachingVehicleInformation& avi,
549  SUMOTime arrivalTime, SUMOTime leaveTime, double arrivalSpeed, double leaveSpeed,
550  bool sameTargetLane, double impatience, double decel, SUMOTime waitingTime,
551  const SUMOVehicle* ego) const;
552 
554  bool checkContOff() const;
555 
557  bool contIntersect(const MSLane* lane, const MSLane* foe);
558 
559 private:
562 
565 
567  std::set<MSLink*> myBlockedFoeLinks;
568 
570  int myIndex;
571 
573  const int myTLIndex;
574 
577 
582 
585 
588 
591  double myLength;
592 
597 
599  bool myHasFoes;
600 
601  // @brief whether vehicles may continue past this link to wait within the intersection
602  bool myAmCont;
603  // @brief whether vehicles may continue past this link to wait within the intersection after switching of the traffic light at this intersection
605 
606  // @brief whether vehicles must keep the intersection clear if there is a downstream jam
608 
611 
612  /* @brief The preceding junction-internal lane, only used at
613  * - exit links (from internal lane to normal lane)
614  * - internal junction links (from internal lane to internal lane)
615  */
617 
622 
625 
626  /* @brief lengths after the crossing point with foeLane
627  * (lengthOnThis, lengthOnFoe)
628  * (index corresponds to myFoeLanes)
629  * empty vector for entry links
630  * */
631  std::vector<std::pair<double, double> > myLengthsBehindCrossing;
632 
633  // TODO: documentation
634  std::vector<MSLink*> myFoeLinks;
635  std::vector<const MSLane*> myFoeLanes;
636 
641 
644 
645  /* @brief Links with the same origin lane and the same destination edge that may
646  be in conflict for sublane simulation */
647  std::vector<MSLink*> mySublaneFoeLinks;
648  /* @brief Links with the same origin lane and different destination edge that may
649  be in conflict for sublane simulation */
650  std::vector<MSLink*> mySublaneFoeLinks2;
651 
652  /* @brief Internal Lanes with the same origin lane and the same destination edge that may
653  be in conflict for sublane simulation */
654  std::vector<MSLane*> mySublaneFoeLanes;
655 
656  static const SUMOTime myLookaheadTime;
658 
661 
664 
666  MSLink(const MSLink& s);
667 
669  MSLink& operator=(const MSLink& s);
670 
671 };
672 
673 
674 #endif
675 
676 /****************************************************************************/
677 
SUMOTime.h
MSLane
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
MSJunction
The base class for an intersection.
Definition: MSJunction.h:60
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:63
MSPerson
Definition: MSPerson.h:63
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
SUMOVehicle
Representation of a vehicle.
Definition: SUMOVehicle.h:60
LinkDirection
LinkDirection
The different directions a link between two lanes may take (or a stream between two edges)....
Definition: SUMOXMLDefinitions.h:1176
LinkState
LinkState
The right-of-way state of a link between two lanes used when constructing a NBTrafficLightLogic,...
Definition: SUMOXMLDefinitions.h:1137
SUMOVehicle.h
LINKSTATE_TL_YELLOW_MINOR
@ LINKSTATE_TL_YELLOW_MINOR
The link has yellow light, has to brake anyway.
Definition: SUMOXMLDefinitions.h:1149
LINKSTATE_TL_REDYELLOW
@ LINKSTATE_TL_REDYELLOW
The link has red light (must brake) but indicates upcoming green.
Definition: SUMOXMLDefinitions.h:1145
SUMOVehicleClass.h
MSTrafficLightLogic
The parent class for traffic light logics.
Definition: MSTrafficLightLogic.h:55
LINKSTATE_TL_YELLOW_MAJOR
@ LINKSTATE_TL_YELLOW_MAJOR
The link has yellow light, may pass.
Definition: SUMOXMLDefinitions.h:1147
config.h
LINKSTATE_TL_RED
@ LINKSTATE_TL_RED
The link has red light (must brake)
Definition: SUMOXMLDefinitions.h:1143
SUMOXMLDefinitions.h
MSVehicle
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:79