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 
162 
167  void setApproaching(const SUMOVehicle* approaching, const SUMOTime arrivalTime,
168  const SUMOReal arrivalSpeed, const SUMOReal leaveSpeed, const bool setRequest,
169  const SUMOTime arrivalTimeBraking, const SUMOReal arrivalSpeedBraking,
170  const SUMOTime waitingTime);
171 
173  void removeApproaching(const SUMOVehicle* veh);
174 
175  void addBlockedLink(MSLink* link);
176 
177  /* @brief return information about this vehicle if it is registered as
178  * approaching (dummy values otherwise)
179  * @note used for visualisation of link items */
181 
189  bool opened(SUMOTime arrivalTime, SUMOReal arrivalSpeed, SUMOReal leaveSpeed, SUMOReal vehicleLength,
190  SUMOReal impatience, SUMOReal decel, SUMOTime waitingTime,
191  std::vector<const SUMOVehicle*>* collectFoes = 0) const;
192 
207  bool blockedAtTime(SUMOTime arrivalTime, SUMOTime leaveTime, SUMOReal arrivalSpeed, SUMOReal leaveSpeed,
208  bool sameTargetLane, SUMOReal impatience, SUMOReal decel, SUMOTime waitingTime,
209  std::vector<const SUMOVehicle*>* collectFoes = 0) const;
210 
211 
212  bool isBlockingAnyone() const {
213  return myApproachingVehicles.size() != 0;
214  }
215 
216  bool willHaveBlockedFoe() const;
217 
218 
219 
229  bool hasApproachingFoe(SUMOTime arrivalTime, SUMOTime leaveTime, SUMOReal speed,
230  SUMOReal decel = DEFAULT_VEH_DECEL) const;
231 
232 
237  LinkState getState() const {
238  return myState;
239  }
240 
241 
246  LinkDirection getDirection() const;
247 
248 
253  void setTLState(LinkState state, SUMOTime t);
254 
255 
260  MSLane* getLane() const;
261 
262 
267  unsigned int getRespondIndex() const;
268 
269 
273  bool havePriority() const {
274  return myState >= 'A' && myState <= 'Z';
275  }
276 
277 
282  SUMOReal getLength() const {
283  return myLength;
284  }
285 
290  bool isCrossing() const {
291  return myIsCrossing;
292  }
293 
294 
295  bool isCont() const {
296  return myAmCont;
297  }
298 
299 #ifdef HAVE_INTERNAL_LANES
300 
304  MSLane* getViaLane() const;
305 
306 
312  LinkLeaders getLeaderInfo(SUMOReal dist) const;
313 #endif
314 
316  MSLane* getViaLaneOrLane() const;
317 
318 
320  SUMOTime getLeaveTime(SUMOTime arrivalTime, SUMOReal arrivalSpeed, SUMOReal leaveSpeed, SUMOReal vehicleLength) const;
321 
323  void writeApproaching(OutputDevice& od, const std::string fromLaneID) const;
324 
325 
326 private:
328  static inline bool unsafeMergeSpeeds(SUMOReal leaderSpeed, SUMOReal followerSpeed, SUMOReal leaderDecel, SUMOReal followerDecel) {
329  // XXX mismatch between continuous an discrete deceleration
330  return (leaderSpeed * leaderSpeed / leaderDecel) <= (followerSpeed * followerSpeed / followerDecel);
331  }
332 
334  static bool maybeOccupied(MSLane* lane);
335 
336 private:
339 
340  std::map<const SUMOVehicle*, ApproachingVehicleInformation> myApproachingVehicles;
341  std::set<MSLink*> myBlockedFoeLinks;
342 
344  unsigned int myRequestIdx;
345 
347  unsigned int myRespondIdx;
348 
351 
354 
357 
360 
361  bool myAmCont;
362 
363 #ifdef HAVE_INTERNAL_LANES
364  MSLane* const myJunctionInlane;
366 
367 #endif
368 
369  std::vector<MSLink*> myFoeLinks;
370  std::vector<MSLane*> myFoeLanes;
372 
373 
374 private:
376  MSLink(const MSLink& s);
377 
379  MSLink& operator=(const MSLink& s);
380 
381 };
382 
383 
384 #endif
385 
386 /****************************************************************************/
387