SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MSEdge.h
Go to the documentation of this file.
1 /****************************************************************************/
11 // A road/street connecting two junctions
12 /****************************************************************************/
13 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
14 // Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
15 /****************************************************************************/
16 //
17 // This file is part of SUMO.
18 // SUMO is free software: you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation, either version 3 of the License, or
21 // (at your option) any later version.
22 //
23 /****************************************************************************/
24 #ifndef MSEdge_h
25 #define MSEdge_h
26 
27 
28 // ===========================================================================
29 // included modules
30 // ===========================================================================
31 #ifdef _MSC_VER
32 #include <windows_config.h>
33 #else
34 #include <config.h>
35 #endif
36 
37 #include <vector>
38 #include <map>
39 #include <string>
40 #include <iostream>
41 #include <utils/common/Named.h>
43 #include <utils/common/SUMOTime.h>
48 #include "MSVehicleType.h"
49 
50 
51 // ===========================================================================
52 // class declarations
53 // ===========================================================================
54 class MSLaneChanger;
55 class OutputDevice;
56 class SUMOVehicle;
58 class MSVehicle;
59 class MSLane;
60 class MSPerson;
61 
62 
63 // ===========================================================================
64 // class definitions
65 // ===========================================================================
73 class MSEdge : public Named, public Parameterised {
74 public:
93  };
94 
95 
97  typedef std::map< const MSEdge*, std::vector<MSLane*>* > AllowedLanesCont;
98 
100  typedef std::map< SUMOVehicleClass, AllowedLanesCont > ClassedAllowedLanesCont;
101 
102 
103 public:
115  MSEdge(const std::string& id, int numericalID, const EdgeBasicFunction function, const std::string& streetName = "");
116 
117 
119  virtual ~MSEdge();
120 
121 
127  void initialize(std::vector<MSLane*>* lanes);
128 
129 
131  void closeBuilding();
132 
133 
136 
143  MSLane* leftLane(const MSLane* const lane) const;
144 
145 
152  MSLane* rightLane(const MSLane* const lane) const;
153 
154 
159  const std::vector<MSLane*>& getLanes() const {
160  return *myLanes;
161  }
162 
163 
172  const std::vector<MSLane*>* allowedLanes(const MSEdge& destination,
173  SUMOVehicleClass vclass = SVC_UNKNOWN) const;
174 
175 
183  const std::vector<MSLane*>* allowedLanes(SUMOVehicleClass vclass = SVC_UNKNOWN) const;
185 
186 
187 
190 
196  return myFunction;
197  }
198 
199 
203  int getNumericalID() const {
204  return myNumericalID;
205  }
206 
207 
210  const std::string& getStreetName() const {
211  return myStreetName;
212  }
214 
215 
216 
219 
223  void addFollower(MSEdge* edge) {
224  mySuccessors.push_back(edge);
225  }
226 
227 
231  const std::vector<MSEdge*>& getIncomingEdges() const {
232  return myPredeccesors;
233  }
234 
235 
239  unsigned int getNoFollowing() const {
240  return (unsigned int) mySuccessors.size();
241  }
242 
247  const MSEdge* getFollower(unsigned int n) const {
248  return mySuccessors[n];
249  }
251 
252 
253 
256 
260  bool isVaporizing() const {
261  return myVaporizationRequests > 0;
262  }
263 
264 
275 
276 
288 
289 
298  SUMOReal getCurrentTravelTime(const SUMOReal minSpeed = 0.00001) const;
299 
300 
302  inline SUMOReal getMinimumTravelTime(const SUMOVehicle* const veh) const {
303  if (veh != 0) {
304  return getLength() / MIN2(veh->getMaxSpeed(), getVehicleMaxSpeed(veh));
305  } else {
306  return getLength() / getSpeedLimit();
307  }
308  }
309 
310 
313 
327  bool insertVehicle(SUMOVehicle& v, SUMOTime time) const;
328 
329 
344  MSLane* getFreeLane(const std::vector<MSLane*>* allowed, const SUMOVehicleClass vclass) const;
345 
346 
357  MSLane* getDepartLane(const MSVehicle& veh) const;
358 
359 
365  }
366 
367 
371  inline void setLastFailedInsertionTime(SUMOTime time) const {
373  }
375 
376 
378  virtual void changeLanes(SUMOTime t);
379 
380 
381 #ifdef HAVE_INTERNAL_LANES
382 
383  const MSEdge* getInternalFollowingEdge(MSEdge* followerAfterInternal) const;
384 #endif
385 
387  inline bool prohibits(const SUMOVehicle* const vehicle) const {
388  if (vehicle == 0) {
389  return false;
390  }
391  const SUMOVehicleClass svc = vehicle->getVehicleType().getVehicleClass();
392  return (myCombinedPermissions & svc) != svc;
393  }
394 
395  void rebuildAllowedLanes();
396 
397 
402  SUMOReal getDistanceTo(const MSEdge* other) const;
403 
404 
408  SUMOReal getLength() const;
409 
410 
415  SUMOReal getSpeedLimit() const;
416 
417 
425  SUMOReal getVehicleMaxSpeed(const SUMOVehicle* const veh) const;
426 
427  virtual void addPerson(MSPerson* p) const {
428  myPersons.insert(p);
429  }
430 
431  virtual void removePerson(MSPerson* p) const {
432  std::set<MSPerson*>::iterator i = myPersons.find(p);
433  if (i != myPersons.end()) {
434  myPersons.erase(i);
435  }
436  }
437 
438 
442  static bool dictionary(const std::string& id, MSEdge* edge);
443 
445  static MSEdge* dictionary(const std::string& id);
446 
448  static MSEdge* dictionary(size_t index);
449 
451  static size_t dictSize();
452 
454  static size_t numericalDictSize();
455 
457  static void clear();
458 
460  static void insertIDs(std::vector<std::string>& into);
461 
462 
463 public:
466 
475  static void parseEdgesList(const std::string& desc, std::vector<const MSEdge*>& into,
476  const std::string& rid);
477 
478 
485  static void parseEdgesList(const std::vector<std::string>& desc, std::vector<const MSEdge*>& into,
486  const std::string& rid);
488 
489 
490 protected:
494  class by_id_sorter {
495  public:
497  explicit by_id_sorter() { }
498 
500  int operator()(const MSEdge* const e1, const MSEdge* const e2) const {
501  return e1->getID() < e2->getID();
502  }
503 
504  };
505 
506 
515  const std::vector<MSLane*>* allowedLanes(const MSEdge* destination,
516  SUMOVehicleClass vclass = SVC_UNKNOWN) const;
517 
518 
520  const std::vector<MSLane*>* getAllowedLanesWithDefault(const AllowedLanesCont& c, const MSEdge* dest) const;
521 
522 protected:
525 
527  std::vector<MSLane*>* myLanes;
528 
531 
534 
537 
540 
542  std::vector<MSEdge*> mySuccessors;
543 
545  std::vector<MSEdge*> myPredeccesors;
546 
548  mutable std::set<MSPerson*> myPersons;
549 
552 
555 
557  // @note: this map is filled on demand
559 
564 
565  std::string myStreetName;
567 
568 
569 
572 
574  typedef std::map< std::string, MSEdge* > DictType;
575 
579  static DictType myDict;
580 
584  static std::vector<MSEdge*> myEdges;
586 
587 
588 
589 private:
591  MSEdge(const MSEdge&);
592 
594  MSEdge& operator=(const MSEdge&);
595 
596 };
597 
598 
599 #endif
600 
601 /****************************************************************************/
602