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-sim.org/
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 
161  MSLane* parallelLane(const MSLane* const lane, int offset) const;
162 
163 
168  const std::vector<MSLane*>& getLanes() const {
169  return *myLanes;
170  }
171 
172 
181  const std::vector<MSLane*>* allowedLanes(const MSEdge& destination,
182  SUMOVehicleClass vclass = SVC_UNKNOWN) const;
183 
184 
192  const std::vector<MSLane*>* allowedLanes(SUMOVehicleClass vclass = SVC_UNKNOWN) const;
194 
195 
196 
199 
205  return myFunction;
206  }
207 
208 
212  int getNumericalID() const {
213  return myNumericalID;
214  }
215 
216 
219  const std::string& getStreetName() const {
220  return myStreetName;
221  }
223 
224 
225 
228 
232  void addFollower(MSEdge* edge) {
233  mySuccessors.push_back(edge);
234  }
235 
236 
240  const std::vector<MSEdge*>& getIncomingEdges() const {
241  return myPredeccesors;
242  }
243 
244 
248  unsigned int getNoFollowing() const {
249  return (unsigned int) mySuccessors.size();
250  }
251 
252 
257  const MSEdge* getFollower(unsigned int n) const {
258  return mySuccessors[n];
259  }
261 
262 
263 
266 
270  bool isVaporizing() const {
271  return myVaporizationRequests > 0;
272  }
273 
274 
285 
286 
298 
299 
308  SUMOReal getCurrentTravelTime(const SUMOReal minSpeed = 0.00001) const;
309 
310 
312  inline SUMOReal getMinimumTravelTime(const SUMOVehicle* const veh) const {
313  if (veh != 0) {
314  return getLength() / MIN2(veh->getMaxSpeed(), getVehicleMaxSpeed(veh));
315  } else {
316  return getLength() / getSpeedLimit();
317  }
318  }
319 
320 
323 
337  bool insertVehicle(SUMOVehicle& v, SUMOTime time) const;
338 
339 
354  MSLane* getFreeLane(const std::vector<MSLane*>* allowed, const SUMOVehicleClass vclass) const;
355 
356 
367  MSLane* getDepartLane(const MSVehicle& veh) const;
368 
369 
375  }
376 
377 
381  inline void setLastFailedInsertionTime(SUMOTime time) const {
383  }
385 
386 
388  virtual void changeLanes(SUMOTime t);
389 
390 
391 #ifdef HAVE_INTERNAL_LANES
392 
393  const MSEdge* getInternalFollowingEdge(MSEdge* followerAfterInternal) const;
394 #endif
395 
397  inline bool prohibits(const SUMOVehicle* const vehicle) const {
398  if (vehicle == 0) {
399  return false;
400  }
401  const SUMOVehicleClass svc = vehicle->getVehicleType().getVehicleClass();
402  return (myCombinedPermissions & svc) != svc;
403  }
404 
405  void rebuildAllowedLanes();
406 
407 
412  SUMOReal getDistanceTo(const MSEdge* other) const;
413 
414 
418  SUMOReal getLength() const;
419 
420 
425  SUMOReal getSpeedLimit() const;
426 
427 
435  SUMOReal getVehicleMaxSpeed(const SUMOVehicle* const veh) const;
436 
437  virtual void addPerson(MSPerson* p) const {
438  myPersons.insert(p);
439  }
440 
441  virtual void removePerson(MSPerson* p) const {
442  std::set<MSPerson*>::iterator i = myPersons.find(p);
443  if (i != myPersons.end()) {
444  myPersons.erase(i);
445  }
446  }
447 
448  inline bool isRoundabout() const {
449  return myAmRoundabout;
450  }
451 
453  myAmRoundabout = true;
454  }
455 
457  bool laneChangeAllowed() const;
458 
462  static bool dictionary(const std::string& id, MSEdge* edge);
463 
465  static MSEdge* dictionary(const std::string& id);
466 
468  static MSEdge* dictionary(size_t index);
469 
471  static size_t dictSize();
472 
474  static size_t numericalDictSize();
475 
477  static void clear();
478 
480  static void insertIDs(std::vector<std::string>& into);
481 
482 
483 public:
486 
495  static void parseEdgesList(const std::string& desc, std::vector<const MSEdge*>& into,
496  const std::string& rid);
497 
498 
505  static void parseEdgesList(const std::vector<std::string>& desc, std::vector<const MSEdge*>& into,
506  const std::string& rid);
508 
509 
510 protected:
514  class by_id_sorter {
515  public:
517  explicit by_id_sorter() { }
518 
520  int operator()(const MSEdge* const e1, const MSEdge* const e2) const {
521  return e1->getID() < e2->getID();
522  }
523 
524  };
525 
526 
535  const std::vector<MSLane*>* allowedLanes(const MSEdge* destination,
536  SUMOVehicleClass vclass = SVC_UNKNOWN) const;
537 
538 
540  const std::vector<MSLane*>* getAllowedLanesWithDefault(const AllowedLanesCont& c, const MSEdge* dest) const;
541 
542 protected:
545 
547  std::vector<MSLane*>* myLanes;
548 
551 
554 
557 
560 
562  std::vector<MSEdge*> mySuccessors;
563 
565  std::vector<MSEdge*> myPredeccesors;
566 
568  mutable std::set<MSPerson*> myPersons;
569 
572 
575 
577  // @note: this map is filled on demand
579 
585 
587  std::string myStreetName;
588 
591 
594 
596  typedef std::map< std::string, MSEdge* > DictType;
597 
601  static DictType myDict;
602 
606  static std::vector<MSEdge*> myEdges;
608 
609 
610 
611 private:
613  MSEdge(const MSEdge&);
614 
616  MSEdge& operator=(const MSEdge&);
617 
618 };
619 
620 
621 #endif
622 
623 /****************************************************************************/
624