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;
49 
50 
51 // ===========================================================================
52 // class definitions
53 // ===========================================================================
74 class MSLink {
75 public:
76 
77  typedef std::vector<std::pair<std::pair<MSVehicle*, SUMOReal>, SUMOReal> > LinkLeaders;
78 
88  ApproachingVehicleInformation(const SUMOTime _arrivalTime, const SUMOTime _leavingTime,
89  const SUMOReal _arrivalSpeed, const SUMOReal _leaveSpeed,
90  const bool _willPass,
91  const SUMOTime _arrivalTimeBraking,
92  const SUMOReal _arrivalSpeedBraking,
93  const SUMOTime _waitingTime
94  ) :
95  arrivalTime(_arrivalTime), leavingTime(_leavingTime),
96  arrivalSpeed(_arrivalSpeed), leaveSpeed(_leaveSpeed),
97  willPass(_willPass),
98  arrivalTimeBraking(_arrivalTimeBraking),
99  arrivalSpeedBraking(_arrivalSpeedBraking),
100  waitingTime(_waitingTime) {}
101 
111  const bool willPass;
118 
119  private:
122 
123  };
124 
125 
126 #ifndef HAVE_INTERNAL_LANES
127 
134  MSLink(MSLane* succLane, LinkDirection dir, LinkState state, SUMOReal length);
135 #else
136 
144  MSLink(MSLane* succLane, MSLane* via, LinkDirection dir, LinkState state, SUMOReal length);
145 #endif
146 
147 
149  ~MSLink();
150 
151 
159  void setRequestInformation(unsigned int index, bool isCrossing, bool isCont,
160  const std::vector<MSLink*>& foeLinks, const std::vector<MSLane*>& foeLanes,
161  MSLane* internalLaneBefore = 0);
162 
163 
168  void setApproaching(const SUMOVehicle* approaching, const SUMOTime arrivalTime,
169  const SUMOReal arrivalSpeed, const SUMOReal leaveSpeed, const bool setRequest,
170  const SUMOTime arrivalTimeBraking, const SUMOReal arrivalSpeedBraking,
171  const SUMOTime waitingTime);
172 
174  void removeApproaching(const SUMOVehicle* veh);
175 
176  void addBlockedLink(MSLink* link);
177 
178  /* @brief return information about this vehicle if it is registered as
179  * approaching (dummy values otherwise)
180  * @note used for visualisation of link items */
182 
190  bool opened(SUMOTime arrivalTime, SUMOReal arrivalSpeed, SUMOReal leaveSpeed, SUMOReal vehicleLength,
191  SUMOReal impatience, SUMOReal decel, SUMOTime waitingTime,
192  std::vector<const SUMOVehicle*>* collectFoes = 0) const;
193 
208  bool blockedAtTime(SUMOTime arrivalTime, SUMOTime leaveTime, SUMOReal arrivalSpeed, SUMOReal leaveSpeed,
209  bool sameTargetLane, SUMOReal impatience, SUMOReal decel, SUMOTime waitingTime,
210  std::vector<const SUMOVehicle*>* collectFoes = 0) const;
211 
212 
213  bool isBlockingAnyone() const {
214  return myApproachingVehicles.size() != 0;
215  }
216 
217  bool willHaveBlockedFoe() const;
218 
219 
220 
230  bool hasApproachingFoe(SUMOTime arrivalTime, SUMOTime leaveTime, SUMOReal speed,
231  SUMOReal decel = DEFAULT_VEH_DECEL) const;
232 
233 
238  LinkState getState() const {
239  return myState;
240  }
241 
242 
247  LinkDirection getDirection() const;
248 
249 
254  void setTLState(LinkState state, SUMOTime t);
255 
256 
261  MSLane* getLane() const;
262 
263 
268  inline unsigned int getIndex() const {
269  return myIndex;
270  }
271 
272 
276  bool havePriority() const {
277  return myState >= 'A' && myState <= 'Z';
278  }
279 
280 
285  SUMOReal getLength() const {
286  return myLength;
287  }
288 
293  bool isCrossing() const {
294  return myIsCrossing;
295  }
296 
297 
298  bool isCont() const {
299  return myAmCont;
300  }
301 
302 
304  bool lastWasContMajor() const;
305 
306 
307 #ifdef HAVE_INTERNAL_LANES
308 
312  MSLane* getViaLane() const;
313 
314 
321  LinkLeaders getLeaderInfo(SUMOReal dist, SUMOReal minGap) const;
322 #endif
323 
325  MSLane* getViaLaneOrLane() const;
326 
327 
329  SUMOTime getLeaveTime(SUMOTime arrivalTime, SUMOReal arrivalSpeed, SUMOReal leaveSpeed, SUMOReal vehicleLength) const;
330 
332  void writeApproaching(OutputDevice& od, const std::string fromLaneID) const;
333 
334 
335 private:
337  static inline bool unsafeMergeSpeeds(SUMOReal leaderSpeed, SUMOReal followerSpeed, SUMOReal leaderDecel, SUMOReal followerDecel) {
338  // XXX mismatch between continuous an discrete deceleration
339  return (leaderSpeed * leaderSpeed / leaderDecel) <= (followerSpeed * followerSpeed / followerDecel);
340  }
341 
343  static bool maybeOccupied(MSLane* lane);
344 
345 private:
348 
349  std::map<const SUMOVehicle*, ApproachingVehicleInformation> myApproachingVehicles;
350  std::set<MSLink*> myBlockedFoeLinks;
351 
353  unsigned int myIndex;
354 
357 
360 
363 
366 
367  bool myAmCont;
368 
369 #ifdef HAVE_INTERNAL_LANES
370  MSLane* const myJunctionInlane;
372 
373  /* @brief lengths after the crossing point with foeLane
374  * (lengthOnThis, lengthOnFoe)
375  * (index corresponds to myFoeLanes)
376  * empty vector for entry links
377  * */
378  std::vector<std::pair<SUMOReal, SUMOReal> > myLengthsBehindCrossing;
379 #endif
380 
381  std::vector<MSLink*> myFoeLinks;
382  std::vector<MSLane*> myFoeLanes;
384 
385 
386 private:
388  MSLink(const MSLink& s);
389 
391  MSLink& operator=(const MSLink& s);
392 
393 };
394 
395 
396 #endif
397 
398 /****************************************************************************/
399 
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:77
LinkDirection
The different directions a link between two lanes may take (or a stream between two edges)...
Representation of a vehicle.
Definition: SUMOVehicle.h:63
LinkState
The right-of-way state of a link between two lanes used when constructing a NBTrafficLightLogic, in MSLink and GNEInternalLane.
int SUMOTime
Definition: SUMOTime.h:43
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
#define SUMOReal
Definition: config.h:215
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
const SUMOReal DEFAULT_VEH_DECEL