SUMO - Simulation of Urban MObility
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-2014 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 class MSJunction;
62 
63 
64 // ===========================================================================
65 // class definitions
66 // ===========================================================================
74 class MSEdge : public Named, public Parameterised {
75 public:
98  };
99 
100 
102  typedef std::map< const MSEdge*, std::vector<MSLane*>* > AllowedLanesCont;
103 
105  typedef std::map< SUMOVehicleClass, AllowedLanesCont > ClassedAllowedLanesCont;
106 
107 
108 public:
120  MSEdge(const std::string& id, int numericalID, const EdgeBasicFunction function, const std::string& streetName = "", const std::string& edgeType = "");
121 
122 
124  virtual ~MSEdge();
125 
126 
132  void initialize(std::vector<MSLane*>* lanes);
133 
134 
136  void closeBuilding();
137 
138 
141 
148  MSLane* leftLane(const MSLane* const lane) const;
149 
150 
157  MSLane* rightLane(const MSLane* const lane) const;
158 
159 
166  MSLane* parallelLane(const MSLane* const lane, int offset) const;
167 
168 
173  const std::vector<MSLane*>& getLanes() const {
174  return *myLanes;
175  }
176 
177 
182  std::vector<MSPerson*> getSortedPersons(SUMOTime timestep) const;
183 
192  const std::vector<MSLane*>* allowedLanes(const MSEdge& destination,
193  SUMOVehicleClass vclass = SVC_IGNORING) const;
194 
195 
203  const std::vector<MSLane*>* allowedLanes(SUMOVehicleClass vclass = SVC_IGNORING) const;
205 
206 
207 
210 
216  return myFunction;
217  }
218 
220  inline bool isInternal() const {
222  }
223 
225  inline bool isCrossing() const {
227  }
228 
230  inline bool isWalkingArea() const {
232  }
233 
237  int getNumericalID() const {
238  return myNumericalID;
239  }
240 
241 
244  const std::string& getStreetName() const {
245  return myStreetName;
246  }
247 
250  const std::string& getEdgeType() const {
251  return myEdgeType;
252  }
254 
255 
256 
259 
263  void addFollower(MSEdge* edge) {
264  mySuccessors.push_back(edge);
265  }
266 
267 
271  const std::vector<MSEdge*>& getIncomingEdges() const {
272  return myPredeccesors;
273  }
274 
275 
279  unsigned int getNoFollowing() const {
280  return (unsigned int) mySuccessors.size();
281  }
282 
283 
288  const MSEdge* getFollower(unsigned int n) const {
289  return mySuccessors[n];
290  }
291 
292 
293  const MSJunction* getFromJunction() const {
294  return myFromJunction;
295  }
296 
297  const MSJunction* getToJunction() const {
298  return myToJunction;
299  }
300 
301 
302  void setJunctions(MSJunction* from, MSJunction* to) {
303  myFromJunction = from;
304  myToJunction = to;
305  }
307 
308 
309 
312 
316  bool isVaporizing() const {
317  return myVaporizationRequests > 0;
318  }
319 
320 
331 
332 
344 
345 
354  SUMOReal getCurrentTravelTime(const SUMOReal minSpeed = 0.00001) const;
355 
356 
358  inline SUMOReal getMinimumTravelTime(const SUMOVehicle* const veh) const {
359  if (veh != 0) {
360  return getLength() / MIN2(veh->getMaxSpeed(), getVehicleMaxSpeed(veh));
361  } else {
362  return getLength() / getSpeedLimit();
363  }
364  }
365 
366 
369 
383  bool insertVehicle(SUMOVehicle& v, SUMOTime time) const;
384 
385 
400  MSLane* getFreeLane(const std::vector<MSLane*>* allowed, const SUMOVehicleClass vclass) const;
401 
402 
413  MSLane* getDepartLane(const MSVehicle& veh) const;
414 
415 
421  }
422 
423 
427  inline void setLastFailedInsertionTime(SUMOTime time) const {
429  }
431 
432 
434  virtual void changeLanes(SUMOTime t);
435 
436 
437 #ifdef HAVE_INTERNAL_LANES
438  const MSEdge* getInternalFollowingEdge(MSEdge* followerAfterInternal) const;
440 #endif
441 
443  inline bool prohibits(const SUMOVehicle* const vehicle) const {
444  if (vehicle == 0) {
445  return false;
446  }
447  const SUMOVehicleClass svc = vehicle->getVehicleType().getVehicleClass();
448  return (myCombinedPermissions & svc) != svc;
449  }
450 
451  void rebuildAllowedLanes();
452 
453 
458  SUMOReal getDistanceTo(const MSEdge* other) const;
459 
460 
464  SUMOReal getLength() const;
465 
466 
471  SUMOReal getSpeedLimit() const;
472 
473 
481  SUMOReal getVehicleMaxSpeed(const SUMOVehicle* const veh) const;
482 
483  virtual void addPerson(MSPerson* p) const {
484  myPersons.insert(p);
485  }
486 
487  virtual void removePerson(MSPerson* p) const {
488  std::set<MSPerson*>::iterator i = myPersons.find(p);
489  if (i != myPersons.end()) {
490  myPersons.erase(i);
491  }
492  }
493 
494  inline bool isRoundabout() const {
495  return myAmRoundabout;
496  }
497 
499  myAmRoundabout = true;
500  }
501 
503  bool laneChangeAllowed() const;
504 
508  static bool dictionary(const std::string& id, MSEdge* edge);
509 
511  static MSEdge* dictionary(const std::string& id);
512 
514  static MSEdge* dictionary(size_t index);
515 
517  static size_t dictSize();
518 
520  static size_t numericalDictSize();
521 
523  static void clear();
524 
526  static void insertIDs(std::vector<std::string>& into);
527 
528 
529 public:
532 
541  static void parseEdgesList(const std::string& desc, std::vector<const MSEdge*>& into,
542  const std::string& rid);
543 
544 
551  static void parseEdgesList(const std::vector<std::string>& desc, std::vector<const MSEdge*>& into,
552  const std::string& rid);
554 
555 
556 protected:
560  class by_id_sorter {
561  public:
563  explicit by_id_sorter() { }
564 
566  int operator()(const MSEdge* const e1, const MSEdge* const e2) const {
567  return e1->getID() < e2->getID();
568  }
569 
570  };
571 
576  public:
578  explicit person_by_offset_sorter(SUMOTime timestep): myTime(timestep) { }
579 
581  int operator()(const MSPerson* const p1, const MSPerson* const p2) const;
582  private:
584  };
585 
586 
595  const std::vector<MSLane*>* allowedLanes(const MSEdge* destination,
596  SUMOVehicleClass vclass = SVC_IGNORING) const;
597 
598 
600  const std::vector<MSLane*>* getAllowedLanesWithDefault(const AllowedLanesCont& c, const MSEdge* dest) const;
601 
602 protected:
605 
607  std::vector<MSLane*>* myLanes;
608 
611 
614 
617 
620 
622  std::vector<MSEdge*> mySuccessors;
623 
625  std::vector<MSEdge*> myPredeccesors;
626 
630 
632  mutable std::set<MSPerson*> myPersons;
633 
636 
638  AllowedLanesCont myAllowed;
639 
641  // @note: this map is filled on demand
642  mutable ClassedAllowedLanesCont myClassedAllowed;
643 
649 
651  std::string myStreetName;
652 
654  std::string myEdgeType;
655 
658 
661 
663  typedef std::map< std::string, MSEdge* > DictType;
664 
668  static DictType myDict;
669 
673  static std::vector<MSEdge*> myEdges;
675 
676 
677 
678 private:
680  MSEdge(const MSEdge&);
681 
683  MSEdge& operator=(const MSEdge&);
684 
685 };
686 
687 
688 #endif
689 
690 /****************************************************************************/
691 
std::set< MSPerson * > myPersons
Persons on the edge (only for drawing)
Definition: MSEdge.h:632
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:77
std::vector< MSLane * > * myLanes
Container for the edge's lane; should be sorted: (right-hand-traffic) the more left the lane...
Definition: MSEdge.h:607
static void insertIDs(std::vector< std::string > &into)
Inserts IDs of all known edges into the given vector.
Definition: MSEdge.cpp:528
SUMOVehicleClass getVehicleClass() const
Get this vehicle type's vehicle class.
Sorts edges by their ids.
Definition: MSEdge.h:560
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types...
SUMOReal getDistanceTo(const MSEdge *other) const
optimistic air distance heuristic for use in routing
Definition: MSEdge.cpp:566
static size_t numericalDictSize()
Returns the number of edges with a numerical id.
Definition: MSEdge.cpp:513
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition: MSEdge.h:173
std::vector< MSEdge * > mySuccessors
The succeeding edges.
Definition: MSEdge.h:622
The base class for an intersection.
Definition: MSJunction.h:58
const EdgeBasicFunction myFunction
the purpose of the edge
Definition: MSEdge.h:613
ClassedAllowedLanesCont myClassedAllowed
From vehicle class to lanes allowed to be used by it.
Definition: MSEdge.h:642
bool isWalkingArea() const
return whether this edge is walking area
Definition: MSEdge.h:230
void closeBuilding()
Definition: MSEdge.cpp:134
virtual ~MSEdge()
Destructor.
Definition: MSEdge.cpp:84
const std::string & getStreetName() const
Returns the street name of the edge.
Definition: MSEdge.h:244
The edge is a macroscopic connector (source/sink)
Definition: MSEdge.h:89
SUMOReal getCurrentTravelTime(const SUMOReal minSpeed=0.00001) const
Computes and returns the current travel time for this edge.
Definition: MSEdge.cpp:445
std::string myEdgeType
the type of the edge (optionally used during network creation)
Definition: MSEdge.h:654
static bool dictionary(const std::string &id, MSEdge *edge)
Inserts edge into the static dictionary Returns true if the key id isn't already in the dictionary...
Definition: MSEdge.cpp:473
SUMOTime incVaporization(SUMOTime t)
Enables vaporization.
Definition: MSEdge.cpp:282
MSLane * getFreeLane(const std::vector< MSLane * > *allowed, const SUMOVehicleClass vclass) const
Finds the emptiest lane allowing the vehicle class.
Definition: MSEdge.cpp:296
virtual SUMOReal getMaxSpeed() const =0
Returns the vehicle's maximum speed.
int myVaporizationRequests
Vaporizer counter.
Definition: MSEdge.h:616
EdgeBasicFunction
Defines possible edge types.
Definition: MSEdge.h:83
bool prohibits(const SUMOVehicle *const vehicle) const
Returns whether the vehicle (class) is not allowed on the edge.
Definition: MSEdge.h:443
SUMOTime decVaporization(SUMOTime t)
Disables vaporization.
Definition: MSEdge.cpp:289
The purpose of the edge is not known.
Definition: MSEdge.h:85
std::map< std::string, MSEdge * > DictType
definition of the static dictionary type
Definition: MSEdge.h:663
void initialize(std::vector< MSLane * > *lanes)
Initialize the edge.
Definition: MSEdge.cpp:100
static std::vector< MSEdge * > myEdges
Static list of edges.
Definition: MSEdge.h:673
MSEdge & operator=(const MSEdge &)
assignment operator.
Performs lane changing of vehicles.
Definition: MSLaneChanger.h:55
const std::string & getID() const
Returns the id.
Definition: Named.h:60
A road/street connecting two junctions.
Definition: MSEdge.h:74
static void parseEdgesList(const std::string &desc, std::vector< const MSEdge * > &into, const std::string &rid)
Parses the given string assuming it contains a list of edge ids divided by spaces.
Definition: MSEdge.cpp:536
SUMOTime myLastFailedInsertionTime
The time of last insertion failure.
Definition: MSEdge.h:619
void rebuildAllowedLanes()
Definition: MSEdge.cpp:173
Sorts edges by their ids.
Definition: MSEdge.h:575
SUMOReal getLength() const
return the length of the edge
Definition: MSEdge.cpp:576
The edge is a district edge.
Definition: MSEdge.h:93
Representation of a vehicle.
Definition: SUMOVehicle.h:64
AllowedLanesCont myAllowed
Associative container from destination-edge to allowed-lanes.
Definition: MSEdge.h:638
person_by_offset_sorter(SUMOTime timestep)
constructor
Definition: MSEdge.h:578
std::map< SUMOVehicleClass, AllowedLanesCont > ClassedAllowedLanesCont
Map from vehicle types to lanes that may be used to reach one of the next edges.
Definition: MSEdge.h:105
static void clear()
Clears the dictionary.
Definition: MSEdge.cpp:519
SVCPermissions myMinimumPermissions
The intersection of lane permissions for this edge.
Definition: MSEdge.h:645
unsigned int getNoFollowing() const
Returns the number of edges that may be reached from this edge.
Definition: MSEdge.h:279
MSLane * leftLane(const MSLane *const lane) const
Returns the lane left to the one given, 0 if the given lane is leftmost.
Definition: MSEdge.cpp:194
MSJunction * myToJunction
Definition: MSEdge.h:629
MSLaneChanger * myLaneChanger
This member will do the lane-change.
Definition: MSEdge.h:610
bool isRoundabout() const
Definition: MSEdge.h:494
bool isVaporizing() const
Returns whether vehicles on this edge shall be vaporized.
Definition: MSEdge.h:316
T MIN2(T a, T b)
Definition: StdDefs.h:66
std::vector< MSEdge * > myPredeccesors
The preceeding edges.
Definition: MSEdge.h:625
virtual void removePerson(MSPerson *p) const
Definition: MSEdge.h:487
int operator()(const MSPerson *const p1, const MSPerson *const p2) const
comparing operator
Definition: MSEdge.cpp:604
MSLane * getDepartLane(const MSVehicle &veh) const
Finds a depart lane for the given vehicle parameters.
Definition: MSEdge.cpp:315
virtual void addPerson(MSPerson *p) const
Definition: MSEdge.h:483
An upper class for objects with additional parameters.
Definition: Parameterised.h:47
SUMOReal getSpeedLimit() const
Returns the speed limit of the edge The speed limit of the first lane is retured; should probably be...
Definition: MSEdge.cpp:582
bool isInternal() const
return whether this edge is an internal edge
Definition: MSEdge.h:220
const std::string & getEdgeType() const
Returns the type of the edge.
Definition: MSEdge.h:250
Base class for objects which have an id.
Definition: Named.h:45
SVCPermissions myCombinedPermissions
The union of lane permissions for this edge.
Definition: MSEdge.h:647
The edge is a pedestrian walking area (a special type of internal edge)
Definition: MSEdge.h:97
EdgeBasicFunction getPurpose() const
Returns the edge type (EdgeBasicFunction)
Definition: MSEdge.h:215
const std::vector< MSEdge * > & getIncomingEdges() const
Returns the list of edges from which this edge may be reached.
Definition: MSEdge.h:271
Structure representing possible vehicle parameter.
int operator()(const MSEdge *const e1, const MSEdge *const e2) const
comparing operator
Definition: MSEdge.h:566
int getNumericalID() const
Returns the numerical id of the edge.
Definition: MSEdge.h:237
MSLane * parallelLane(const MSLane *const lane, int offset) const
Returns the lane with the given offset parallel to the given lane one or 0 if it does not exist...
Definition: MSEdge.cpp:206
virtual void changeLanes(SUMOTime t)
Performs lane changing on this edge.
Definition: MSEdge.cpp:413
The edge is a normal street.
Definition: MSEdge.h:87
const std::vector< MSLane * > * allowedLanes(const MSEdge &destination, SUMOVehicleClass vclass=SVC_IGNORING) const
Get the allowed lanes to reach the destination-edge.
Definition: MSEdge.cpp:221
bool myAmRoundabout
whether this edge belongs to a roundabout
Definition: MSEdge.h:657
The edge is a pedestrian crossing (a special type of internal edge)
Definition: MSEdge.h:95
void addFollower(MSEdge *edge)
Returns the list of edges which may be reached from this edge.
Definition: MSEdge.h:263
static size_t dictSize()
Returns the number of edges.
Definition: MSEdge.cpp:507
std::string myStreetName
the real-world name of this edge (need not be unique)
Definition: MSEdge.h:651
MSJunction * myFromJunction
the junctions for this edge
Definition: MSEdge.h:628
int SUMOTime
Definition: SUMOTime.h:43
SUMOTime getLastFailedInsertionTime() const
Returns the last time a vehicle could not be inserted.
Definition: MSEdge.h:419
void setJunctions(MSJunction *from, MSJunction *to)
Definition: MSEdge.h:302
by_id_sorter()
constructor
Definition: MSEdge.h:563
const MSEdge * getFollower(unsigned int n) const
Returns the n-th of the following edges.
Definition: MSEdge.h:288
std::map< const MSEdge *, std::vector< MSLane * > * > AllowedLanesCont
Suceeding edges (keys) and allowed lanes to reach these edges (values).
Definition: MSEdge.h:102
int myNumericalID
This edge's numerical id.
Definition: MSEdge.h:604
void setLastFailedInsertionTime(SUMOTime time) const
Sets the last time a vehicle could not be inserted.
Definition: MSEdge.h:427
static DictType myDict
Static dictionary to associate string-ids with objects.
Definition: MSEdge.h:668
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
#define SUMOReal
Definition: config.h:215
SUMOReal getMinimumTravelTime(const SUMOVehicle *const veh) const
returns the minimum travel time for the given vehicle
Definition: MSEdge.h:358
bool isCrossing() const
return whether this edge is a pedestrian crossing
Definition: MSEdge.h:225
const MSJunction * getFromJunction() const
Definition: MSEdge.h:293
bool laneChangeAllowed() const
whether lane changing may be performed on this edge
Definition: MSEdge.cpp:113
SUMOReal getVehicleMaxSpeed(const SUMOVehicle *const veh) const
Returns the maximum speed the vehicle may use on this edge.
Definition: MSEdge.cpp:589
MSLane * rightLane(const MSLane *const lane) const
Returns the lane right to the one given, 0 if the given lane is rightmost.
Definition: MSEdge.cpp:200
void markAsRoundabout()
Definition: MSEdge.h:498
bool insertVehicle(SUMOVehicle &v, SUMOTime time) const
Tries to insert the given vehicle into the network.
Definition: MSEdge.cpp:362
MSEdge(const std::string &id, int numericalID, const EdgeBasicFunction function, const std::string &streetName="", const std::string &edgeType="")
Constructor.
Definition: MSEdge.cpp:71
The edge is an internal edge.
Definition: MSEdge.h:91
const std::vector< MSLane * > * getAllowedLanesWithDefault(const AllowedLanesCont &c, const MSEdge *dest) const
lookup in map and return 0 if not found
Definition: MSEdge.cpp:233
std::vector< MSPerson * > getSortedPersons(SUMOTime timestep) const
Returns this edge's persons sorted by pos.
Definition: MSEdge.cpp:596
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
vehicles ignoring classes
const MSJunction * getToJunction() const
Definition: MSEdge.h:297
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle's type.