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;
51 
52 
53 // ===========================================================================
54 // class definitions
55 // ===========================================================================
76 class MSLink {
77 public:
78 
79  // distance to link in m below which adaptation for zipper-merging should take place
81 
82  struct LinkLeader {
83  LinkLeader(MSVehicle* _veh, SUMOReal _gap, SUMOReal _distToCrossing) :
84  vehAndGap(std::make_pair(_veh, _gap)),
85  distToCrossing(_distToCrossing) {}
86 
87  std::pair<MSVehicle*, SUMOReal> vehAndGap;
89  };
90 
91  typedef std::vector<LinkLeader> LinkLeaders;
92 
102  ApproachingVehicleInformation(const SUMOTime _arrivalTime, const SUMOTime _leavingTime,
103  const SUMOReal _arrivalSpeed, const SUMOReal _leaveSpeed,
104  const bool _willPass,
105  const SUMOTime _arrivalTimeBraking,
106  const SUMOReal _arrivalSpeedBraking,
107  const SUMOTime _waitingTime,
108  const SUMOReal _dist
109  ) :
110  arrivalTime(_arrivalTime), leavingTime(_leavingTime),
111  arrivalSpeed(_arrivalSpeed), leaveSpeed(_leaveSpeed),
112  willPass(_willPass),
113  arrivalTimeBraking(_arrivalTimeBraking),
114  arrivalSpeedBraking(_arrivalSpeedBraking),
115  waitingTime(_waitingTime),
116  dist(_dist) {
117  }
118 
128  const bool willPass;
136  const SUMOReal dist;
137 
138  private:
141 
142  };
143 
144 
145 #ifndef HAVE_INTERNAL_LANES
146 
154  MSLink(MSLane* succLane, LinkDirection dir, LinkState state, SUMOReal length, bool keepClear);
155 #else
156 
164  MSLink(MSLane* succLane, MSLane* via, LinkDirection dir, LinkState state, SUMOReal length, bool keepClear);
165 #endif
166 
167 
169  ~MSLink();
170 
171 
179  void setRequestInformation(int index, bool hasFoes, bool isCont,
180  const std::vector<MSLink*>& foeLinks, const std::vector<MSLane*>& foeLanes,
181  MSLane* internalLaneBefore = 0);
182 
183 
188  void setApproaching(const SUMOVehicle* approaching, const SUMOTime arrivalTime,
189  const SUMOReal arrivalSpeed, const SUMOReal leaveSpeed, const bool setRequest,
190  const SUMOTime arrivalTimeBraking, const SUMOReal arrivalSpeedBraking,
191  const SUMOTime waitingTime, SUMOReal dist);
192 
194  void removeApproaching(const SUMOVehicle* veh);
195 
196  void addBlockedLink(MSLink* link);
197 
198  /* @brief return information about this vehicle if it is registered as
199  * approaching (dummy values otherwise)
200  * @note used for visualisation of link items */
202 
204  const std::map<const SUMOVehicle*, ApproachingVehicleInformation>& getApproaching() const {
205  return myApproachingVehicles;
206  }
207 
215  bool opened(SUMOTime arrivalTime, SUMOReal arrivalSpeed, SUMOReal leaveSpeed, SUMOReal vehicleLength,
216  SUMOReal impatience, SUMOReal decel, SUMOTime waitingTime,
217  std::vector<const SUMOVehicle*>* collectFoes = 0) const;
218 
233  bool blockedAtTime(SUMOTime arrivalTime, SUMOTime leaveTime, SUMOReal arrivalSpeed, SUMOReal leaveSpeed,
234  bool sameTargetLane, SUMOReal impatience, SUMOReal decel, SUMOTime waitingTime,
235  std::vector<const SUMOVehicle*>* collectFoes = 0) const;
236 
237 
238  bool isBlockingAnyone() const {
239  return myApproachingVehicles.size() != 0;
240  }
241 
242  bool willHaveBlockedFoe() const;
243 
244 
245 
255  bool hasApproachingFoe(SUMOTime arrivalTime, SUMOTime leaveTime, SUMOReal speed, SUMOReal decel) const;
256 
257 
262  LinkState getState() const {
263  return myState;
264  }
265 
266 
267  //@brief Returns the time of the last state change
268  inline SUMOTime getLastStateChange() const {
269  return myLastStateChange;
270  }
271 
272 
277  LinkDirection getDirection() const;
278 
279 
285  void setTLState(LinkState state, SUMOTime t);
286 
287 
292  MSLane* getLane() const;
293 
294 
299  MSLane* getApproachingLane() const;
300 
301 
306  inline int getIndex() const {
307  return myIndex;
308  }
309 
310 
314  inline bool havePriority() const {
315  return myState >= 'A' && myState <= 'Z';
316  }
317 
321  inline bool haveRed() const {
323  }
324 
325  inline bool isTLSControlled() const {
327  }
328 
333  SUMOReal getLength() const {
334  return myLength;
335  }
336 
341  bool hasFoes() const {
342  return myHasFoes;
343  }
344 
345 
346  bool isCont() const {
347  return myAmCont;
348  }
349 
350 
352  bool keepClear() const {
353  return myKeepClear;
354  }
355 
357  bool lastWasContMajor() const;
358 
359 
360 #ifdef HAVE_INTERNAL_LANES
361 
365  MSLane* getViaLane() const;
366 
367 
375  LinkLeaders getLeaderInfo(SUMOReal dist, SUMOReal minGap, std::vector<const MSPerson*>* collectBlockers = 0) const;
376 #endif
377 
379  SUMOReal getZipperSpeed(const MSVehicle* ego, const SUMOReal dist, SUMOReal vSafe,
380  SUMOTime arrivalTime,
381  std::vector<const SUMOVehicle*>* collectFoes) const;
382 
384  MSLane* getViaLaneOrLane() const;
385 
387  const MSLane* getInternalLaneBefore() const;
388 
390  SUMOTime getLeaveTime(const SUMOTime arrivalTime, const SUMOReal arrivalSpeed, const SUMOReal leaveSpeed, const SUMOReal vehicleLength) const;
391 
393  void writeApproaching(OutputDevice& od, const std::string fromLaneID) const;
394 
396  void passedJunction(const MSVehicle* vehicle);
397 
399  bool isLeader(const MSVehicle* ego, const MSVehicle* foe);
400 
402  bool fromInternalLane() const;
403 
405  bool isExitLink() const;
406 
408  bool isInternalJunctionLink() const;
409 
412  return myMesoTLSPenalty;
413  }
414 
416  void setMesoTLSPenalty(const SUMOTime penalty) {
417  myMesoTLSPenalty = penalty;
418  }
419 
420 private:
422  static inline bool unsafeMergeSpeeds(SUMOReal leaderSpeed, SUMOReal followerSpeed, SUMOReal leaderDecel, SUMOReal followerDecel) {
423  // XXX mismatch between continuous an discrete deceleration
424  return (leaderSpeed * leaderSpeed / leaderDecel) <= (followerSpeed * followerSpeed / followerDecel);
425  }
426 
428  static bool maybeOccupied(MSLane* lane);
429 
431  static bool couldBrakeForLeader(SUMOReal followDist, SUMOReal leaderDist, const MSVehicle* follow, const MSVehicle* leader);
432 
433 private:
436 
437  std::map<const SUMOVehicle*, ApproachingVehicleInformation> myApproachingVehicles;
438  std::set<MSLink*> myBlockedFoeLinks;
439 
441  int myIndex;
442 
445 
448 
451 
454 
456  bool myHasFoes;
457 
458  bool myAmCont;
459 
461 
464 
465 #ifdef HAVE_INTERNAL_LANES
466  MSLane* const myJunctionInlane;
468 
470  const MSLane* myInternalLaneBefore;
471 
472  /* @brief lengths after the crossing point with foeLane
473  * (lengthOnThis, lengthOnFoe)
474  * (index corresponds to myFoeLanes)
475  * empty vector for entry links
476  * */
477  std::vector<std::pair<SUMOReal, SUMOReal> > myLengthsBehindCrossing;
478 #endif
479 
482 
483  std::vector<MSLink*> myFoeLinks;
484  std::vector<const MSLane*> myFoeLanes;
485 
486  static const SUMOTime myLookaheadTime;
488 
489 
490 private:
492  MSLink(const MSLink& s);
493 
495  MSLink& operator=(const MSLink& s);
496 
497 };
498 
499 
500 #endif
501 
502 /****************************************************************************/
503 
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:80
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)...
#define SUMOTime_MIN
Definition: SUMOTime.h:45
Representation of a vehicle.
Definition: SUMOVehicle.h:65
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)
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:77
The link has red light (must brake) but indicates upcoming green.