SUMO - Simulation of Urban MObility
MSLink.h
Go to the documentation of this file.
1 /****************************************************************************/
9 // A connnection between lanes
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2002-2017 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 #ifndef MSLink_h
23 #define MSLink_h
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #include <vector>
36 #include <set>
37 #include <utils/common/SUMOTime.h>
40 
41 
42 // ===========================================================================
43 // class declarations
44 // ===========================================================================
45 class MSLane;
46 class MSJunction;
47 class SUMOVehicle;
48 class MSVehicle;
49 class MSPerson;
50 class OutputDevice;
52 
53 
54 // ===========================================================================
55 // class definitions
56 // ===========================================================================
77 class MSLink {
78 public:
79 
80  // distance to link in m below which adaptation for zipper-merging should take place
81  static const double ZIPPER_ADAPT_DIST;
82 
83  struct LinkLeader {
84  LinkLeader(MSVehicle* _veh, double _gap, double _distToCrossing, bool _fromLeft = true) :
85  vehAndGap(std::make_pair(_veh, _gap)),
86  distToCrossing(_distToCrossing),
87  fromLeft(_fromLeft) {
88  }
89 
90  std::pair<MSVehicle*, double> vehAndGap;
92  bool fromLeft;
93  };
94 
95  typedef std::vector<LinkLeader> LinkLeaders;
96 
106  ApproachingVehicleInformation(const SUMOTime _arrivalTime, const SUMOTime _leavingTime,
107  const double _arrivalSpeed, const double _leaveSpeed,
108  const bool _willPass,
109  const SUMOTime _arrivalTimeBraking,
110  const double _arrivalSpeedBraking,
111  const SUMOTime _waitingTime,
112  const double _dist
113  ) :
114  arrivalTime(_arrivalTime), leavingTime(_leavingTime),
115  arrivalSpeed(_arrivalSpeed), leaveSpeed(_leaveSpeed),
116  willPass(_willPass),
117  arrivalTimeBraking(_arrivalTimeBraking),
118  arrivalSpeedBraking(_arrivalSpeedBraking),
119  waitingTime(_waitingTime),
120  dist(_dist) {
121  }
122 
128  const double arrivalSpeed;
130  const double leaveSpeed;
132  const bool willPass;
136  const double arrivalSpeedBraking;
140  const double dist;
141 
142  private:
145 
146  };
147 
148 
157  MSLink(MSLane* predLane, MSLane* succLane, MSLane* via, LinkDirection dir, LinkState state, double length, double foeVisibilityDistance, bool keepClear, MSTrafficLightLogic* logic, int tlLinkIdx);
158 
159 
161  ~MSLink();
162 
163 
171  void setRequestInformation(int index, bool hasFoes, bool isCont,
172  const std::vector<MSLink*>& foeLinks, const std::vector<MSLane*>& foeLanes,
173  MSLane* internalLaneBefore = 0);
174 
176  void addWalkingAreaFoe(const MSLane* lane) {
177  myWalkingAreaFoe = lane;
178  }
179 
182  return myWalkingAreaFoe;
183  }
184 
189  void setApproaching(const SUMOVehicle* approaching, const SUMOTime arrivalTime,
190  const double arrivalSpeed, const double leaveSpeed, const bool setRequest,
191  const SUMOTime arrivalTimeBraking, const double arrivalSpeedBraking,
192  const SUMOTime waitingTime, double dist);
193 
195  void removeApproaching(const SUMOVehicle* veh);
196 
197  void addBlockedLink(MSLink* link);
198 
199  /* @brief return information about this vehicle if it is registered as
200  * approaching (dummy values otherwise)
201  * @note used for visualisation of link items */
203 
205  const std::map<const SUMOVehicle*, ApproachingVehicleInformation>& getApproaching() const {
206  return myApproachingVehicles;
207  }
208 
216  bool opened(SUMOTime arrivalTime, double arrivalSpeed, double leaveSpeed, double vehicleLength,
217  double impatience, double decel, SUMOTime waitingTime,
218  double posLat = 0,
219  std::vector<const SUMOVehicle*>* collectFoes = 0,
220  bool ignoreRed = false,
221  const SUMOVehicle* ego = 0) const;
222 
237  bool blockedAtTime(SUMOTime arrivalTime, SUMOTime leaveTime, double arrivalSpeed, double leaveSpeed,
238  bool sameTargetLane, double impatience, double decel, SUMOTime waitingTime,
239  std::vector<const SUMOVehicle*>* collectFoes = 0, const SUMOVehicle* ego = 0) const;
240 
241 
242  bool isBlockingAnyone() const {
243  return myApproachingVehicles.size() != 0;
244  }
245 
246  bool willHaveBlockedFoe() const;
247 
248 
249 
259  bool hasApproachingFoe(SUMOTime arrivalTime, SUMOTime leaveTime, double speed, double decel) const;
260 
262  return myJunction;
263  }
264 
265 
270  LinkState getState() const {
271  return myState;
272  }
273 
274 
275  //@brief Returns the time of the last state change
276  inline SUMOTime getLastStateChange() const {
277  return myLastStateChange;
278  }
279 
280 
285  LinkDirection getDirection() const;
286 
287 
293  void setTLState(LinkState state, SUMOTime t);
294 
295 
300  MSLane* getLane() const;
301 
302 
307  inline int getIndex() const {
308  return myIndex;
309  }
310 
312  inline int getTLIndex() const {
313  return myTLIndex;
314  }
315 
317  inline const MSTrafficLightLogic* getTLLogic() const {
318  return myLogic;
319  }
320 
324  inline bool havePriority() const {
325  return myState >= 'A' && myState <= 'Z';
326  }
327 
331  inline bool haveRed() const {
333  }
334 
335  inline bool haveYellow() const {
337  }
338 
339  inline bool isTLSControlled() const {
340  return myLogic != 0;
341  }
342 
347  double getLength() const {
348  return myLength;
349  }
350 
351 
358  double getFoeVisibilityDistance() const {
360  }
361 
362 
367  bool hasFoes() const {
368  return myHasFoes;
369  }
370 
371  // @todo documentation
372  bool isCont() const {
373  return myAmCont;
374  }
375 
376 
378  bool keepClear() const {
379  return myKeepClear;
380  }
381 
383  bool lastWasContMajor() const;
384 
388  double getInternalLengthsAfter() const;
389 
393  double getInternalLengthsBefore() const;
394 
400  double getLengthsBeforeCrossing(const MSLane* foeLane) const;
401 
402 
408  double getLengthBeforeCrossing(const MSLane* foeLane) const;
409 
410 
415  MSLane* getViaLane() const;
416 
425  LinkLeaders getLeaderInfo(const MSVehicle* ego, double dist, std::vector<const MSPerson*>* collectBlockers = 0, bool isShadowLink = false) const;
426 
428  double getZipperSpeed(const MSVehicle* ego, const double dist, double vSafe,
429  SUMOTime arrivalTime,
430  std::vector<const SUMOVehicle*>* collectFoes) const;
431 
433  MSLane* getViaLaneOrLane() const;
434 
436  const MSLane* getLaneBefore() const;
437 
439  const MSLane* getInternalLaneBefore() const;
440 
442  SUMOTime getLeaveTime(const SUMOTime arrivalTime, const double arrivalSpeed, const double leaveSpeed, const double vehicleLength) const;
443 
445  void writeApproaching(OutputDevice& od, const std::string fromLaneID) const;
446 
448  void passedJunction(const MSVehicle* vehicle);
449 
451  MSLink* getParallelLink(int direction) const;
452 
454  bool isLeader(const MSVehicle* ego, const MSVehicle* foe) const;
455 
457  bool fromInternalLane() const;
458 
460  bool isExitLink() const;
461 
464 
466  bool isInternalJunctionLink() const;
467 
470  return myMesoTLSPenalty;
471  }
472 
474  double getGreenFraction() const {
475  return myGreenFraction;
476  }
477 
479  void setMesoTLSPenalty(const SUMOTime penalty) {
480  myMesoTLSPenalty = penalty;
481  }
482 
484  void setGreenFraction(const double fraction) {
485  myGreenFraction = fraction;
486  }
487 
488  const std::vector<const MSLane*>& getFoeLanes() const {
489  return myFoeLanes;
490  }
491 
492  const std::vector<std::pair<double, double> >& getLengthsBehindCrossing() const {
494  }
495 
496  const std::vector<MSLink*>& getFoeLinks() const {
497  return myFoeLinks;
498  }
499 
501  void initParallelLinks();
502 
503 private:
505  static inline bool unsafeMergeSpeeds(double leaderSpeed, double followerSpeed, double leaderDecel, double followerDecel) {
506  // XXX mismatch between continuous an discrete deceleration
507  return (leaderSpeed * leaderSpeed / leaderDecel) <= (followerSpeed * followerSpeed / followerDecel);
508  }
509 
511  static bool maybeOccupied(MSLane* lane);
512 
514  static bool couldBrakeForLeader(double followDist, double leaderDist, const MSVehicle* follow, const MSVehicle* leader);
515 
516  MSLink* computeParallelLink(int direction);
517 
518  bool blockedByFoe(const SUMOVehicle* veh, const ApproachingVehicleInformation& avi, SUMOTime arrivalTime, SUMOTime leaveTime, double arrivalSpeed, double leaveSpeed,
519  bool sameTargetLane, double impatience, double decel, SUMOTime waitingTime) const;
520 
521 private:
524 
527 
528  std::map<const SUMOVehicle*, ApproachingVehicleInformation> myApproachingVehicles;
529  std::set<MSLink*> myBlockedFoeLinks;
530 
532  int myIndex;
533 
535  const int myTLIndex;
536 
539 
542 
545 
548 
551  double myLength;
552 
557 
559  bool myHasFoes;
560 
561  // @todo documentation
562  bool myAmCont;
563 
565 
568 
569  /* @brief The preceding junction-internal lane, only used at
570  * - exit links (from internal lane to normal lane)
571  * - internal junction links (from internal lane to internal lane)
572  */
574 
579 
580  /* @brief lengths after the crossing point with foeLane
581  * (lengthOnThis, lengthOnFoe)
582  * (index corresponds to myFoeLanes)
583  * empty vector for entry links
584  * */
585  std::vector<std::pair<double, double> > myLengthsBehindCrossing;
586 
587  // TODO: documentation
588  std::vector<MSLink*> myFoeLinks;
589  std::vector<const MSLane*> myFoeLanes;
591 
592  /* @brief Links with the same origin lane and the same destination edge that may
593  be in conflict for sublane simulation */
594  std::vector<MSLink*> mySublaneFoeLinks;
595 
596  /* @brief Internal Lanes with the same origin lane and the same destination edge that may
597  be in conflict for sublane simulation */
598  std::vector<MSLane*> mySublaneFoeLanes;
599 
600  static const SUMOTime myLookaheadTime;
602 
605 
608 
610  MSLink(const MSLink& s);
611 
613  MSLink& operator=(const MSLink& s);
614 
615 };
616 
617 
618 #endif
619 
620 /****************************************************************************/
621 
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:67
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:71
long long int SUMOTime
Definition: TraCIDefs.h:52
The link has yellow light, has to brake anyway.
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
The link has red light (must brake) but indicates upcoming green.