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-sim.org/
12 // Copyright (C) 2001-2014 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 SUMOVehicle;
47 class MSVehicle;
48 class MSPerson;
50 
51 
52 // ===========================================================================
53 // class definitions
54 // ===========================================================================
75 class MSLink {
76 public:
77 
78  struct LinkLeader {
79  LinkLeader(MSVehicle* _veh, SUMOReal _gap, SUMOReal _distToCrossing) :
80  vehAndGap(std::make_pair(_veh, _gap)),
81  distToCrossing(_distToCrossing) {}
82 
83  std::pair<MSVehicle*, SUMOReal> vehAndGap;
85  };
86 
87  typedef std::vector<LinkLeader> LinkLeaders;
88 
98  ApproachingVehicleInformation(const SUMOTime _arrivalTime, const SUMOTime _leavingTime,
99  const SUMOReal _arrivalSpeed, const SUMOReal _leaveSpeed,
100  const bool _willPass,
101  const SUMOTime _arrivalTimeBraking,
102  const SUMOReal _arrivalSpeedBraking,
103  const SUMOTime _waitingTime
104  ) :
105  arrivalTime(_arrivalTime), leavingTime(_leavingTime),
106  arrivalSpeed(_arrivalSpeed), leaveSpeed(_leaveSpeed),
107  willPass(_willPass),
108  arrivalTimeBraking(_arrivalTimeBraking),
109  arrivalSpeedBraking(_arrivalSpeedBraking),
110  waitingTime(_waitingTime) {}
111 
121  const bool willPass;
128 
129  private:
132 
133  };
134 
135 
136 #ifndef HAVE_INTERNAL_LANES
137 
144  MSLink(MSLane* succLane, LinkDirection dir, LinkState state, SUMOReal length);
145 #else
146 
154  MSLink(MSLane* succLane, MSLane* via, LinkDirection dir, LinkState state, SUMOReal length);
155 #endif
156 
157 
159  ~MSLink();
160 
161 
169  void setRequestInformation(int index, bool hasFoes, bool isCont,
170  const std::vector<MSLink*>& foeLinks, const std::vector<MSLane*>& foeLanes,
171  MSLane* internalLaneBefore = 0);
172 
173 
178  void setApproaching(const SUMOVehicle* approaching, const SUMOTime arrivalTime,
179  const SUMOReal arrivalSpeed, const SUMOReal leaveSpeed, const bool setRequest,
180  const SUMOTime arrivalTimeBraking, const SUMOReal arrivalSpeedBraking,
181  const SUMOTime waitingTime);
182 
184  void removeApproaching(const SUMOVehicle* veh);
185 
186  void addBlockedLink(MSLink* link);
187 
188  /* @brief return information about this vehicle if it is registered as
189  * approaching (dummy values otherwise)
190  * @note used for visualisation of link items */
192 
200  bool opened(SUMOTime arrivalTime, SUMOReal arrivalSpeed, SUMOReal leaveSpeed, SUMOReal vehicleLength,
201  SUMOReal impatience, SUMOReal decel, SUMOTime waitingTime,
202  std::vector<const SUMOVehicle*>* collectFoes = 0) const;
203 
218  bool blockedAtTime(SUMOTime arrivalTime, SUMOTime leaveTime, SUMOReal arrivalSpeed, SUMOReal leaveSpeed,
219  bool sameTargetLane, SUMOReal impatience, SUMOReal decel, SUMOTime waitingTime,
220  std::vector<const SUMOVehicle*>* collectFoes = 0) const;
221 
222 
223  bool isBlockingAnyone() const {
224  return myApproachingVehicles.size() != 0;
225  }
226 
227  bool willHaveBlockedFoe() const;
228 
229 
230 
240  bool hasApproachingFoe(SUMOTime arrivalTime, SUMOTime leaveTime, SUMOReal speed, SUMOReal decel) const;
241 
242 
247  LinkState getState() const {
248  return myState;
249  }
250 
251 
256  LinkDirection getDirection() const;
257 
258 
263  void setTLState(LinkState state, SUMOTime t);
264 
265 
270  MSLane* getLane() const;
271 
272 
277  inline int getIndex() const {
278  return myIndex;
279  }
280 
281 
285  bool havePriority() const {
286  return myState >= 'A' && myState <= 'Z';
287  }
288 
289 
294  SUMOReal getLength() const {
295  return myLength;
296  }
297 
302  bool hasFoes() const {
303  return myHasFoes;
304  }
305 
306 
307  bool isCont() const {
308  return myAmCont;
309  }
310 
311 
313  bool lastWasContMajor() const;
314 
315 
316 #ifdef HAVE_INTERNAL_LANES
317 
321  MSLane* getViaLane() const;
322 
323 
331  LinkLeaders getLeaderInfo(SUMOReal dist, SUMOReal minGap, std::vector<const MSPerson*>* collectBlockers = 0) const;
332 #endif
333 
335  MSLane* getViaLaneOrLane() const;
336 
337 
339  SUMOTime getLeaveTime(const SUMOTime arrivalTime, const SUMOReal arrivalSpeed, const SUMOReal leaveSpeed, const SUMOReal vehicleLength) const;
340 
342  void writeApproaching(OutputDevice& od, const std::string fromLaneID) const;
343 
344 
345 private:
347  static inline bool unsafeMergeSpeeds(SUMOReal leaderSpeed, SUMOReal followerSpeed, SUMOReal leaderDecel, SUMOReal followerDecel) {
348  // XXX mismatch between continuous an discrete deceleration
349  return (leaderSpeed * leaderSpeed / leaderDecel) <= (followerSpeed * followerSpeed / followerDecel);
350  }
351 
353  static bool maybeOccupied(MSLane* lane);
354 
355 private:
358 
359  std::map<const SUMOVehicle*, ApproachingVehicleInformation> myApproachingVehicles;
360  std::set<MSLink*> myBlockedFoeLinks;
361 
363  int myIndex;
364 
367 
370 
373 
375  bool myHasFoes;
376 
377  bool myAmCont;
378 
379 #ifdef HAVE_INTERNAL_LANES
380 
381  MSLane* const myJunctionInlane;
382 
383  /* @brief lengths after the crossing point with foeLane
384  * (lengthOnThis, lengthOnFoe)
385  * (index corresponds to myFoeLanes)
386  * empty vector for entry links
387  * */
388  std::vector<std::pair<SUMOReal, SUMOReal> > myLengthsBehindCrossing;
389 #endif
390 
391  std::vector<MSLink*> myFoeLinks;
392  std::vector<MSLane*> myFoeLanes;
394 
395 
396 private:
398  MSLink(const MSLink& s);
399 
401  MSLink& operator=(const MSLink& s);
402 
403 };
404 
405 
406 #endif
407 
408 /****************************************************************************/
409