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 /****************************************************************************/
17 // A connnection between lanes
18 /****************************************************************************/
19 #ifndef MSLink_h
20 #define MSLink_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include <vector>
29 #include <set>
30 #include <utils/common/SUMOTime.h>
34 
35 
36 // ===========================================================================
37 // class declarations
38 // ===========================================================================
39 class MSLane;
40 class MSJunction;
41 class MSVehicle;
42 class MSPerson;
43 class OutputDevice;
45 
46 
47 // ===========================================================================
48 // class definitions
49 // ===========================================================================
70 class MSLink {
71 public:
72 
73  // distance to link in m below which adaptation for zipper-merging should take place
74  static const double ZIPPER_ADAPT_DIST;
75 
76  struct LinkLeader {
77  LinkLeader(MSVehicle* _veh, double _gap, double _distToCrossing, bool _fromLeft = true) :
78  vehAndGap(std::make_pair(_veh, _gap)),
79  distToCrossing(_distToCrossing),
80  fromLeft(_fromLeft) {
81  }
82 
83  std::pair<MSVehicle*, double> vehAndGap;
85  bool fromLeft;
86  };
87 
88  typedef std::vector<LinkLeader> LinkLeaders;
89 
99  ApproachingVehicleInformation(const SUMOTime _arrivalTime, const SUMOTime _leavingTime,
100  const double _arrivalSpeed, const double _leaveSpeed,
101  const bool _willPass,
102  const SUMOTime _arrivalTimeBraking,
103  const double _arrivalSpeedBraking,
104  const SUMOTime _waitingTime,
105  const double _dist
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  }
115 
121  const double arrivalSpeed;
123  const double leaveSpeed;
125  const bool willPass;
129  const double arrivalSpeedBraking;
133  const double dist;
134 
135  private:
138 
139  };
140 
141 
150  MSLink(MSLane* predLane, MSLane* succLane, MSLane* via, LinkDirection dir, LinkState state, double length, double foeVisibilityDistance, bool keepClear, MSTrafficLightLogic* logic, int tlLinkIdx);
151 
152 
154  ~MSLink();
155 
156 
164  void setRequestInformation(int index, bool hasFoes, bool isCont,
165  const std::vector<MSLink*>& foeLinks, const std::vector<MSLane*>& foeLanes,
166  MSLane* internalLaneBefore = 0);
167 
169  void addWalkingAreaFoe(const MSLane* lane) {
170  myWalkingAreaFoe = lane;
171  }
172 
174  void addWalkingAreaFoeExit(const MSLane* lane) {
175  myWalkingAreaFoeExit = lane;
176  }
177 
180  return myWalkingAreaFoe;
181  }
183  return myWalkingAreaFoeExit;
184  }
185 
190  void setApproaching(const SUMOVehicle* approaching, const SUMOTime arrivalTime,
191  const double arrivalSpeed, const double leaveSpeed, const bool setRequest,
192  const SUMOTime arrivalTimeBraking, const double arrivalSpeedBraking,
193  const SUMOTime waitingTime, double dist);
194 
196  void setApproaching(const SUMOVehicle* approaching, ApproachingVehicleInformation ai);
197 
199  void removeApproaching(const SUMOVehicle* veh);
200 
201  void addBlockedLink(MSLink* link);
202 
203  /* @brief return information about this vehicle if it is registered as
204  * approaching (dummy values otherwise)
205  * @note used for visualisation of link items */
206  ApproachingVehicleInformation getApproaching(const SUMOVehicle* veh) const;
207 
209  const std::map<const SUMOVehicle*, const ApproachingVehicleInformation, ComparatorNumericalIdLess>& getApproaching() const {
210  return myApproachingVehicles;
211  }
212 
220  bool opened(SUMOTime arrivalTime, double arrivalSpeed, double leaveSpeed, double vehicleLength,
221  double impatience, double decel, SUMOTime waitingTime,
222  double posLat = 0,
223  std::vector<const SUMOVehicle*>* collectFoes = 0,
224  bool ignoreRed = false,
225  const SUMOVehicle* ego = 0) const;
226 
241  bool blockedAtTime(SUMOTime arrivalTime, SUMOTime leaveTime, double arrivalSpeed, double leaveSpeed,
242  bool sameTargetLane, double impatience, double decel, SUMOTime waitingTime,
243  std::vector<const SUMOVehicle*>* collectFoes = 0, const SUMOVehicle* ego = 0) const;
244 
245 
246  bool isBlockingAnyone() const {
247  return myApproachingVehicles.size() != 0;
248  }
249 
250  bool willHaveBlockedFoe() const;
251 
252 
253 
263  bool hasApproachingFoe(SUMOTime arrivalTime, SUMOTime leaveTime, double speed, double decel) const;
264 
266  return myJunction;
267  }
268 
269 
274  LinkState getState() const {
275  return myState;
276  }
277 
278 
284  return myOffState;
285  }
286 
287 
288  //@brief Returns the time of the last state change
289  inline SUMOTime getLastStateChange() const {
290  return myLastStateChange;
291  }
292 
293 
298  LinkDirection getDirection() const;
299 
300 
306  void setTLState(LinkState state, SUMOTime t);
307 
308 
313  MSLane* getLane() const;
314 
315 
320  inline int getIndex() const {
321  return myIndex;
322  }
323 
325  inline int getTLIndex() const {
326  return myTLIndex;
327  }
328 
330  inline const MSTrafficLightLogic* getTLLogic() const {
331  return myLogic;
332  }
333 
337  inline bool havePriority() const {
338  return myState >= 'A' && myState <= 'Z';
339  }
340 
344  inline bool haveRed() const {
346  }
347 
348  inline bool haveYellow() const {
350  }
351 
352  inline bool isTLSControlled() const {
353  return myLogic != 0;
354  }
355 
360  double getLength() const {
361  return myLength;
362  }
363 
364 
371  double getFoeVisibilityDistance() const {
373  }
374 
375 
380  bool hasFoes() const {
381  return myHasFoes;
382  }
383 
384  // @brief return whether the vehicle may continute past this link to wait within the intersection
385  bool isCont() const;
386 
387 
389  bool keepClear() const {
390  return myKeepClear;
391  }
392 
394  bool lastWasContMajor() const;
395 
399  double getInternalLengthsAfter() const;
400 
404  double getInternalLengthsBefore() const;
405 
411  double getLengthsBeforeCrossing(const MSLane* foeLane) const;
412 
413 
419  double getLengthBeforeCrossing(const MSLane* foeLane) const;
420 
421 
426  MSLane* getViaLane() const;
427 
436  LinkLeaders getLeaderInfo(const MSVehicle* ego, double dist, std::vector<const MSPerson*>* collectBlockers = 0, bool isShadowLink = false) const;
437 
439  void checkWalkingAreaFoe(const MSVehicle* ego, const MSLane* foeLane, std::vector<const MSPerson*>* collectBlockers, LinkLeaders& result) const;
440 
442  double getZipperSpeed(const MSVehicle* ego, const double dist, double vSafe,
443  SUMOTime arrivalTime,
444  std::vector<const SUMOVehicle*>* collectFoes) const;
445 
447  MSLane* getViaLaneOrLane() const;
448 
450  const MSLane* getLaneBefore() const;
451 
453  const MSLane* getInternalLaneBefore() const;
454 
456  SUMOTime getLeaveTime(const SUMOTime arrivalTime, const double arrivalSpeed, const double leaveSpeed, const double vehicleLength) const;
457 
459  void writeApproaching(OutputDevice& od, const std::string fromLaneID) const;
460 
462  MSLink* getParallelLink(int direction) const;
463 
465  bool fromInternalLane() const;
466 
468  bool isEntryLink() const;
469 
471  bool isConflictEntryLink() const;
472 
474  bool isExitLink() const;
475 
477  bool isExitLinkAfterInternalJunction() const;
478 
481 
483  bool isInternalJunctionLink() const;
484 
487  return myMesoTLSPenalty;
488  }
489 
491  double getGreenFraction() const {
492  return myGreenFraction;
493  }
494 
496  void setMesoTLSPenalty(const SUMOTime penalty) {
497  myMesoTLSPenalty = penalty;
498  }
499 
501  void setGreenFraction(const double fraction) {
502  myGreenFraction = fraction;
503  }
504 
505  const std::vector<const MSLane*>& getFoeLanes() const {
506  return myFoeLanes;
507  }
508 
509  const std::vector<std::pair<double, double> >& getLengthsBehindCrossing() const {
511  }
512 
513  const std::vector<MSLink*>& getFoeLinks() const {
514  return myFoeLinks;
515  }
516 
518  void initParallelLinks();
519 
521  double getLateralShift() {
522  return myLateralShift;
523  }
524 
526  std::string getDescription() const;
527 
528 private:
530  static inline bool unsafeMergeSpeeds(double leaderSpeed, double followerSpeed, double leaderDecel, double followerDecel) {
531  // XXX mismatch between continuous an discrete deceleration
532  return (leaderSpeed * leaderSpeed / leaderDecel) <= (followerSpeed * followerSpeed / followerDecel);
533  }
534 
536  static bool maybeOccupied(MSLane* lane);
537 
539  static bool couldBrakeForLeader(double followDist, double leaderDist, const MSVehicle* follow, const MSVehicle* leader);
540 
541  MSLink* computeParallelLink(int direction);
542 
543  bool blockedByFoe(const SUMOVehicle* veh, const ApproachingVehicleInformation& avi,
544  SUMOTime arrivalTime, SUMOTime leaveTime, double arrivalSpeed, double leaveSpeed,
545  bool sameTargetLane, double impatience, double decel, SUMOTime waitingTime,
546  const SUMOVehicle* ego) const;
547 
549  bool checkContOff() const;
550 
552  bool contIntersect(const MSLane* lane, const MSLane* foe);
553 
554 private:
557 
560 
561  std::map<const SUMOVehicle*, const ApproachingVehicleInformation, ComparatorNumericalIdLess> myApproachingVehicles;
562  std::set<MSLink*> myBlockedFoeLinks;
563 
565  int myIndex;
566 
568  const int myTLIndex;
569 
572 
577 
580 
583 
586  double myLength;
587 
592 
594  bool myHasFoes;
595 
596  // @brief whether vehicles may continue past this link to wait within the intersection
597  bool myAmCont;
598  // @brief whether vehicles may continue past this link to wait within the intersection after switching of the traffic light at this intersection
600 
601  // @brief whether vehicles must keep the intersection clear if there is a downstream jam
603 
606 
607  /* @brief The preceding junction-internal lane, only used at
608  * - exit links (from internal lane to normal lane)
609  * - internal junction links (from internal lane to internal lane)
610  */
612 
617 
620 
621  /* @brief lengths after the crossing point with foeLane
622  * (lengthOnThis, lengthOnFoe)
623  * (index corresponds to myFoeLanes)
624  * empty vector for entry links
625  * */
626  std::vector<std::pair<double, double> > myLengthsBehindCrossing;
627 
628  // TODO: documentation
629  std::vector<MSLink*> myFoeLinks;
630  std::vector<const MSLane*> myFoeLanes;
631 
636 
639 
640  /* @brief Links with the same origin lane and the same destination edge that may
641  be in conflict for sublane simulation */
642  std::vector<MSLink*> mySublaneFoeLinks;
643  /* @brief Links with the same origin lane and different destination edge that may
644  be in conflict for sublane simulation */
645  std::vector<MSLink*> mySublaneFoeLinks2;
646 
647  /* @brief Internal Lanes with the same origin lane and the same destination edge that may
648  be in conflict for sublane simulation */
649  std::vector<MSLane*> mySublaneFoeLanes;
650 
651  static const SUMOTime myLookaheadTime;
653 
656 
659 
661  MSLink(const MSLink& s);
662 
664  MSLink& operator=(const MSLink& s);
665 
666 };
667 
668 
669 #endif
670 
671 /****************************************************************************/
672 
SUMOTime.h
MSLane
Representation of a lane in the micro simulation.
Definition: MSLane.h:83
MSJunction
The base class for an intersection.
Definition: MSJunction.h:61
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
MSPerson
Definition: MSPerson.h:64
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:35
SUMOVehicle
Representation of a vehicle.
Definition: SUMOVehicle.h:61
LinkDirection
LinkDirection
The different directions a link between two lanes may take (or a stream between two edges)....
Definition: SUMOXMLDefinitions.h:1171
LinkState
LinkState
The right-of-way state of a link between two lanes used when constructing a NBTrafficLightLogic,...
Definition: SUMOXMLDefinitions.h:1132
SUMOVehicle.h
LINKSTATE_TL_YELLOW_MINOR
The link has yellow light, has to brake anyway.
Definition: SUMOXMLDefinitions.h:1144
LINKSTATE_TL_REDYELLOW
The link has red light (must brake) but indicates upcoming green.
Definition: SUMOXMLDefinitions.h:1140
SUMOVehicleClass.h
MSTrafficLightLogic
The parent class for traffic light logics.
Definition: MSTrafficLightLogic.h:56
LINKSTATE_TL_YELLOW_MAJOR
The link has yellow light, may pass.
Definition: SUMOXMLDefinitions.h:1142
config.h
LINKSTATE_TL_RED
The link has red light (must brake)
Definition: SUMOXMLDefinitions.h:1138
SUMOXMLDefinitions.h
MSVehicle
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:80