SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 
146  MSLink(MSLane* succLane, LinkDirection dir, LinkState state, SUMOReal length, bool keepClear);
147 #else
148 
156  MSLink(MSLane* succLane, MSLane* via, LinkDirection dir, LinkState state, SUMOReal length, bool keepClear);
157 #endif
158 
159 
161  ~MSLink();
162 
163 
171  void setRequestInformation(int index, bool hasFoes, bool isCont,
172  const std::vector<MSLink*>& foeLinks, const std::vector<MSLane*>& foeLanes,
173  MSLane* internalLaneBefore = 0);
174 
175 
180  void setApproaching(const SUMOVehicle* approaching, const SUMOTime arrivalTime,
181  const SUMOReal arrivalSpeed, const SUMOReal leaveSpeed, const bool setRequest,
182  const SUMOTime arrivalTimeBraking, const SUMOReal arrivalSpeedBraking,
183  const SUMOTime waitingTime);
184 
186  void removeApproaching(const SUMOVehicle* veh);
187 
188  void addBlockedLink(MSLink* link);
189 
190  /* @brief return information about this vehicle if it is registered as
191  * approaching (dummy values otherwise)
192  * @note used for visualisation of link items */
194 
202  bool opened(SUMOTime arrivalTime, SUMOReal arrivalSpeed, SUMOReal leaveSpeed, SUMOReal vehicleLength,
203  SUMOReal impatience, SUMOReal decel, SUMOTime waitingTime,
204  std::vector<const SUMOVehicle*>* collectFoes = 0) const;
205 
220  bool blockedAtTime(SUMOTime arrivalTime, SUMOTime leaveTime, SUMOReal arrivalSpeed, SUMOReal leaveSpeed,
221  bool sameTargetLane, SUMOReal impatience, SUMOReal decel, SUMOTime waitingTime,
222  std::vector<const SUMOVehicle*>* collectFoes = 0) const;
223 
224 
225  bool isBlockingAnyone() const {
226  return myApproachingVehicles.size() != 0;
227  }
228 
229  bool willHaveBlockedFoe() const;
230 
231 
232 
242  bool hasApproachingFoe(SUMOTime arrivalTime, SUMOTime leaveTime, SUMOReal speed, SUMOReal decel) const;
243 
244 
249  LinkState getState() const {
250  return myState;
251  }
252 
253 
254  //@brief Returns the time of the last state change
255  inline SUMOTime getLastStateChange() const {
256  return myLastStateChange;
257  }
258 
259 
264  LinkDirection getDirection() const;
265 
266 
272  void setTLState(LinkState state, SUMOTime t);
273 
274 
279  MSLane* getLane() const;
280 
281 
286  MSLane* getApproachingLane() const;
287 
288 
293  inline int getIndex() const {
294  return myIndex;
295  }
296 
297 
301  inline bool havePriority() const {
302  return myState >= 'A' && myState <= 'Z';
303  }
304 
308  inline bool haveRed() const {
310  }
311 
312 
317  SUMOReal getLength() const {
318  return myLength;
319  }
320 
325  bool hasFoes() const {
326  return myHasFoes;
327  }
328 
329 
330  bool isCont() const {
331  return myAmCont;
332  }
333 
334 
336  bool keepClear() const {
337  return myKeepClear;
338  }
339 
341  bool lastWasContMajor() const;
342 
343 
344 #ifdef HAVE_INTERNAL_LANES
345 
349  MSLane* getViaLane() const;
350 
351 
359  LinkLeaders getLeaderInfo(SUMOReal dist, SUMOReal minGap, std::vector<const MSPerson*>* collectBlockers = 0) const;
360 #endif
361 
363  MSLane* getViaLaneOrLane() const;
364 
365 
367  SUMOTime getLeaveTime(const SUMOTime arrivalTime, const SUMOReal arrivalSpeed, const SUMOReal leaveSpeed, const SUMOReal vehicleLength) const;
368 
370  void writeApproaching(OutputDevice& od, const std::string fromLaneID) const;
371 
373  const MSJunction* getJunction() const {
374  return myJunction;
375  }
376 
377 private:
379  static inline bool unsafeMergeSpeeds(SUMOReal leaderSpeed, SUMOReal followerSpeed, SUMOReal leaderDecel, SUMOReal followerDecel) {
380  // XXX mismatch between continuous an discrete deceleration
381  return (leaderSpeed * leaderSpeed / leaderDecel) <= (followerSpeed * followerSpeed / followerDecel);
382  }
383 
385  static bool maybeOccupied(MSLane* lane);
386 
387 private:
390 
391  std::map<const SUMOVehicle*, ApproachingVehicleInformation> myApproachingVehicles;
392  std::set<MSLink*> myBlockedFoeLinks;
393 
395  int myIndex;
396 
399 
402 
405 
408 
410  bool myHasFoes;
411 
412  bool myAmCont;
413 
415 
416 #ifdef HAVE_INTERNAL_LANES
417  MSLane* const myJunctionInlane;
419 
421  const MSLane* myInternalLaneBefore;
422 
423  /* @brief lengths after the crossing point with foeLane
424  * (lengthOnThis, lengthOnFoe)
425  * (index corresponds to myFoeLanes)
426  * empty vector for entry links
427  * */
428  std::vector<std::pair<SUMOReal, SUMOReal> > myLengthsBehindCrossing;
429 #endif
430 
433 
434  std::vector<MSLink*> myFoeLinks;
435  std::vector<const MSLane*> myFoeLanes;
437 
438 
439 private:
441  MSLink(const MSLink& s);
442 
444  MSLink& operator=(const MSLink& s);
445 
446 };
447 
448 
449 #endif
450 
451 /****************************************************************************/
452 
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:215
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
The link has red light (must brake) but indicates upcoming green.