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, bool keepClear, MSTrafficLightLogic* logic, int tlLinkIdx);
156 #else
157 
165  MSLink(MSLane* predLane, MSLane* succLane, MSLane* via, LinkDirection dir, LinkState state, SUMOReal length, 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 
356  bool hasFoes() const {
357  return myHasFoes;
358  }
359 
360 
361  bool isCont() const {
362  return myAmCont;
363  }
364 
365 
367  bool keepClear() const {
368  return myKeepClear;
369  }
370 
372  bool lastWasContMajor() const;
373 
374 
375 #ifdef HAVE_INTERNAL_LANES
376 
380  MSLane* getViaLane() const;
381 
382 
390  LinkLeaders getLeaderInfo(SUMOReal dist, SUMOReal minGap, std::vector<const MSPerson*>* collectBlockers = 0) const;
391 #endif
392 
394  SUMOReal getZipperSpeed(const MSVehicle* ego, const SUMOReal dist, SUMOReal vSafe,
395  SUMOTime arrivalTime,
396  std::vector<const SUMOVehicle*>* collectFoes) const;
397 
399  MSLane* getViaLaneOrLane() const;
400 
402  const MSLane* getLaneBefore() const;
403 
405  const MSLane* getInternalLaneBefore() const;
406 
408  SUMOTime getLeaveTime(const SUMOTime arrivalTime, const SUMOReal arrivalSpeed, const SUMOReal leaveSpeed, const SUMOReal vehicleLength) const;
409 
411  void writeApproaching(OutputDevice& od, const std::string fromLaneID) const;
412 
414  void passedJunction(const MSVehicle* vehicle);
415 
417  MSLink* getParallelLink(int direction) const;
418 
420  bool isLeader(const MSVehicle* ego, const MSVehicle* foe);
421 
423  bool fromInternalLane() const;
424 
426  bool isExitLink() const;
427 
429  bool isInternalJunctionLink() const;
430 
433  return myMesoTLSPenalty;
434  }
435 
437  void setMesoTLSPenalty(const SUMOTime penalty) {
438  myMesoTLSPenalty = penalty;
439  }
440 
441  const std::vector<const MSLane*>& getFoeLanes() {
442  return myFoeLanes;
443  }
444 
446  void initParallelLinks();
447 
448 private:
450  static inline bool unsafeMergeSpeeds(SUMOReal leaderSpeed, SUMOReal followerSpeed, SUMOReal leaderDecel, SUMOReal followerDecel) {
451  // XXX mismatch between continuous an discrete deceleration
452  return (leaderSpeed * leaderSpeed / leaderDecel) <= (followerSpeed * followerSpeed / followerDecel);
453  }
454 
456  static bool maybeOccupied(MSLane* lane);
457 
459  static bool couldBrakeForLeader(SUMOReal followDist, SUMOReal leaderDist, const MSVehicle* follow, const MSVehicle* leader);
460 
461  MSLink* computeParallelLink(int direction);
462 
463  bool blockedByFoe(const SUMOVehicle* veh, const ApproachingVehicleInformation& avi, SUMOTime arrivalTime, SUMOTime leaveTime, SUMOReal arrivalSpeed, SUMOReal leaveSpeed,
464  bool sameTargetLane, SUMOReal impatience, SUMOReal decel, SUMOTime waitingTime) const;
465 
466 private:
469 
472 
473  std::map<const SUMOVehicle*, ApproachingVehicleInformation> myApproachingVehicles;
474  std::set<MSLink*> myBlockedFoeLinks;
475 
477  int myIndex;
478 
480  const int myTLIndex;
481 
484 
487 
490 
493 
496 
498  bool myHasFoes;
499 
500  bool myAmCont;
501 
503 
506 
507 #ifdef HAVE_INTERNAL_LANES
508  MSLane* const myInternalLane;
510 
512  // XXX obsolete as this is identical with myLaneBefore
513  const MSLane* myInternalLaneBefore;
514 
515  /* @brief lengths after the crossing point with foeLane
516  * (lengthOnThis, lengthOnFoe)
517  * (index corresponds to myFoeLanes)
518  * empty vector for entry links
519  * */
520  std::vector<std::pair<SUMOReal, SUMOReal> > myLengthsBehindCrossing;
521 #endif
522 
523  std::vector<MSLink*> myFoeLinks;
524  std::vector<const MSLane*> myFoeLanes;
525 
526  /* @brief with the same origin lane and the same destination edge that may
527  be in conflict for sublane simulation */
528  std::vector<MSLink*> mySublaneFoeLinks;
529 
530  static const SUMOTime myLookaheadTime;
532 
535 
538 
540  MSLink(const MSLink& s);
541 
543  MSLink& operator=(const MSLink& s);
544 
545 };
546 
547 
548 #endif
549 
550 /****************************************************************************/
551 
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:81
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.