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
82 
83  struct LinkLeader {
84  LinkLeader(MSVehicle* _veh, SUMOReal _gap, SUMOReal _distToCrossing) :
85  vehAndGap(std::make_pair(_veh, _gap)),
86  distToCrossing(_distToCrossing) {}
87 
88  std::pair<MSVehicle*, SUMOReal> vehAndGap;
90  };
91 
92  typedef std::vector<LinkLeader> LinkLeaders;
93 
103  ApproachingVehicleInformation(const SUMOTime _arrivalTime, const SUMOTime _leavingTime,
104  const SUMOReal _arrivalSpeed, const SUMOReal _leaveSpeed,
105  const bool _willPass,
106  const SUMOTime _arrivalTimeBraking,
107  const SUMOReal _arrivalSpeedBraking,
108  const SUMOTime _waitingTime,
109  const SUMOReal _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 
129  const bool willPass;
137  const SUMOReal dist;
138 
139  private:
142 
143  };
144 
145 
146 #ifndef HAVE_INTERNAL_LANES
147 
155  MSLink(MSLane* predLane, MSLane* succLane, LinkDirection dir, LinkState state, SUMOReal length, SUMOReal foeVisibilityDistance, bool keepClear, MSTrafficLightLogic* logic, int tlLinkIdx);
156 #else
157 
165  MSLink(MSLane* predLane, MSLane* succLane, MSLane* via, LinkDirection dir, LinkState state, SUMOReal length, SUMOReal foeVisibilityDistance, bool keepClear, MSTrafficLightLogic* logic, int tlLinkIdx);
166 #endif
167 
168 
170  ~MSLink();
171 
172 
180  void setRequestInformation(int index, bool hasFoes, bool isCont,
181  const std::vector<MSLink*>& foeLinks, const std::vector<MSLane*>& foeLanes,
182  MSLane* internalLaneBefore = 0);
183 
184 
189  void setApproaching(const SUMOVehicle* approaching, const SUMOTime arrivalTime,
190  const SUMOReal arrivalSpeed, const SUMOReal leaveSpeed, const bool setRequest,
191  const SUMOTime arrivalTimeBraking, const SUMOReal arrivalSpeedBraking,
192  const SUMOTime waitingTime, SUMOReal 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, SUMOReal arrivalSpeed, SUMOReal leaveSpeed, SUMOReal vehicleLength,
217  SUMOReal impatience, SUMOReal decel, SUMOTime waitingTime,
218  SUMOReal posLat = 0,
219  std::vector<const SUMOVehicle*>* collectFoes = 0) const;
220 
235  bool blockedAtTime(SUMOTime arrivalTime, SUMOTime leaveTime, SUMOReal arrivalSpeed, SUMOReal leaveSpeed,
236  bool sameTargetLane, SUMOReal impatience, SUMOReal decel, SUMOTime waitingTime,
237  std::vector<const SUMOVehicle*>* collectFoes = 0) const;
238 
239 
240  bool isBlockingAnyone() const {
241  return myApproachingVehicles.size() != 0;
242  }
243 
244  bool willHaveBlockedFoe() const;
245 
246 
247 
257  bool hasApproachingFoe(SUMOTime arrivalTime, SUMOTime leaveTime, SUMOReal speed, SUMOReal decel) const;
258 
260  return myJunction;
261  }
262 
263 
268  LinkState getState() const {
269  return myState;
270  }
271 
272 
273  //@brief Returns the time of the last state change
274  inline SUMOTime getLastStateChange() const {
275  return myLastStateChange;
276  }
277 
278 
283  LinkDirection getDirection() const;
284 
285 
291  void setTLState(LinkState state, SUMOTime t);
292 
293 
298  MSLane* getLane() const;
299 
300 
305  inline int getIndex() const {
306  return myIndex;
307  }
308 
310  inline int getTLIndex() const {
311  return myTLIndex;
312  }
313 
315  inline const MSTrafficLightLogic* getTLLogic() const {
316  return myLogic;
317  }
318 
322  inline bool havePriority() const {
323  return myState >= 'A' && myState <= 'Z';
324  }
325 
329  inline bool haveRed() const {
331  }
332 
333  inline bool isTLSControlled() const {
334  return myLogic != 0;
335  }
336 
341  SUMOReal getLength() const {
342  return myLength;
343  }
344 
345 
354  }
355 
356 
361  bool hasFoes() const {
362  return myHasFoes;
363  }
364 
365  // @todo documentation
366  bool isCont() const {
367  return myAmCont;
368  }
369 
370 
372  bool keepClear() const {
373  return myKeepClear;
374  }
375 
377  bool lastWasContMajor() const;
378 
383 
384 #ifdef HAVE_INTERNAL_LANES
385 
389  MSLane* getViaLane() const;
390 
398  LinkLeaders getLeaderInfo(const MSVehicle* ego, SUMOReal dist, std::vector<const MSPerson*>* collectBlockers = 0) const;
399 #endif
400 
402  SUMOReal getZipperSpeed(const MSVehicle* ego, const SUMOReal dist, SUMOReal vSafe,
403  SUMOTime arrivalTime,
404  std::vector<const SUMOVehicle*>* collectFoes) const;
405 
407  MSLane* getViaLaneOrLane() const;
408 
410  const MSLane* getLaneBefore() const;
411 
413  const MSLane* getInternalLaneBefore() const;
414 
416  SUMOTime getLeaveTime(const SUMOTime arrivalTime, const SUMOReal arrivalSpeed, const SUMOReal leaveSpeed, const SUMOReal vehicleLength) const;
417 
419  void writeApproaching(OutputDevice& od, const std::string fromLaneID) const;
420 
422  void passedJunction(const MSVehicle* vehicle);
423 
425  MSLink* getParallelLink(int direction) const;
426 
428  bool isLeader(const MSVehicle* ego, const MSVehicle* foe);
429 
431  bool fromInternalLane() const;
432 
434  bool isExitLink() const;
435 
437  bool isInternalJunctionLink() const;
438 
441  return myMesoTLSPenalty;
442  }
443 
446  return myGreenFraction;
447  }
448 
450  void setMesoTLSPenalty(const SUMOTime penalty) {
451  myMesoTLSPenalty = penalty;
452  }
453 
455  void setGreenFraction(const SUMOReal fraction) {
456  myGreenFraction = fraction;
457  }
458 
459  const std::vector<const MSLane*>& getFoeLanes() {
460  return myFoeLanes;
461  }
462 
464  void initParallelLinks();
465 
466 private:
468  static inline bool unsafeMergeSpeeds(SUMOReal leaderSpeed, SUMOReal followerSpeed, SUMOReal leaderDecel, SUMOReal followerDecel) {
469  // XXX mismatch between continuous an discrete deceleration
470  return (leaderSpeed * leaderSpeed / leaderDecel) <= (followerSpeed * followerSpeed / followerDecel);
471  }
472 
474  static bool maybeOccupied(MSLane* lane);
475 
477  static bool couldBrakeForLeader(SUMOReal followDist, SUMOReal leaderDist, const MSVehicle* follow, const MSVehicle* leader);
478 
479  MSLink* computeParallelLink(int direction);
480 
481  bool blockedByFoe(const SUMOVehicle* veh, const ApproachingVehicleInformation& avi, SUMOTime arrivalTime, SUMOTime leaveTime, SUMOReal arrivalSpeed, SUMOReal leaveSpeed,
482  bool sameTargetLane, SUMOReal impatience, SUMOReal decel, SUMOTime waitingTime) const;
483 
484 private:
487 
490 
491  std::map<const SUMOVehicle*, ApproachingVehicleInformation> myApproachingVehicles;
492  std::set<MSLink*> myBlockedFoeLinks;
493 
495  int myIndex;
496 
498  const int myTLIndex;
499 
502 
505 
508 
511 
514 
519 
521  bool myHasFoes;
522 
523  // @todo documentation
524  bool myAmCont;
525 
527 
531 
532 #ifdef HAVE_INTERNAL_LANES
533  MSLane* const myInternalLane;
535 
536  /* @brief The preceding junction-internal lane, only used at
537  * - exit links (from internal lane to normal lane)
538  * - internal junction links (from internal lane to internal lane)
539  */
540  const MSLane* myInternalLaneBefore;
541 
542  /* @brief lengths after the crossing point with foeLane
543  * (lengthOnThis, lengthOnFoe)
544  * (index corresponds to myFoeLanes)
545  * empty vector for entry links
546  * */
547  std::vector<std::pair<SUMOReal, SUMOReal> > myLengthsBehindCrossing;
548 #endif
549 
550  std::vector<MSLink*> myFoeLinks;
551  std::vector<const MSLane*> myFoeLanes;
552 
553  /* @brief with the same origin lane and the same destination edge that may
554  be in conflict for sublane simulation */
555  std::vector<MSLink*> mySublaneFoeLinks;
556 
557  static const SUMOTime myLookaheadTime;
559 
562 
565 
567  MSLink(const MSLink& s);
568 
570  MSLink& operator=(const MSLink& s);
571 
572 };
573 
574 
575 #endif
576 
577 /****************************************************************************/
578 
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:83
long long int SUMOTime
Definition: SUMOTime.h:43
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
#define SUMOReal
Definition: config.h:208
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
The link has red light (must brake) but indicates upcoming green.