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-2015 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  struct LinkLeader {
80  LinkLeader(MSVehicle* _veh, SUMOReal _gap, SUMOReal _distToCrossing) :
81  vehAndGap(std::make_pair(_veh, _gap)),
82  distToCrossing(_distToCrossing) {}
83 
84  std::pair<MSVehicle*, SUMOReal> vehAndGap;
86  };
87 
88  typedef std::vector<LinkLeader> LinkLeaders;
89 
99  ApproachingVehicleInformation(const SUMOTime _arrivalTime, const SUMOTime _leavingTime,
100  const SUMOReal _arrivalSpeed, const SUMOReal _leaveSpeed,
101  const bool _willPass,
102  const SUMOTime _arrivalTimeBraking,
103  const SUMOReal _arrivalSpeedBraking,
104  const SUMOTime _waitingTime,
105  const SUMOReal _dist
106  ) :
107  arrivalTime(_arrivalTime), leavingTime(_leavingTime),
108  arrivalSpeed(_arrivalSpeed), leaveSpeed(_leaveSpeed),
109  willPass(_willPass),
110  arrivalTimeBraking(_arrivalTimeBraking),
111  arrivalSpeedBraking(_arrivalSpeedBraking),
112  waitingTime(_waitingTime),
113  dist(_dist)
114  {}
115 
125  const bool willPass;
133  const SUMOReal dist;
134 
135  private:
138 
139  };
140 
141 
142 #ifndef HAVE_INTERNAL_LANES
143 
151  MSLink(MSLane* succLane, LinkDirection dir, LinkState state, SUMOReal length, bool keepClear);
152 #else
153 
161  MSLink(MSLane* succLane, MSLane* via, LinkDirection dir, LinkState state, SUMOReal length, bool keepClear);
162 #endif
163 
164 
166  ~MSLink();
167 
168 
176  void setRequestInformation(int index, bool hasFoes, bool isCont,
177  const std::vector<MSLink*>& foeLinks, const std::vector<MSLane*>& foeLanes,
178  MSLane* internalLaneBefore = 0);
179 
180 
185  void setApproaching(const SUMOVehicle* approaching, const SUMOTime arrivalTime,
186  const SUMOReal arrivalSpeed, const SUMOReal leaveSpeed, const bool setRequest,
187  const SUMOTime arrivalTimeBraking, const SUMOReal arrivalSpeedBraking,
188  const SUMOTime waitingTime, SUMOReal dist);
189 
191  void removeApproaching(const SUMOVehicle* veh);
192 
193  void addBlockedLink(MSLink* link);
194 
195  /* @brief return information about this vehicle if it is registered as
196  * approaching (dummy values otherwise)
197  * @note used for visualisation of link items */
199 
207  bool opened(SUMOTime arrivalTime, SUMOReal arrivalSpeed, SUMOReal leaveSpeed, SUMOReal vehicleLength,
208  SUMOReal impatience, SUMOReal decel, SUMOTime waitingTime,
209  std::vector<const SUMOVehicle*>* collectFoes = 0) const;
210 
225  bool blockedAtTime(SUMOTime arrivalTime, SUMOTime leaveTime, SUMOReal arrivalSpeed, SUMOReal leaveSpeed,
226  bool sameTargetLane, SUMOReal impatience, SUMOReal decel, SUMOTime waitingTime,
227  std::vector<const SUMOVehicle*>* collectFoes = 0) const;
228 
229 
230  bool isBlockingAnyone() const {
231  return myApproachingVehicles.size() != 0;
232  }
233 
234  bool willHaveBlockedFoe() const;
235 
236 
237 
247  bool hasApproachingFoe(SUMOTime arrivalTime, SUMOTime leaveTime, SUMOReal speed, SUMOReal decel) const;
248 
249 
254  LinkState getState() const {
255  return myState;
256  }
257 
258 
259  //@brief Returns the time of the last state change
260  inline SUMOTime getLastStateChange() const {
261  return myLastStateChange;
262  }
263 
264 
269  LinkDirection getDirection() const;
270 
271 
277  void setTLState(LinkState state, SUMOTime t);
278 
279 
284  MSLane* getLane() const;
285 
286 
291  MSLane* getApproachingLane() const;
292 
293 
298  inline int getIndex() const {
299  return myIndex;
300  }
301 
302 
306  inline bool havePriority() const {
307  return myState >= 'A' && myState <= 'Z';
308  }
309 
313  inline bool haveRed() const {
315  }
316 
317 
322  SUMOReal getLength() const {
323  return myLength;
324  }
325 
330  bool hasFoes() const {
331  return myHasFoes;
332  }
333 
334 
335  bool isCont() const {
336  return myAmCont;
337  }
338 
339 
341  bool keepClear() const {
342  return myKeepClear;
343  }
344 
346  bool lastWasContMajor() const;
347 
348 
349 #ifdef HAVE_INTERNAL_LANES
350 
354  MSLane* getViaLane() const;
355 
356 
364  LinkLeaders getLeaderInfo(SUMOReal dist, SUMOReal minGap, std::vector<const MSPerson*>* collectBlockers = 0) const;
365 #endif
366 
368  SUMOReal getZipperSpeed(const MSVehicle* ego, const SUMOReal dist, SUMOReal vSafe,
369  SUMOTime arrivalTime,
370  std::vector<const SUMOVehicle*>* collectFoes) const;
371 
373  MSLane* getViaLaneOrLane() const;
374 
376  const MSLane* getInternalLaneBefore() const;
377 
379  SUMOTime getLeaveTime(const SUMOTime arrivalTime, const SUMOReal arrivalSpeed, const SUMOReal leaveSpeed, const SUMOReal vehicleLength) const;
380 
382  void writeApproaching(OutputDevice& od, const std::string fromLaneID) const;
383 
385  void passedJunction(const MSVehicle* vehicle);
386 
388  bool isLeader(const MSVehicle* ego, const MSVehicle* foe);
389 
390 private:
392  static inline bool unsafeMergeSpeeds(SUMOReal leaderSpeed, SUMOReal followerSpeed, SUMOReal leaderDecel, SUMOReal followerDecel) {
393  // XXX mismatch between continuous an discrete deceleration
394  return (leaderSpeed * leaderSpeed / leaderDecel) <= (followerSpeed * followerSpeed / followerDecel);
395  }
396 
398  static bool maybeOccupied(MSLane* lane);
399 
401  static bool couldBrakeForLeader(SUMOReal followDist, SUMOReal leaderDist, const MSVehicle* follow, const MSVehicle* leader);
402 
403 private:
406 
407  std::map<const SUMOVehicle*, ApproachingVehicleInformation> myApproachingVehicles;
408  std::set<MSLink*> myBlockedFoeLinks;
409 
411  int myIndex;
412 
415 
418 
421 
424 
426  bool myHasFoes;
427 
428  bool myAmCont;
429 
431 
432 #ifdef HAVE_INTERNAL_LANES
433  MSLane* const myJunctionInlane;
435 
437  const MSLane* myInternalLaneBefore;
438 
439  /* @brief lengths after the crossing point with foeLane
440  * (lengthOnThis, lengthOnFoe)
441  * (index corresponds to myFoeLanes)
442  * empty vector for entry links
443  * */
444  std::vector<std::pair<SUMOReal, SUMOReal> > myLengthsBehindCrossing;
445 #endif
446 
449 
450  std::vector<MSLink*> myFoeLinks;
451  std::vector<const MSLane*> myFoeLanes;
452 
453  static const SUMOTime myLookaheadTime;
455 
456 
457 private:
459  MSLink(const MSLink& s);
460 
462  MSLink& operator=(const MSLink& s);
463 
464 };
465 
466 
467 #endif
468 
469 /****************************************************************************/
470 
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:61
LinkDirection
The different directions a link between two lanes may take (or a stream between two edges)...
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:214
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
The link has red light (must brake) but indicates upcoming green.