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.sourceforge.net/
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>
39 
40 
41 // ===========================================================================
42 // class declarations
43 // ===========================================================================
44 class MSLane;
45 class SUMOVehicle;
46 class MSVehicle;
47 
48 
49 // ===========================================================================
50 // class definitions
51 // ===========================================================================
72 class MSLink {
73 public:
79  ApproachingVehicleInformation(const SUMOTime _arrivalTime, const SUMOTime _leavingTime,
80  SUMOReal _arrivalSpeed, SUMOReal _leaveSpeed,
81  SUMOVehicle* _vehicle, const bool _willPass) :
82  arrivalTime(_arrivalTime), leavingTime(_leavingTime),
83  arrivalSpeed(_arrivalSpeed), leaveSpeed(_leaveSpeed),
84  vehicle(_vehicle), willPass(_willPass) {}
85 
97  bool willPass;
98  };
99 
100 
101 #ifndef HAVE_INTERNAL_LANES
102 
109  MSLink(MSLane* succLane, LinkDirection dir, LinkState state, SUMOReal length);
110 #else
111 
119  MSLink(MSLane* succLane, MSLane* via, LinkDirection dir, LinkState state, SUMOReal length);
120 #endif
121 
122 
124  ~MSLink();
125 
126 
134  void setRequestInformation(unsigned int requestIdx, unsigned int respondIdx, bool isCrossing, bool isCont,
135  const std::vector<MSLink*>& foeLinks, const std::vector<MSLane*>& foeLanes);
136 
137 
142  void setApproaching(SUMOVehicle* approaching, SUMOTime arrivalTime,
143  SUMOReal arrivalSpeed, SUMOReal leaveSpeed, bool setRequest);
144 
146  void removeApproaching(SUMOVehicle* veh);
147 
148  void addBlockedLink(MSLink* link);
149 
150  const std::vector<ApproachingVehicleInformation>& getApproaching() const {
151  return myApproachingVehicles;
152  }
153 
154  /* @brief return information about this vehicle if it is registered as
155  * approaching (dummy values otherwise)
156  * @note used for visualisation of link items */
157  ApproachingVehicleInformation getApproaching(const SUMOVehicle* veh) const;
158 
165  bool opened(SUMOTime arrivalTime, SUMOReal arrivalSpeed, SUMOReal leaveSpeed, SUMOReal vehicleLength) const;
166 
176  bool blockedAtTime(SUMOTime arrivalTime, SUMOTime leaveTime, SUMOReal arrivalSpeed, SUMOReal leaveSpeed,
177  bool sameTargetLane) const;
178 
179  bool isBlockingAnyone() const {
180  return myApproachingVehicles.size() != 0;
181  }
182 
183  bool willHaveBlockedFoe() const;
184 
185 
186 
195  bool hasApproachingFoe(SUMOTime arrivalTime, SUMOTime leaveTime, SUMOReal speed) const;
196 
197 
202  LinkState getState() const {
203  return myState;
204  }
205 
206 
211  LinkDirection getDirection() const;
212 
213 
218  void setTLState(LinkState state, SUMOTime t);
219 
220 
225  MSLane* getLane() const;
226 
227 
232  unsigned int getRespondIndex() const;
233 
234 
238  bool havePriority() const {
239  return myState >= 'A' && myState <= 'Z';
240  }
241 
242 
247  SUMOReal getLength() const {
248  return myLength;
249  }
250 
255  bool isCrossing() const {
256  return myIsCrossing;
257  }
258 
259 
260  bool isCont() const {
261  return myAmCont;
262  }
263 
264 #ifdef HAVE_INTERNAL_LANES
265 
269  MSLane* getViaLane() const;
270 
271 
279  std::pair<MSVehicle*, SUMOReal> getLeaderInfo(const std::map<const MSLink*, std::string>& previousLeaders, SUMOReal dist) const;
280 #endif
281 
283  MSLane* getViaLaneOrLane() const;
284 
285 
287  SUMOTime getLeaveTime(SUMOTime arrivalTime, SUMOReal arrivalSpeed, SUMOReal leaveSpeed, SUMOReal vehicleLength) const;
288 
289 
290 
291 
292 private:
293  typedef std::vector<ApproachingVehicleInformation> LinkApproachingVehicles;
294 
296  public:
297  explicit vehicle_in_request_finder(const SUMOVehicle* const v) : myVehicle(v) { }
299  return vo.vehicle == myVehicle;
300  }
301  private:
302  vehicle_in_request_finder& operator=(const vehicle_in_request_finder&); // just to avoid a compiler warning
303  private:
304  const SUMOVehicle* const myVehicle;
305 
306  };
307 
309  static SUMOTime unsafeHeadwayTime(SUMOTime headwayTime, SUMOReal leaderSpeed, SUMOReal followerSpeed);
310 
312  static bool maybeOccupied(MSLane* lane);
313 
314 private:
317 
319  std::set<MSLink*> myBlockedFoeLinks;
320 
322  unsigned int myRequestIdx;
323 
325  unsigned int myRespondIdx;
326 
329 
332 
335 
338 
339  bool myAmCont;
340 
341 #ifdef HAVE_INTERNAL_LANES
342 
343  MSLane* const myJunctionInlane;
344 
345 #endif
346 
347  std::vector<MSLink*> myFoeLinks;
348  std::vector<MSLane*> myFoeLanes;
350 
351 
352 private:
354  MSLink(const MSLink& s);
355 
357  MSLink& operator=(const MSLink& s);
358 
359 };
360 
361 
362 #endif
363 
364 /****************************************************************************/
365