SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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  ) :
106  arrivalTime(_arrivalTime), leavingTime(_leavingTime),
107  arrivalSpeed(_arrivalSpeed), leaveSpeed(_leaveSpeed),
108  willPass(_willPass),
109  arrivalTimeBraking(_arrivalTimeBraking),
110  arrivalSpeedBraking(_arrivalSpeedBraking),
111  waitingTime(_waitingTime) {}
112 
122  const bool willPass;
129 
130  private:
133 
134  };
135 
136 
137 #ifndef HAVE_INTERNAL_LANES
138 
145  MSLink(MSLane* succLane, LinkDirection dir, LinkState state, SUMOReal length);
146 #else
147 
155  MSLink(MSLane* succLane, MSLane* via, LinkDirection dir, LinkState state, SUMOReal length);
156 #endif
157 
158 
160  ~MSLink();
161 
162 
170  void setRequestInformation(int index, bool hasFoes, bool isCont,
171  const std::vector<MSLink*>& foeLinks, const std::vector<MSLane*>& foeLanes,
172  MSLane* internalLaneBefore = 0);
173 
174 
179  void setApproaching(const SUMOVehicle* approaching, const SUMOTime arrivalTime,
180  const SUMOReal arrivalSpeed, const SUMOReal leaveSpeed, const bool setRequest,
181  const SUMOTime arrivalTimeBraking, const SUMOReal arrivalSpeedBraking,
182  const SUMOTime waitingTime);
183 
185  void removeApproaching(const SUMOVehicle* veh);
186 
187  void addBlockedLink(MSLink* link);
188 
189  /* @brief return information about this vehicle if it is registered as
190  * approaching (dummy values otherwise)
191  * @note used for visualisation of link items */
193 
201  bool opened(SUMOTime arrivalTime, SUMOReal arrivalSpeed, SUMOReal leaveSpeed, SUMOReal vehicleLength,
202  SUMOReal impatience, SUMOReal decel, SUMOTime waitingTime,
203  std::vector<const SUMOVehicle*>* collectFoes = 0) const;
204 
219  bool blockedAtTime(SUMOTime arrivalTime, SUMOTime leaveTime, SUMOReal arrivalSpeed, SUMOReal leaveSpeed,
220  bool sameTargetLane, SUMOReal impatience, SUMOReal decel, SUMOTime waitingTime,
221  std::vector<const SUMOVehicle*>* collectFoes = 0) const;
222 
223 
224  bool isBlockingAnyone() const {
225  return myApproachingVehicles.size() != 0;
226  }
227 
228  bool willHaveBlockedFoe() const;
229 
230 
231 
241  bool hasApproachingFoe(SUMOTime arrivalTime, SUMOTime leaveTime, SUMOReal speed, SUMOReal decel) const;
242 
243 
248  LinkState getState() const {
249  return myState;
250  }
251 
252 
253  //@brief Returns the time of the last state change
254  inline SUMOTime getLastStateChange() const {
255  return myLastStateChange;
256  }
257 
258 
263  LinkDirection getDirection() const;
264 
265 
271  void setTLState(LinkState state, SUMOTime t);
272 
273 
278  MSLane* getLane() const;
279 
280 
285  MSLane* getApproachingLane() const;
286 
287 
292  inline int getIndex() const {
293  return myIndex;
294  }
295 
296 
300  inline bool havePriority() const {
301  return myState >= 'A' && myState <= 'Z';
302  }
303 
307  inline bool haveRed() const {
309  }
310 
311 
316  SUMOReal getLength() const {
317  return myLength;
318  }
319 
324  bool hasFoes() const {
325  return myHasFoes;
326  }
327 
328 
329  bool isCont() const {
330  return myAmCont;
331  }
332 
333 
335  bool lastWasContMajor() const;
336 
337 
338 #ifdef HAVE_INTERNAL_LANES
339 
343  MSLane* getViaLane() const;
344 
345 
353  LinkLeaders getLeaderInfo(SUMOReal dist, SUMOReal minGap, std::vector<const MSPerson*>* collectBlockers = 0) const;
354 #endif
355 
357  MSLane* getViaLaneOrLane() const;
358 
359 
361  SUMOTime getLeaveTime(const SUMOTime arrivalTime, const SUMOReal arrivalSpeed, const SUMOReal leaveSpeed, const SUMOReal vehicleLength) const;
362 
364  void writeApproaching(OutputDevice& od, const std::string fromLaneID) const;
365 
367  const MSJunction* getJunction() const {
368  return myJunction;
369  }
370 
371 private:
373  static inline bool unsafeMergeSpeeds(SUMOReal leaderSpeed, SUMOReal followerSpeed, SUMOReal leaderDecel, SUMOReal followerDecel) {
374  // XXX mismatch between continuous an discrete deceleration
375  return (leaderSpeed * leaderSpeed / leaderDecel) <= (followerSpeed * followerSpeed / followerDecel);
376  }
377 
379  static bool maybeOccupied(MSLane* lane);
380 
381 private:
384 
385  std::map<const SUMOVehicle*, ApproachingVehicleInformation> myApproachingVehicles;
386  std::set<MSLink*> myBlockedFoeLinks;
387 
389  int myIndex;
390 
393 
396 
399 
402 
404  bool myHasFoes;
405 
406  bool myAmCont;
407 
408 #ifdef HAVE_INTERNAL_LANES
409  MSLane* const myJunctionInlane;
411 
413  const MSLane* myInternalLaneBefore;
414 
415  /* @brief lengths after the crossing point with foeLane
416  * (lengthOnThis, lengthOnFoe)
417  * (index corresponds to myFoeLanes)
418  * empty vector for entry links
419  * */
420  std::vector<std::pair<SUMOReal, SUMOReal> > myLengthsBehindCrossing;
421 #endif
422 
425 
426  std::vector<MSLink*> myFoeLinks;
427  std::vector<const MSLane*> myFoeLanes;
429 
430 
431 private:
433  MSLink(const MSLink& s);
434 
436  MSLink& operator=(const MSLink& s);
437 
438 };
439 
440 
441 #endif
442 
443 /****************************************************************************/
444 
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:80
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)
int SUMOTime
Definition: SUMOTime.h:43
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
#define SUMOReal
Definition: config.h:218
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
The link has red light (must brake) but indicates upcoming green.