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) :
85  vehAndGap(std::make_pair(_veh, _gap)),
86  distToCrossing(_distToCrossing) {}
87 
88  std::pair<MSVehicle*, double> vehAndGap;
90  };
91 
92  typedef std::vector<LinkLeader> LinkLeaders;
93 
103  ApproachingVehicleInformation(const SUMOTime _arrivalTime, const SUMOTime _leavingTime,
104  const double _arrivalSpeed, const double _leaveSpeed,
105  const bool _willPass,
106  const SUMOTime _arrivalTimeBraking,
107  const double _arrivalSpeedBraking,
108  const SUMOTime _waitingTime,
109  const double _dist
110  ) :
111  arrivalTime(_arrivalTime), leavingTime(_leavingTime),
112  arrivalSpeed(_arrivalSpeed), leaveSpeed(_leaveSpeed),
113  willPass(_willPass),
114  arrivalTimeBraking(_arrivalTimeBraking),
115  arrivalSpeedBraking(_arrivalSpeedBraking),
116  waitingTime(_waitingTime),
117  dist(_dist) {
118  }
119 
125  const double arrivalSpeed;
127  const double leaveSpeed;
129  const bool willPass;
133  const double arrivalSpeedBraking;
137  const double dist;
138 
139  private:
142 
143  };
144 
145 
154  MSLink(MSLane* predLane, MSLane* succLane, MSLane* via, LinkDirection dir, LinkState state, double length, double foeVisibilityDistance, bool keepClear, MSTrafficLightLogic* logic, int tlLinkIdx);
155 
156 
158  ~MSLink();
159 
160 
168  void setRequestInformation(int index, bool hasFoes, bool isCont,
169  const std::vector<MSLink*>& foeLinks, const std::vector<MSLane*>& foeLanes,
170  MSLane* internalLaneBefore = 0);
171 
172 
177  void setApproaching(const SUMOVehicle* approaching, const SUMOTime arrivalTime,
178  const double arrivalSpeed, const double leaveSpeed, const bool setRequest,
179  const SUMOTime arrivalTimeBraking, const double arrivalSpeedBraking,
180  const SUMOTime waitingTime, double dist);
181 
183  void removeApproaching(const SUMOVehicle* veh);
184 
185  void addBlockedLink(MSLink* link);
186 
187  /* @brief return information about this vehicle if it is registered as
188  * approaching (dummy values otherwise)
189  * @note used for visualisation of link items */
191 
193  const std::map<const SUMOVehicle*, ApproachingVehicleInformation>& getApproaching() const {
194  return myApproachingVehicles;
195  }
196 
204  bool opened(SUMOTime arrivalTime, double arrivalSpeed, double leaveSpeed, double vehicleLength,
205  double impatience, double decel, SUMOTime waitingTime,
206  double posLat = 0,
207  std::vector<const SUMOVehicle*>* collectFoes = 0) const;
208 
223  bool blockedAtTime(SUMOTime arrivalTime, SUMOTime leaveTime, double arrivalSpeed, double leaveSpeed,
224  bool sameTargetLane, double impatience, double decel, SUMOTime waitingTime,
225  std::vector<const SUMOVehicle*>* collectFoes = 0) const;
226 
227 
228  bool isBlockingAnyone() const {
229  return myApproachingVehicles.size() != 0;
230  }
231 
232  bool willHaveBlockedFoe() const;
233 
234 
235 
245  bool hasApproachingFoe(SUMOTime arrivalTime, SUMOTime leaveTime, double speed, double decel) const;
246 
248  return myJunction;
249  }
250 
251 
256  LinkState getState() const {
257  return myState;
258  }
259 
260 
261  //@brief Returns the time of the last state change
262  inline SUMOTime getLastStateChange() const {
263  return myLastStateChange;
264  }
265 
266 
271  LinkDirection getDirection() const;
272 
273 
279  void setTLState(LinkState state, SUMOTime t);
280 
281 
286  MSLane* getLane() const;
287 
288 
293  inline int getIndex() const {
294  return myIndex;
295  }
296 
298  inline int getTLIndex() const {
299  return myTLIndex;
300  }
301 
303  inline const MSTrafficLightLogic* getTLLogic() const {
304  return myLogic;
305  }
306 
310  inline bool havePriority() const {
311  return myState >= 'A' && myState <= 'Z';
312  }
313 
317  inline bool haveRed() const {
319  }
320 
321  inline bool isTLSControlled() const {
322  return myLogic != 0;
323  }
324 
329  double getLength() const {
330  return myLength;
331  }
332 
333 
340  double getFoeVisibilityDistance() const {
342  }
343 
344 
349  bool hasFoes() const {
350  return myHasFoes;
351  }
352 
353  // @todo documentation
354  bool isCont() const {
355  return myAmCont;
356  }
357 
358 
360  bool keepClear() const {
361  return myKeepClear;
362  }
363 
365  bool lastWasContMajor() const;
366 
370  double getInternalLengthsAfter() const;
371 
375  double getLengthBeforeCrossing(const MSLink* foeEntryLink) const;
376 
381  MSLane* getViaLane() const;
382 
390  LinkLeaders getLeaderInfo(const MSVehicle* ego, double dist, std::vector<const MSPerson*>* collectBlockers = 0) const;
391 
393  double getZipperSpeed(const MSVehicle* ego, const double dist, double vSafe,
394  SUMOTime arrivalTime,
395  std::vector<const SUMOVehicle*>* collectFoes) const;
396 
398  MSLane* getViaLaneOrLane() const;
399 
401  const MSLane* getLaneBefore() const;
402 
404  const MSLane* getInternalLaneBefore() const;
405 
407  SUMOTime getLeaveTime(const SUMOTime arrivalTime, const double arrivalSpeed, const double leaveSpeed, const double vehicleLength) const;
408 
410  void writeApproaching(OutputDevice& od, const std::string fromLaneID) const;
411 
413  void passedJunction(const MSVehicle* vehicle);
414 
416  MSLink* getParallelLink(int direction) const;
417 
419  bool isLeader(const MSVehicle* ego, const MSVehicle* foe) const;
420 
422  bool fromInternalLane() const;
423 
425  bool isExitLink() const;
426 
428  bool isInternalJunctionLink() const;
429 
432  return myMesoTLSPenalty;
433  }
434 
436  double getGreenFraction() const {
437  return myGreenFraction;
438  }
439 
441  void setMesoTLSPenalty(const SUMOTime penalty) {
442  myMesoTLSPenalty = penalty;
443  }
444 
446  void setGreenFraction(const double fraction) {
447  myGreenFraction = fraction;
448  }
449 
450  const std::vector<const MSLane*>& getFoeLanes() {
451  return myFoeLanes;
452  }
453 
454  const std::vector<MSLink*>& getFoeLinks() {
455  return myFoeLinks;
456  }
457 
459  void initParallelLinks();
460 
461 private:
463  static inline bool unsafeMergeSpeeds(double leaderSpeed, double followerSpeed, double leaderDecel, double followerDecel) {
464  // XXX mismatch between continuous an discrete deceleration
465  return (leaderSpeed * leaderSpeed / leaderDecel) <= (followerSpeed * followerSpeed / followerDecel);
466  }
467 
469  static bool maybeOccupied(MSLane* lane);
470 
472  static bool couldBrakeForLeader(double followDist, double leaderDist, const MSVehicle* follow, const MSVehicle* leader);
473 
474  MSLink* computeParallelLink(int direction);
475 
476  bool blockedByFoe(const SUMOVehicle* veh, const ApproachingVehicleInformation& avi, SUMOTime arrivalTime, SUMOTime leaveTime, double arrivalSpeed, double leaveSpeed,
477  bool sameTargetLane, double impatience, double decel, SUMOTime waitingTime) const;
478 
479 private:
482 
485 
486  std::map<const SUMOVehicle*, ApproachingVehicleInformation> myApproachingVehicles;
487  std::set<MSLink*> myBlockedFoeLinks;
488 
490  int myIndex;
491 
493  const int myTLIndex;
494 
497 
500 
503 
506 
508  double myLength;
509 
514 
516  bool myHasFoes;
517 
518  // @todo documentation
519  bool myAmCont;
520 
522 
525 
526  /* @brief The preceding junction-internal lane, only used at
527  * - exit links (from internal lane to normal lane)
528  * - internal junction links (from internal lane to internal lane)
529  */
531 
536 
537  /* @brief lengths after the crossing point with foeLane
538  * (lengthOnThis, lengthOnFoe)
539  * (index corresponds to myFoeLanes)
540  * empty vector for entry links
541  * */
542  std::vector<std::pair<double, double> > myLengthsBehindCrossing;
543 
544  // TODO: documentation
545  std::vector<MSLink*> myFoeLinks;
546  std::vector<const MSLane*> myFoeLanes;
547 
548  /* @brief with the same origin lane and the same destination edge that may
549  be in conflict for sublane simulation */
550  std::vector<MSLink*> mySublaneFoeLinks;
551 
552  static const SUMOTime myLookaheadTime;
554 
557 
560 
562  MSLink(const MSLink& s);
563 
565  MSLink& operator=(const MSLink& s);
566 
567 };
568 
569 
570 #endif
571 
572 /****************************************************************************/
573 
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 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
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
The link has red light (must brake) but indicates upcoming green.