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-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 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 
257  LinkDirection getDirection() const;
258 
259 
264  void setTLState(LinkState state, SUMOTime t);
265 
266 
271  MSLane* getLane() const;
272 
273 
278  inline int getIndex() const {
279  return myIndex;
280  }
281 
282 
286  inline bool havePriority() const {
287  return myState >= 'A' && myState <= 'Z';
288  }
289 
293  inline bool haveRed() const {
295  }
296 
297 
302  SUMOReal getLength() const {
303  return myLength;
304  }
305 
310  bool hasFoes() const {
311  return myHasFoes;
312  }
313 
314 
315  bool isCont() const {
316  return myAmCont;
317  }
318 
319 
321  bool lastWasContMajor() const;
322 
323 
324 #ifdef HAVE_INTERNAL_LANES
325 
329  MSLane* getViaLane() const;
330 
331 
339  LinkLeaders getLeaderInfo(SUMOReal dist, SUMOReal minGap, std::vector<const MSPerson*>* collectBlockers = 0) const;
340 #endif
341 
343  MSLane* getViaLaneOrLane() const;
344 
345 
347  SUMOTime getLeaveTime(const SUMOTime arrivalTime, const SUMOReal arrivalSpeed, const SUMOReal leaveSpeed, const SUMOReal vehicleLength) const;
348 
350  void writeApproaching(OutputDevice& od, const std::string fromLaneID) const;
351 
353  const MSJunction* getJunction() const {
354  return myJunction;
355  }
356 
357 private:
359  static inline bool unsafeMergeSpeeds(SUMOReal leaderSpeed, SUMOReal followerSpeed, SUMOReal leaderDecel, SUMOReal followerDecel) {
360  // XXX mismatch between continuous an discrete deceleration
361  return (leaderSpeed * leaderSpeed / leaderDecel) <= (followerSpeed * followerSpeed / followerDecel);
362  }
363 
365  static bool maybeOccupied(MSLane* lane);
366 
367 private:
370 
371  std::map<const SUMOVehicle*, ApproachingVehicleInformation> myApproachingVehicles;
372  std::set<MSLink*> myBlockedFoeLinks;
373 
375  int myIndex;
376 
379 
382 
385 
387  bool myHasFoes;
388 
389  bool myAmCont;
390 
391 #ifdef HAVE_INTERNAL_LANES
392  MSLane* const myJunctionInlane;
394 
395  /* @brief lengths after the crossing point with foeLane
396  * (lengthOnThis, lengthOnFoe)
397  * (index corresponds to myFoeLanes)
398  * empty vector for entry links
399  * */
400  std::vector<std::pair<SUMOReal, SUMOReal> > myLengthsBehindCrossing;
401 #endif
402 
405 
406  std::vector<MSLink*> myFoeLinks;
407  std::vector<MSLane*> myFoeLanes;
409 
410 
411 private:
413  MSLink(const MSLink& s);
414 
416  MSLink& operator=(const MSLink& s);
417 
418 };
419 
420 
421 #endif
422 
423 /****************************************************************************/
424 
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:78
The base class for an intersection.
Definition: MSJunction.h:59
LinkDirection
The different directions a link between two lanes may take (or a stream between two edges)...
Representation of a vehicle.
Definition: SUMOVehicle.h:64
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.