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.dlr.de/
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 "MSNet.h"
49 #include "MSVehicleType.h"
50 
51 
52 // ===========================================================================
53 // class declarations
54 // ===========================================================================
55 class MSLaneChanger;
56 class OutputDevice;
57 class SUMOVehicle;
59 class MSVehicle;
60 class MSLane;
61 class MSPerson;
62 class MSJunction;
63 
64 
65 // ===========================================================================
66 // class definitions
67 // ===========================================================================
75 class MSEdge : public Named, public Parameterised {
76 public:
99  };
100 
101 
103  typedef std::map< const MSEdge*, std::vector<MSLane*>* > AllowedLanesCont;
104 
106  typedef std::map< SUMOVehicleClass, AllowedLanesCont > ClassedAllowedLanesCont;
107 
108 
109 public:
121  MSEdge(const std::string& id, int numericalID, const EdgeBasicFunction function,
122  const std::string& streetName, const std::string& edgeType, int priority);
123 
124 
126  virtual ~MSEdge();
127 
128 
134  void initialize(const std::vector<MSLane*>* lanes);
135 
136 
139  void recalcCache();
140 
141 
143  void closeBuilding();
144 
145 
148 
155  MSLane* leftLane(const MSLane* const lane) const;
156 
157 
164  MSLane* rightLane(const MSLane* const lane) const;
165 
166 
173  MSLane* parallelLane(const MSLane* const lane, int offset) const;
174 
175 
180  const std::vector<MSLane*>& getLanes() const {
181  return *myLanes;
182  }
183 
184 
189  std::vector<MSPerson*> getSortedPersons(SUMOTime timestep) const;
190 
199  const std::vector<MSLane*>* allowedLanes(const MSEdge& destination,
200  SUMOVehicleClass vclass = SVC_IGNORING) const;
201 
202 
210  const std::vector<MSLane*>* allowedLanes(SUMOVehicleClass vclass = SVC_IGNORING) const;
212 
213 
214 
217 
223  return myFunction;
224  }
225 
227  inline bool isInternal() const {
229  }
230 
232  inline bool isCrossing() const {
234  }
235 
237  inline bool isWalkingArea() const {
239  }
240 
244  inline int getNumericalID() const {
245  return myNumericalID;
246  }
247 
248 
251  const std::string& getStreetName() const {
252  return myStreetName;
253  }
254 
257  const std::string& getEdgeType() const {
258  return myEdgeType;
259  }
260 
263  int getPriority() const {
264  return myPriority;
265  }
267 
268 
269 
272 
276  void addSuccessor(MSEdge* edge) {
277  mySuccessors.push_back(edge);
278  }
279 
280 
284  const std::vector<MSEdge*>& getIncomingEdges() const {
285  return myPredecessors;
286  }
287 
288 
292  unsigned int getNumSuccessors() const {
293  return (unsigned int) mySuccessors.size();
294  }
295 
296 
301  const MSEdge* getSuccessor(unsigned int n) const {
302  return mySuccessors[n];
303  }
304 
305 
310  unsigned int getNumPredecessors() const {
311  return (unsigned int) myPredecessors.size();
312  }
313 
314 
319  MSEdge* getPredecessor(unsigned int pos) const {
320  return myPredecessors[pos];
321  }
322 
323 
324  const MSJunction* getFromJunction() const {
325  return myFromJunction;
326  }
327 
328  const MSJunction* getToJunction() const {
329  return myToJunction;
330  }
331 
332 
333  void setJunctions(MSJunction* from, MSJunction* to) {
334  myFromJunction = from;
335  myToJunction = to;
336  }
338 
339 
340 
343 
347  bool isVaporizing() const {
348  return myVaporizationRequests > 0;
349  }
350 
351 
362 
363 
375 
376 
385  SUMOReal getCurrentTravelTime(const SUMOReal minSpeed = NUMERICAL_EPS) const;
386 
387 
389  inline SUMOReal getMinimumTravelTime(const SUMOVehicle* const veh) const {
390  if (veh != 0) {
391  return getLength() / MIN2(veh->getMaxSpeed(), getVehicleMaxSpeed(veh));
392  } else {
393  return getLength() / getSpeedLimit();
394  }
395  }
396 
397 
405  static inline SUMOReal getTravelTimeStatic(const MSEdge* const edge, const SUMOVehicle* const veh, SUMOReal time) {
406  return MSNet::getInstance()->getTravelTime(edge, veh, time);
407  }
408 
409 
412 
429  bool insertVehicle(SUMOVehicle& v, SUMOTime time, const bool checkOnly = false) const;
430 
431 
446  MSLane* getFreeLane(const std::vector<MSLane*>* allowed, const SUMOVehicleClass vclass) const;
447 
448 
459  MSLane* getDepartLane(MSVehicle& veh) const;
460 
461 
467  }
468 
469 
473  inline void setLastFailedInsertionTime(SUMOTime time) const {
475  }
477 
478 
480  virtual void changeLanes(SUMOTime t);
481 
482 
483 #ifdef HAVE_INTERNAL_LANES
484  const MSEdge* getInternalFollowingEdge(MSEdge* followerAfterInternal) const;
486 #endif
487 
489  inline bool prohibits(const SUMOVehicle* const vehicle) const {
490  if (vehicle == 0) {
491  return false;
492  }
493  const SUMOVehicleClass svc = vehicle->getVehicleType().getVehicleClass();
494  return (myCombinedPermissions & svc) != svc;
495  }
496 
498  return myCombinedPermissions;
499  }
500 
501  void rebuildAllowedLanes();
502 
503 
508  SUMOReal getDistanceTo(const MSEdge* other) const;
509 
510 
514  inline SUMOReal getLength() const {
515  return myLength;
516  }
517 
518 
523  SUMOReal getSpeedLimit() const;
524 
525 
533  SUMOReal getVehicleMaxSpeed(const SUMOVehicle* const veh) const;
534 
535  virtual void addPerson(MSPerson* p) const {
536  myPersons.insert(p);
537  }
538 
539  virtual void removePerson(MSPerson* p) const {
540  std::set<MSPerson*>::iterator i = myPersons.find(p);
541  if (i != myPersons.end()) {
542  myPersons.erase(i);
543  }
544  }
545 
546  inline bool isRoundabout() const {
547  return myAmRoundabout;
548  }
549 
551  myAmRoundabout = true;
552  }
553 
554  void markDelayed() const {
555  myAmDelayed = true;
556  }
557 
561  static bool dictionary(const std::string& id, MSEdge* edge);
562 
564  static MSEdge* dictionary(const std::string& id);
565 
567  static MSEdge* dictionary(size_t index);
568 
570  static size_t dictSize();
571 
573  static size_t numericalDictSize();
574 
576  static void clear();
577 
579  static void insertIDs(std::vector<std::string>& into);
580 
581 
582 public:
585 
594  static void parseEdgesList(const std::string& desc, std::vector<const MSEdge*>& into,
595  const std::string& rid);
596 
597 
604  static void parseEdgesList(const std::vector<std::string>& desc, std::vector<const MSEdge*>& into,
605  const std::string& rid);
607 
608 
609 protected:
613  class by_id_sorter {
614  public:
616  explicit by_id_sorter() { }
617 
619  int operator()(const MSEdge* const e1, const MSEdge* const e2) const {
620  return e1->getID() < e2->getID();
621  }
622 
623  };
624 
629  public:
631  explicit person_by_offset_sorter(SUMOTime timestep): myTime(timestep) { }
632 
634  int operator()(const MSPerson* const p1, const MSPerson* const p2) const;
635  private:
637  };
638 
639 
648  const std::vector<MSLane*>* allowedLanes(const MSEdge* destination,
649  SUMOVehicleClass vclass = SVC_IGNORING) const;
650 
651 
653  const std::vector<MSLane*>* getAllowedLanesWithDefault(const AllowedLanesCont& c, const MSEdge* dest) const;
654 
655 protected:
657  const int myNumericalID;
658 
660  const std::vector<MSLane*>* myLanes;
661 
664 
667 
670 
673 
675  std::vector<MSEdge*> mySuccessors;
676 
678  std::vector<MSEdge*> myPredecessors;
679 
683 
685  mutable std::set<MSPerson*> myPersons;
686 
689 
692 
694  // @note: this map is filled on demand
696 
702 
704  std::string myStreetName;
705 
707  std::string myEdgeType;
708 
710  const int myPriority;
711 
714 
717 
719  mutable bool myAmDelayed;
720 
723 
726 
728  typedef std::map< std::string, MSEdge* > DictType;
729 
733  static DictType myDict;
734 
738  static std::vector<MSEdge*> myEdges;
740 
741 
742 
743 private:
745  MSEdge(const MSEdge&);
746 
748  MSEdge& operator=(const MSEdge&);
749 
750 };
751 
752 
753 #endif
754 
755 /****************************************************************************/
756 
bool myAmDelayed
whether this edge had a vehicle with less than max speed on it
Definition: MSEdge.h:719
std::set< MSPerson * > myPersons
Persons on the edge (only for drawing)
Definition: MSEdge.h:685
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:78
static void insertIDs(std::vector< std::string > &into)
Inserts IDs of all known edges into the given vector.
Definition: MSEdge.cpp:578
SUMOReal myLength
the length of the edge (cached value for speedup)
Definition: MSEdge.h:713
SUMOVehicleClass getVehicleClass() const
Get this vehicle type&#39;s vehicle class.
Sorts edges by their ids.
Definition: MSEdge.h:613
void addSuccessor(MSEdge *edge)
Returns the list of edges which may be reached from this edge.
Definition: MSEdge.h:276
bool insertVehicle(SUMOVehicle &v, SUMOTime time, const bool checkOnly=false) const
Tries to insert the given vehicle into the network.
Definition: MSEdge.cpp:365
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:616
static size_t numericalDictSize()
Returns the number of edges with a numerical id.
Definition: MSEdge.cpp:563
void initialize(const std::vector< MSLane * > *lanes)
Initialize the edge.
Definition: MSEdge.cpp:106
const std::vector< MSLane * > & getLanes() const
Returns this edge&#39;s lanes.
Definition: MSEdge.h:180
unsigned int getNumPredecessors() const
Returns the number of edges this edge is connected to.
Definition: MSEdge.h:310
std::vector< MSEdge * > mySuccessors
The succeeding edges.
Definition: MSEdge.h:675
void recalcCache()
Recalculates the cached values.
Definition: MSEdge.cpp:121
The base class for an intersection.
Definition: MSJunction.h:59
const EdgeBasicFunction myFunction
the purpose of the edge
Definition: MSEdge.h:666
int SVCPermissions
ClassedAllowedLanesCont myClassedAllowed
From vehicle class to lanes allowed to be used by it.
Definition: MSEdge.h:695
bool isWalkingArea() const
return whether this edge is walking area
Definition: MSEdge.h:237
void closeBuilding()
Definition: MSEdge.cpp:128
virtual ~MSEdge()
Destructor.
Definition: MSEdge.cpp:90
const std::string & getStreetName() const
Returns the street name of the edge.
Definition: MSEdge.h:251
The edge is a macroscopic connector (source/sink)
Definition: MSEdge.h:90
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:156
std::string myEdgeType
the type of the edge (optionally used during network creation)
Definition: MSEdge.h:707
SVCPermissions getPermissions() const
Definition: MSEdge.h:497
static bool dictionary(const std::string &id, MSEdge *edge)
Inserts edge into the static dictionary Returns true if the key id isn&#39;t already in the dictionary...
Definition: MSEdge.cpp:523
const int myNumericalID
This edge&#39;s numerical id.
Definition: MSEdge.h:657
SUMOTime incVaporization(SUMOTime t)
Enables vaporization.
Definition: MSEdge.cpp:276
MSLane * getFreeLane(const std::vector< MSLane * > *allowed, const SUMOVehicleClass vclass) const
Finds the emptiest lane allowing the vehicle class.
Definition: MSEdge.cpp:290
virtual SUMOReal getMaxSpeed() const =0
Returns the vehicle&#39;s maximum speed.
int myVaporizationRequests
Vaporizer counter.
Definition: MSEdge.h:669
EdgeBasicFunction
Defines possible edge types.
Definition: MSEdge.h:84
bool prohibits(const SUMOVehicle *const vehicle) const
Returns whether the vehicle (class) is not allowed on the edge.
Definition: MSEdge.h:489
const MSEdge * getSuccessor(unsigned int n) const
Returns the n-th of the following edges.
Definition: MSEdge.h:301
SUMOTime decVaporization(SUMOTime t)
Disables vaporization.
Definition: MSEdge.cpp:283
The purpose of the edge is not known.
Definition: MSEdge.h:86
std::vector< MSEdge * > myPredecessors
The preceeding edges.
Definition: MSEdge.h:678
std::map< std::string, MSEdge * > DictType
definition of the static dictionary type
Definition: MSEdge.h:728
static std::vector< MSEdge * > myEdges
Static list of edges.
Definition: MSEdge.h:738
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:75
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:586
SUMOTime myLastFailedInsertionTime
The time of last insertion failure.
Definition: MSEdge.h:672
void rebuildAllowedLanes()
Definition: MSEdge.cpp:167
Sorts edges by their ids.
Definition: MSEdge.h:628
SUMOReal getLength() const
return the length of the edge
Definition: MSEdge.h:514
The edge is a district edge.
Definition: MSEdge.h:94
Representation of a vehicle.
Definition: SUMOVehicle.h:64
AllowedLanesCont myAllowed
Associative container from destination-edge to allowed-lanes.
Definition: MSEdge.h:691
person_by_offset_sorter(SUMOTime timestep)
constructor
Definition: MSEdge.h:631
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:106
static void clear()
Clears the dictionary.
Definition: MSEdge.cpp:569
SVCPermissions myMinimumPermissions
The intersection of lane permissions for this edge.
Definition: MSEdge.h:698
static SUMOReal getTravelTime(const MSEdge *const e, const SUMOVehicle *const v, SUMOReal t)
Returns the travel time to pass an edge.
Definition: MSNet.cpp:138
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:188
MSJunction * myToJunction
Definition: MSEdge.h:682
MSLaneChanger * myLaneChanger
This member will do the lane-change.
Definition: MSEdge.h:663
void markDelayed() const
Definition: MSEdge.h:554
MSEdge(const std::string &id, int numericalID, const EdgeBasicFunction function, const std::string &streetName, const std::string &edgeType, int priority)
Constructor.
Definition: MSEdge.cpp:72
bool isRoundabout() const
Definition: MSEdge.h:546
bool isVaporizing() const
Returns whether vehicles on this edge shall be vaporized.
Definition: MSEdge.h:347
T MIN2(T a, T b)
Definition: StdDefs.h:68
virtual void removePerson(MSPerson *p) const
Definition: MSEdge.h:539
int operator()(const MSPerson *const p1, const MSPerson *const p2) const
comparing operator
Definition: MSEdge.cpp:648
const std::vector< MSLane * > * myLanes
Container for the edge&#39;s lane; should be sorted: (right-hand-traffic) the more left the lane...
Definition: MSEdge.h:660
virtual void addPerson(MSPerson *p) const
Definition: MSEdge.h:535
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:626
bool isInternal() const
return whether this edge is an internal edge
Definition: MSEdge.h:227
const std::string & getEdgeType() const
Returns the type of the edge.
Definition: MSEdge.h:257
MSLane * getDepartLane(MSVehicle &veh) const
Finds a depart lane for the given vehicle parameters.
Definition: MSEdge.cpp:310
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:700
The edge is a pedestrian walking area (a special type of internal edge)
Definition: MSEdge.h:98
EdgeBasicFunction getPurpose() const
Returns the edge type (EdgeBasicFunction)
Definition: MSEdge.h:222
const std::vector< MSEdge * > & getIncomingEdges() const
Returns the list of edges from which this edge may be reached.
Definition: MSEdge.h:284
Structure representing possible vehicle parameter.
int operator()(const MSEdge *const e1, const MSEdge *const e2) const
comparing operator
Definition: MSEdge.h:619
int getNumericalID() const
Returns the numerical id of the edge.
Definition: MSEdge.h:244
int getPriority() const
Returns the priority of the edge.
Definition: MSEdge.h:263
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:200
virtual void changeLanes(SUMOTime t)
Performs lane changing on this edge.
Definition: MSEdge.cpp:449
The edge is a normal street.
Definition: MSEdge.h:88
SUMOReal myEmptyTraveltime
the traveltime on the empty edge (cached value for speedup)
Definition: MSEdge.h:716
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:215
bool myAmRoundabout
whether this edge belongs to a roundabout
Definition: MSEdge.h:722
The edge is a pedestrian crossing (a special type of internal edge)
Definition: MSEdge.h:96
static size_t dictSize()
Returns the number of edges.
Definition: MSEdge.cpp:557
std::string myStreetName
the real-world name of this edge (need not be unique)
Definition: MSEdge.h:704
MSJunction * myFromJunction
the junctions for this edge
Definition: MSEdge.h:681
int SUMOTime
Definition: SUMOTime.h:43
SUMOTime getLastFailedInsertionTime() const
Returns the last time a vehicle could not be inserted.
Definition: MSEdge.h:465
void setJunctions(MSJunction *from, MSJunction *to)
Definition: MSEdge.h:333
by_id_sorter()
constructor
Definition: MSEdge.h:616
std::map< const MSEdge *, std::vector< MSLane * > * > AllowedLanesCont
Suceeding edges (keys) and allowed lanes to reach these edges (values).
Definition: MSEdge.h:103
const int myPriority
the priority of the edge (used during network creation)
Definition: MSEdge.h:710
void setLastFailedInsertionTime(SUMOTime time) const
Sets the last time a vehicle could not be inserted.
Definition: MSEdge.h:473
static DictType myDict
Static dictionary to associate string-ids with objects.
Definition: MSEdge.h:733
MSEdge * getPredecessor(unsigned int pos) const
Returns the edge at the given position from the list of reachable edges.
Definition: MSEdge.h:319
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
#define SUMOReal
Definition: config.h:218
SUMOReal getMinimumTravelTime(const SUMOVehicle *const veh) const
returns the minimum travel time for the given vehicle
Definition: MSEdge.h:389
bool isCrossing() const
return whether this edge is a pedestrian crossing
Definition: MSEdge.h:232
unsigned int getNumSuccessors() const
Returns the number of edges that may be reached from this edge.
Definition: MSEdge.h:292
const MSJunction * getFromJunction() const
Definition: MSEdge.h:324
#define NUMERICAL_EPS
Definition: config.h:162
SUMOReal getVehicleMaxSpeed(const SUMOVehicle *const veh) const
Returns the maximum speed the vehicle may use on this edge.
Definition: MSEdge.cpp:633
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:194
void markAsRoundabout()
Definition: MSEdge.h:550
The edge is an internal edge.
Definition: MSEdge.h:92
const std::vector< MSLane * > * getAllowedLanesWithDefault(const AllowedLanesCont &c, const MSEdge *dest) const
lookup in map and return 0 if not found
Definition: MSEdge.cpp:227
std::vector< MSPerson * > getSortedPersons(SUMOTime timestep) const
Returns this edge&#39;s persons sorted by pos.
Definition: MSEdge.cpp:640
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
SUMOReal getCurrentTravelTime(const SUMOReal minSpeed=NUMERICAL_EPS) const
Computes and returns the current travel time for this edge.
Definition: MSEdge.cpp:493
vehicles ignoring classes
static SUMOReal getTravelTimeStatic(const MSEdge *const edge, const SUMOVehicle *const veh, SUMOReal time)
Returns the travel time for the given edge.
Definition: MSEdge.h:405
const MSJunction * getToJunction() const
Definition: MSEdge.h:328
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle&#39;s type.