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) 2001-2016 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  MSLane* getApproachingLane() 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 isTLSControlled() const {
341  return myLogic != 0;
342  }
343 
348  SUMOReal getLength() const {
349  return myLength;
350  }
351 
352 
361  }
362 
363 
368  bool hasFoes() const {
369  return myHasFoes;
370  }
371 
372  // @todo documentation
373  bool isCont() const {
374  return myAmCont;
375  }
376 
377 
379  bool keepClear() const {
380  return myKeepClear;
381  }
382 
384  bool lastWasContMajor() const;
385 
390 
391 #ifdef HAVE_INTERNAL_LANES
392 
396  MSLane* getViaLane() const;
397 
405  LinkLeaders getLeaderInfo(SUMOReal dist, SUMOReal minGap, std::vector<const MSPerson*>* collectBlockers = 0) const;
406 #endif
407 
409  SUMOReal getZipperSpeed(const MSVehicle* ego, const SUMOReal dist, SUMOReal vSafe,
410  SUMOTime arrivalTime,
411  std::vector<const SUMOVehicle*>* collectFoes) const;
412 
414  MSLane* getViaLaneOrLane() const;
415 
417  const MSLane* getLaneBefore() const;
418 
420  const MSLane* getInternalLaneBefore() const;
421 
423  SUMOTime getLeaveTime(const SUMOTime arrivalTime, const SUMOReal arrivalSpeed, const SUMOReal leaveSpeed, const SUMOReal vehicleLength) const;
424 
426  void writeApproaching(OutputDevice& od, const std::string fromLaneID) const;
427 
429  void passedJunction(const MSVehicle* vehicle);
430 
432  MSLink* getParallelLink(int direction) const;
433 
435  bool isLeader(const MSVehicle* ego, const MSVehicle* foe);
436 
438  bool fromInternalLane() const;
439 
441  bool isExitLink() const;
442 
444  bool isInternalJunctionLink() const;
445 
448  return myMesoTLSPenalty;
449  }
450 
452  void setMesoTLSPenalty(const SUMOTime penalty) {
453  myMesoTLSPenalty = penalty;
454  }
455 
456  const std::vector<const MSLane*>& getFoeLanes() {
457  return myFoeLanes;
458  }
459 
461  void initParallelLinks();
462 
463 private:
465  static inline bool unsafeMergeSpeeds(SUMOReal leaderSpeed, SUMOReal followerSpeed, SUMOReal leaderDecel, SUMOReal followerDecel) {
466  // XXX mismatch between continuous an discrete deceleration
467  return (leaderSpeed * leaderSpeed / leaderDecel) <= (followerSpeed * followerSpeed / followerDecel);
468  }
469 
471  static bool maybeOccupied(MSLane* lane);
472 
474  static bool couldBrakeForLeader(SUMOReal followDist, SUMOReal leaderDist, const MSVehicle* follow, const MSVehicle* leader);
475 
476  MSLink* computeParallelLink(int direction);
477 
478  bool blockedByFoe(const SUMOVehicle* veh, const ApproachingVehicleInformation& avi, SUMOTime arrivalTime, SUMOTime leaveTime, SUMOReal arrivalSpeed, SUMOReal leaveSpeed,
479  bool sameTargetLane, SUMOReal impatience, SUMOReal decel, SUMOTime waitingTime) const;
480 
481 private:
484 
487 
488  std::map<const SUMOVehicle*, ApproachingVehicleInformation> myApproachingVehicles;
489  std::set<MSLink*> myBlockedFoeLinks;
490 
492  int myIndex;
493 
495  const int myTLIndex;
496 
499 
502 
505 
508 
511 
513  bool myHasFoes;
514 
515  // @todo documentation
516  bool myAmCont;
517 
519 
524 
527 
528 #ifdef HAVE_INTERNAL_LANES
529  MSLane* const myInternalLane;
531 
533  // XXX obsolete as this is identical with myLaneBefore
534  const MSLane* myInternalLaneBefore;
535 
536  /* @brief lengths after the crossing point with foeLane
537  * (lengthOnThis, lengthOnFoe)
538  * (index corresponds to myFoeLanes)
539  * empty vector for entry links
540  * */
541  std::vector<std::pair<SUMOReal, SUMOReal> > myLengthsBehindCrossing;
542 #endif
543 
544  std::vector<MSLink*> myFoeLinks;
545  std::vector<const MSLane*> myFoeLanes;
546 
547  /* @brief with the same origin lane and the same destination edge that may
548  be in conflict for sublane simulation */
549  std::vector<MSLink*> mySublaneFoeLinks;
550 
551  static const SUMOTime myLookaheadTime;
553 
556 
559 
561  MSLink(const MSLink& s);
562 
564  MSLink& operator=(const MSLink& s);
565 
566 };
567 
568 
569 #endif
570 
571 /****************************************************************************/
572 
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:82
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: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 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:213
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
The link has red light (must brake) but indicates upcoming green.