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-2013 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<MSVehicle*, 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 requestIdx, unsigned int respondIdx, 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  unsigned int getRespondIndex() const;
269 
270 
274  bool havePriority() const {
275  return myState >= 'A' && myState <= 'Z';
276  }
277 
278 
283  SUMOReal getLength() const {
284  return myLength;
285  }
286 
291  bool isCrossing() const {
292  return myIsCrossing;
293  }
294 
295 
296  bool isCont() const {
297  return myAmCont;
298  }
299 
300 #ifdef HAVE_INTERNAL_LANES
301 
305  MSLane* getViaLane() const;
306 
307 
314  LinkLeaders getLeaderInfo(SUMOReal dist, SUMOReal minGap) const;
315 #endif
316 
318  MSLane* getViaLaneOrLane() const;
319 
320 
322  SUMOTime getLeaveTime(SUMOTime arrivalTime, SUMOReal arrivalSpeed, SUMOReal leaveSpeed, SUMOReal vehicleLength) const;
323 
325  void writeApproaching(OutputDevice& od, const std::string fromLaneID) const;
326 
327 
328 private:
330  static inline bool unsafeMergeSpeeds(SUMOReal leaderSpeed, SUMOReal followerSpeed, SUMOReal leaderDecel, SUMOReal followerDecel) {
331  // XXX mismatch between continuous an discrete deceleration
332  return (leaderSpeed * leaderSpeed / leaderDecel) <= (followerSpeed * followerSpeed / followerDecel);
333  }
334 
336  static bool maybeOccupied(MSLane* lane);
337 
338 private:
341 
342  std::map<const SUMOVehicle*, ApproachingVehicleInformation> myApproachingVehicles;
343  std::set<MSLink*> myBlockedFoeLinks;
344 
346  unsigned int myRequestIdx;
347 
349  unsigned int myRespondIdx;
350 
353 
356 
359 
362 
363  bool myAmCont;
364 
365 #ifdef HAVE_INTERNAL_LANES
366  MSLane* const myJunctionInlane;
368 
369  /* @brief lengths after the crossing point with foeLane
370  * (lengthOnThis, lengthOnFoe)
371  * (index corresponds to myFoeLanes)
372  * empty vector for entry links
373  * */
374  std::vector<std::pair<SUMOReal, SUMOReal> > myLengthsBehindCrossing;
375 #endif
376 
377  std::vector<MSLink*> myFoeLinks;
378  std::vector<MSLane*> myFoeLanes;
380 
381 
382 private:
384  MSLink(const MSLink& s);
385 
387  MSLink& operator=(const MSLink& s);
388 
389 };
390 
391 
392 #endif
393 
394 /****************************************************************************/
395 
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