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-2018 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 
175  return myWalkingAreaFoe;
176  }
177 
182  void setApproaching(const SUMOVehicle* approaching, const SUMOTime arrivalTime,
183  const double arrivalSpeed, const double leaveSpeed, const bool setRequest,
184  const SUMOTime arrivalTimeBraking, const double arrivalSpeedBraking,
185  const SUMOTime waitingTime, double dist);
186 
188  void setApproaching(const SUMOVehicle* approaching, ApproachingVehicleInformation ai);
189 
191  void removeApproaching(const SUMOVehicle* veh);
192 
193  void addBlockedLink(MSLink* link);
194 
195  /* @brief return information about this vehicle if it is registered as
196  * approaching (dummy values otherwise)
197  * @note used for visualisation of link items */
199 
201  const std::map<const SUMOVehicle*, ApproachingVehicleInformation, ComparatorNumericalIdLess>& getApproaching() const {
202  return myApproachingVehicles;
203  }
204 
212  bool opened(SUMOTime arrivalTime, double arrivalSpeed, double leaveSpeed, double vehicleLength,
213  double impatience, double decel, SUMOTime waitingTime,
214  double posLat = 0,
215  std::vector<const SUMOVehicle*>* collectFoes = 0,
216  bool ignoreRed = false,
217  const SUMOVehicle* ego = 0) const;
218 
233  bool blockedAtTime(SUMOTime arrivalTime, SUMOTime leaveTime, double arrivalSpeed, double leaveSpeed,
234  bool sameTargetLane, double impatience, double decel, SUMOTime waitingTime,
235  std::vector<const SUMOVehicle*>* collectFoes = 0, const SUMOVehicle* ego = 0) const;
236 
237 
238  bool isBlockingAnyone() const {
239  return myApproachingVehicles.size() != 0;
240  }
241 
242  bool willHaveBlockedFoe() const;
243 
244 
245 
255  bool hasApproachingFoe(SUMOTime arrivalTime, SUMOTime leaveTime, double speed, double decel) const;
256 
258  return myJunction;
259  }
260 
261 
266  LinkState getState() const {
267  return myState;
268  }
269 
270 
276  return myOffState;
277  }
278 
279 
280  //@brief Returns the time of the last state change
281  inline SUMOTime getLastStateChange() const {
282  return myLastStateChange;
283  }
284 
285 
290  LinkDirection getDirection() const;
291 
292 
298  void setTLState(LinkState state, SUMOTime t);
299 
300 
305  MSLane* getLane() const;
306 
307 
312  inline int getIndex() const {
313  return myIndex;
314  }
315 
317  inline int getTLIndex() const {
318  return myTLIndex;
319  }
320 
322  inline const MSTrafficLightLogic* getTLLogic() const {
323  return myLogic;
324  }
325 
329  inline bool havePriority() const {
330  return myState >= 'A' && myState <= 'Z';
331  }
332 
336  inline bool haveRed() const {
338  }
339 
340  inline bool haveYellow() const {
342  }
343 
344  inline bool isTLSControlled() const {
345  return myLogic != 0;
346  }
347 
352  double getLength() const {
353  return myLength;
354  }
355 
356 
363  double getFoeVisibilityDistance() const {
365  }
366 
367 
372  bool hasFoes() const {
373  return myHasFoes;
374  }
375 
376  // @brief return whether the vehicle may continute past this link to wait within the intersection
377  bool isCont() const;
378 
379 
381  bool keepClear() const {
382  return myKeepClear;
383  }
384 
386  bool lastWasContMajor() const;
387 
391  double getInternalLengthsAfter() const;
392 
396  double getInternalLengthsBefore() const;
397 
403  double getLengthsBeforeCrossing(const MSLane* foeLane) const;
404 
405 
411  double getLengthBeforeCrossing(const MSLane* foeLane) const;
412 
413 
418  MSLane* getViaLane() const;
419 
428  LinkLeaders getLeaderInfo(const MSVehicle* ego, double dist, std::vector<const MSPerson*>* collectBlockers = 0, bool isShadowLink = false) const;
429 
431  double getZipperSpeed(const MSVehicle* ego, const double dist, double vSafe,
432  SUMOTime arrivalTime,
433  std::vector<const SUMOVehicle*>* collectFoes) const;
434 
436  MSLane* getViaLaneOrLane() const;
437 
439  const MSLane* getLaneBefore() const;
440 
442  const MSLane* getInternalLaneBefore() const;
443 
445  SUMOTime getLeaveTime(const SUMOTime arrivalTime, const double arrivalSpeed, const double leaveSpeed, const double vehicleLength) const;
446 
448  void writeApproaching(OutputDevice& od, const std::string fromLaneID) const;
449 
451  MSLink* getParallelLink(int direction) const;
452 
454  bool fromInternalLane() const;
455 
457  bool isEntryLink() const;
458 
460  bool isConflictEntryLink() const;
461 
463  bool isExitLink() const;
464 
466  bool isExitLinkAfterInternalJunction() const;
467 
470 
472  bool isInternalJunctionLink() const;
473 
476  return myMesoTLSPenalty;
477  }
478 
480  double getGreenFraction() const {
481  return myGreenFraction;
482  }
483 
485  void setMesoTLSPenalty(const SUMOTime penalty) {
486  myMesoTLSPenalty = penalty;
487  }
488 
490  void setGreenFraction(const double fraction) {
491  myGreenFraction = fraction;
492  }
493 
494  const std::vector<const MSLane*>& getFoeLanes() const {
495  return myFoeLanes;
496  }
497 
498  const std::vector<std::pair<double, double> >& getLengthsBehindCrossing() const {
500  }
501 
502  const std::vector<MSLink*>& getFoeLinks() const {
503  return myFoeLinks;
504  }
505 
507  void initParallelLinks();
508 
510  double getLateralShift() {
511  return myLateralShift;
512  }
513 
514 private:
516  static inline bool unsafeMergeSpeeds(double leaderSpeed, double followerSpeed, double leaderDecel, double followerDecel) {
517  // XXX mismatch between continuous an discrete deceleration
518  return (leaderSpeed * leaderSpeed / leaderDecel) <= (followerSpeed * followerSpeed / followerDecel);
519  }
520 
522  static bool maybeOccupied(MSLane* lane);
523 
525  static bool couldBrakeForLeader(double followDist, double leaderDist, const MSVehicle* follow, const MSVehicle* leader);
526 
527  MSLink* computeParallelLink(int direction);
528 
529  bool blockedByFoe(const SUMOVehicle* veh, const ApproachingVehicleInformation& avi,
530  SUMOTime arrivalTime, SUMOTime leaveTime, double arrivalSpeed, double leaveSpeed,
531  bool sameTargetLane, double impatience, double decel, SUMOTime waitingTime,
532  const SUMOVehicle* ego) const;
533 
535  bool checkContOff() const;
536 
538  bool contIntersect(const MSLane* lane, const MSLane* foe);
539 
540 private:
543 
546 
547  std::map<const SUMOVehicle*, ApproachingVehicleInformation, ComparatorNumericalIdLess> myApproachingVehicles;
548  std::set<MSLink*> myBlockedFoeLinks;
549 
551  int myIndex;
552 
554  const int myTLIndex;
555 
558 
563 
566 
569 
572  double myLength;
573 
578 
580  bool myHasFoes;
581 
582  // @brief whether vehicles may continue past this link to wait within the intersection
583  bool myAmCont;
584  // @brief whether vehicles may continue past this link to wait within the intersection after switching of the traffic light at this intersection
586 
587  // @brief whether vehicles must keep the intersection clear if there is a downstream jam
589 
592 
593  /* @brief The preceding junction-internal lane, only used at
594  * - exit links (from internal lane to normal lane)
595  * - internal junction links (from internal lane to internal lane)
596  */
598 
603 
606 
607  /* @brief lengths after the crossing point with foeLane
608  * (lengthOnThis, lengthOnFoe)
609  * (index corresponds to myFoeLanes)
610  * empty vector for entry links
611  * */
612  std::vector<std::pair<double, double> > myLengthsBehindCrossing;
613 
614  // TODO: documentation
615  std::vector<MSLink*> myFoeLinks;
616  std::vector<const MSLane*> myFoeLanes;
618 
621 
622  /* @brief Links with the same origin lane and the same destination edge that may
623  be in conflict for sublane simulation */
624  std::vector<MSLink*> mySublaneFoeLinks;
625  /* @brief Links with the same origin lane and different destination edge that may
626  be in conflict for sublane simulation */
627  std::vector<MSLink*> mySublaneFoeLinks2;
628 
629  /* @brief Internal Lanes with the same origin lane and the same destination edge that may
630  be in conflict for sublane simulation */
631  std::vector<MSLane*> mySublaneFoeLanes;
632 
633  static const SUMOTime myLookaheadTime;
635 
638 
641 
643  MSLink(const MSLink& s);
644 
646  MSLink& operator=(const MSLink& s);
647 
648 };
649 
650 
651 #endif
652 
653 /****************************************************************************/
654 
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:79
long long int SUMOTime
Definition: SUMOTime.h:36
The base class for an intersection.
Definition: MSJunction.h:61
LinkDirection
The different directions a link between two lanes may take (or a stream between two edges)...
Representation of a vehicle.
Definition: SUMOVehicle.h:60
LinkState
The right-of-way state of a link between two lanes used when constructing a NBTrafficLightLogic, in MSLink and GNEInternalLane.
The link has yellow light, may pass.
The link has red light (must brake)
The parent class for traffic light logics.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
The link has yellow light, has to brake anyway.
Representation of a lane in the micro simulation.
Definition: MSLane.h:78
The link has red light (must brake) but indicates upcoming green.