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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // A connnection between lanes
20 /****************************************************************************/
21 #ifndef MSLink_h
22 #define MSLink_h
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <vector>
35 #include <set>
36 #include <utils/common/SUMOTime.h>
40 
41 
42 // ===========================================================================
43 // class declarations
44 // ===========================================================================
45 class MSLane;
46 class MSJunction;
47 class MSVehicle;
48 class MSPerson;
49 class OutputDevice;
51 
52 
53 // ===========================================================================
54 // class definitions
55 // ===========================================================================
76 class MSLink {
77 public:
78 
79  // distance to link in m below which adaptation for zipper-merging should take place
80  static const double ZIPPER_ADAPT_DIST;
81 
82  struct LinkLeader {
83  LinkLeader(MSVehicle* _veh, double _gap, double _distToCrossing, bool _fromLeft = true) :
84  vehAndGap(std::make_pair(_veh, _gap)),
85  distToCrossing(_distToCrossing),
86  fromLeft(_fromLeft) {
87  }
88 
89  std::pair<MSVehicle*, double> vehAndGap;
91  bool fromLeft;
92  };
93 
94  typedef std::vector<LinkLeader> LinkLeaders;
95 
105  ApproachingVehicleInformation(const SUMOTime _arrivalTime, const SUMOTime _leavingTime,
106  const double _arrivalSpeed, const double _leaveSpeed,
107  const bool _willPass,
108  const SUMOTime _arrivalTimeBraking,
109  const double _arrivalSpeedBraking,
110  const SUMOTime _waitingTime,
111  const double _dist
112  ) :
113  arrivalTime(_arrivalTime), leavingTime(_leavingTime),
114  arrivalSpeed(_arrivalSpeed), leaveSpeed(_leaveSpeed),
115  willPass(_willPass),
116  arrivalTimeBraking(_arrivalTimeBraking),
117  arrivalSpeedBraking(_arrivalSpeedBraking),
118  waitingTime(_waitingTime),
119  dist(_dist) {
120  }
121 
127  const double arrivalSpeed;
129  const double leaveSpeed;
131  const bool willPass;
135  const double arrivalSpeedBraking;
139  const double dist;
140 
141  private:
144 
145  };
146 
147 
156  MSLink(MSLane* predLane, MSLane* succLane, MSLane* via, LinkDirection dir, LinkState state, double length, double foeVisibilityDistance, bool keepClear, MSTrafficLightLogic* logic, int tlLinkIdx);
157 
158 
160  ~MSLink();
161 
162 
170  void setRequestInformation(int index, bool hasFoes, bool isCont,
171  const std::vector<MSLink*>& foeLinks, const std::vector<MSLane*>& foeLanes,
172  MSLane* internalLaneBefore = 0);
173 
175  void addWalkingAreaFoe(const MSLane* lane) {
176  myWalkingAreaFoe = lane;
177  }
178 
181  return myWalkingAreaFoe;
182  }
183 
188  void setApproaching(const SUMOVehicle* approaching, const SUMOTime arrivalTime,
189  const double arrivalSpeed, const double leaveSpeed, const bool setRequest,
190  const SUMOTime arrivalTimeBraking, const double arrivalSpeedBraking,
191  const SUMOTime waitingTime, double dist);
192 
194  void setApproaching(const SUMOVehicle* approaching, ApproachingVehicleInformation ai);
195 
197  void removeApproaching(const SUMOVehicle* veh);
198 
199  void addBlockedLink(MSLink* link);
200 
201  /* @brief return information about this vehicle if it is registered as
202  * approaching (dummy values otherwise)
203  * @note used for visualisation of link items */
205 
207  const std::map<const SUMOVehicle*, ApproachingVehicleInformation, ComparatorIdLess>& getApproaching() const {
208  return myApproachingVehicles;
209  }
210 
218  bool opened(SUMOTime arrivalTime, double arrivalSpeed, double leaveSpeed, double vehicleLength,
219  double impatience, double decel, SUMOTime waitingTime,
220  double posLat = 0,
221  std::vector<const SUMOVehicle*>* collectFoes = 0,
222  bool ignoreRed = false,
223  const SUMOVehicle* ego = 0) const;
224 
239  bool blockedAtTime(SUMOTime arrivalTime, SUMOTime leaveTime, double arrivalSpeed, double leaveSpeed,
240  bool sameTargetLane, double impatience, double decel, SUMOTime waitingTime,
241  std::vector<const SUMOVehicle*>* collectFoes = 0, const SUMOVehicle* ego = 0) const;
242 
243 
244  bool isBlockingAnyone() const {
245  return myApproachingVehicles.size() != 0;
246  }
247 
248  bool willHaveBlockedFoe() const;
249 
250 
251 
261  bool hasApproachingFoe(SUMOTime arrivalTime, SUMOTime leaveTime, double speed, double decel) const;
262 
264  return myJunction;
265  }
266 
267 
272  LinkState getState() const {
273  return myState;
274  }
275 
276 
277  //@brief Returns the time of the last state change
278  inline SUMOTime getLastStateChange() const {
279  return myLastStateChange;
280  }
281 
282 
287  LinkDirection getDirection() const;
288 
289 
295  void setTLState(LinkState state, SUMOTime t);
296 
297 
302  MSLane* getLane() const;
303 
304 
309  inline int getIndex() const {
310  return myIndex;
311  }
312 
314  inline int getTLIndex() const {
315  return myTLIndex;
316  }
317 
319  inline const MSTrafficLightLogic* getTLLogic() const {
320  return myLogic;
321  }
322 
326  inline bool havePriority() const {
327  return myState >= 'A' && myState <= 'Z';
328  }
329 
333  inline bool haveRed() const {
335  }
336 
337  inline bool haveYellow() const {
339  }
340 
341  inline bool isTLSControlled() const {
342  return myLogic != 0;
343  }
344 
349  double getLength() const {
350  return myLength;
351  }
352 
353 
360  double getFoeVisibilityDistance() const {
362  }
363 
364 
369  bool hasFoes() const {
370  return myHasFoes;
371  }
372 
373  // @todo documentation
374  bool isCont() const {
375  return myAmCont;
376  }
377 
378 
380  bool keepClear() const {
381  return myKeepClear;
382  }
383 
385  bool lastWasContMajor() const;
386 
390  double getInternalLengthsAfter() const;
391 
395  double getInternalLengthsBefore() const;
396 
402  double getLengthsBeforeCrossing(const MSLane* foeLane) const;
403 
404 
410  double getLengthBeforeCrossing(const MSLane* foeLane) const;
411 
412 
417  MSLane* getViaLane() const;
418 
427  LinkLeaders getLeaderInfo(const MSVehicle* ego, double dist, std::vector<const MSPerson*>* collectBlockers = 0, bool isShadowLink = false) const;
428 
430  double getZipperSpeed(const MSVehicle* ego, const double dist, double vSafe,
431  SUMOTime arrivalTime,
432  std::vector<const SUMOVehicle*>* collectFoes) const;
433 
435  MSLane* getViaLaneOrLane() const;
436 
438  const MSLane* getLaneBefore() const;
439 
441  const MSLane* getInternalLaneBefore() const;
442 
444  SUMOTime getLeaveTime(const SUMOTime arrivalTime, const double arrivalSpeed, const double leaveSpeed, const double vehicleLength) const;
445 
447  void writeApproaching(OutputDevice& od, const std::string fromLaneID) const;
448 
450  void passedJunction(const MSVehicle* vehicle) const;
451 
453  MSLink* getParallelLink(int direction) const;
454 
456  bool isLeader(const MSVehicle* ego, const MSVehicle* foe) const;
457 
459  bool fromInternalLane() const;
460 
462  bool isExitLink() const;
463 
466 
468  bool isInternalJunctionLink() const;
469 
472  return myMesoTLSPenalty;
473  }
474 
476  double getGreenFraction() const {
477  return myGreenFraction;
478  }
479 
481  void setMesoTLSPenalty(const SUMOTime penalty) {
482  myMesoTLSPenalty = penalty;
483  }
484 
486  void setGreenFraction(const double fraction) {
487  myGreenFraction = fraction;
488  }
489 
490  const std::vector<const MSLane*>& getFoeLanes() const {
491  return myFoeLanes;
492  }
493 
494  const std::vector<std::pair<double, double> >& getLengthsBehindCrossing() const {
496  }
497 
498  const std::vector<MSLink*>& getFoeLinks() const {
499  return myFoeLinks;
500  }
501 
503  void initParallelLinks();
504 
505 private:
507  static inline bool unsafeMergeSpeeds(double leaderSpeed, double followerSpeed, double leaderDecel, double followerDecel) {
508  // XXX mismatch between continuous an discrete deceleration
509  return (leaderSpeed * leaderSpeed / leaderDecel) <= (followerSpeed * followerSpeed / followerDecel);
510  }
511 
513  static bool maybeOccupied(MSLane* lane);
514 
516  static bool couldBrakeForLeader(double followDist, double leaderDist, const MSVehicle* follow, const MSVehicle* leader);
517 
518  MSLink* computeParallelLink(int direction);
519 
520  bool blockedByFoe(const SUMOVehicle* veh, const ApproachingVehicleInformation& avi,
521  SUMOTime arrivalTime, SUMOTime leaveTime, double arrivalSpeed, double leaveSpeed,
522  bool sameTargetLane, double impatience, double decel, SUMOTime waitingTime,
523  const SUMOVehicle* ego) const;
524 
525 private:
528 
531 
532  std::map<const SUMOVehicle*, ApproachingVehicleInformation, ComparatorIdLess> myApproachingVehicles;
533  std::set<MSLink*> myBlockedFoeLinks;
534 
536  int myIndex;
537 
539  const int myTLIndex;
540 
543 
546 
549 
552 
555  double myLength;
556 
561 
563  bool myHasFoes;
564 
565  // @todo documentation
566  bool myAmCont;
567 
569 
572 
573  /* @brief The preceding junction-internal lane, only used at
574  * - exit links (from internal lane to normal lane)
575  * - internal junction links (from internal lane to internal lane)
576  */
578 
583 
584  /* @brief lengths after the crossing point with foeLane
585  * (lengthOnThis, lengthOnFoe)
586  * (index corresponds to myFoeLanes)
587  * empty vector for entry links
588  * */
589  std::vector<std::pair<double, double> > myLengthsBehindCrossing;
590 
591  // TODO: documentation
592  std::vector<MSLink*> myFoeLinks;
593  std::vector<const MSLane*> myFoeLanes;
595 
596  /* @brief Links with the same origin lane and the same destination edge that may
597  be in conflict for sublane simulation */
598  std::vector<MSLink*> mySublaneFoeLinks;
599 
600  /* @brief Internal Lanes with the same origin lane and the same destination edge that may
601  be in conflict for sublane simulation */
602  std::vector<MSLane*> mySublaneFoeLanes;
603 
604  static const SUMOTime myLookaheadTime;
606 
609 
612 
614  MSLink(const MSLink& s);
615 
617  MSLink& operator=(const MSLink& s);
618 
619 };
620 
621 
622 #endif
623 
624 /****************************************************************************/
625 
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:83
The base class for an intersection.
Definition: MSJunction.h:64
LinkDirection
The different directions a link between two lanes may take (or a stream between two edges)...
Representation of a vehicle.
Definition: SUMOVehicle.h:66
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:70
long long int SUMOTime
Definition: TraCIDefs.h:51
The link has yellow light, has to brake anyway.
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
The link has red light (must brake) but indicates upcoming green.