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.dlr.de/
14 // Copyright (C) 2001-2015 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 class MSEdge;
64 class MSContainer;
65 
66 
67 // ===========================================================================
68 // class definitions
69 // ===========================================================================
78 typedef std::vector<MSEdge*> MSEdgeVector;
79 typedef std::vector<const MSEdge*> ConstMSEdgeVector;
80 
81 class MSEdge : public Named, public Parameterised {
82 public:
105  };
106 
107 
109  typedef std::map< const MSEdge*, std::vector<MSLane*>* > AllowedLanesCont;
110 
112  typedef std::map< SUMOVehicleClass, AllowedLanesCont > ClassedAllowedLanesCont;
113 
114 
115 public:
127  MSEdge(const std::string& id, int numericalID, const EdgeBasicFunction function,
128  const std::string& streetName, const std::string& edgeType, int priority);
129 
130 
132  virtual ~MSEdge();
133 
134 
140  void initialize(const std::vector<MSLane*>* lanes);
141 
142 
145  void recalcCache();
146 
147 
149  void closeBuilding();
150 
151 
154 
161  MSLane* leftLane(const MSLane* const lane) const;
162 
163 
170  MSLane* rightLane(const MSLane* const lane) const;
171 
172 
179  MSLane* parallelLane(const MSLane* const lane, int offset) const;
180 
181 
186  const std::vector<MSLane*>& getLanes() const {
187  return *myLanes;
188  }
189 
190 
195  std::vector<MSTransportable*> getSortedPersons(SUMOTime timestep) const;
196 
197 
202  std::vector<MSTransportable*> getSortedContainers(SUMOTime timestep) const;
203 
212  const std::vector<MSLane*>* allowedLanes(const MSEdge& destination,
213  SUMOVehicleClass vclass = SVC_IGNORING) const;
214 
215 
223  const std::vector<MSLane*>* allowedLanes(SUMOVehicleClass vclass = SVC_IGNORING) const;
225 
226 
227 
230 
236  return myFunction;
237  }
238 
240  inline bool isInternal() const {
242  }
243 
245  inline bool isCrossing() const {
247  }
248 
250  inline bool isWalkingArea() const {
252  }
253 
257  inline int getNumericalID() const {
258  return myNumericalID;
259  }
260 
261 
264  const std::string& getStreetName() const {
265  return myStreetName;
266  }
267 
270  const std::string& getEdgeType() const {
271  return myEdgeType;
272  }
273 
276  int getPriority() const {
277  return myPriority;
278  }
280 
281 
282 
285 
291  void addSuccessor(MSEdge* edge) {
292  mySuccessors.push_back(edge);
293  edge->myPredecessors.push_back(this);
294  }
295 
296 
301  return myPredecessors;
302  }
303 
304 
308  unsigned int getNumSuccessors() const {
309  return (unsigned int) mySuccessors.size();
310  }
311 
312 
315  const MSEdgeVector& getSuccessors() const {
316  return mySuccessors;
317  }
318 
319 
324  const MSEdgeVector& getSuccessors(SUMOVehicleClass vClass) const;
325 
326 
331  unsigned int getNumPredecessors() const {
332  return (unsigned int) myPredecessors.size();
333  }
334 
335 
340  const MSEdgeVector& getPredecessors() const {
341  return myPredecessors;
342  }
343 
344 
345  const MSJunction* getFromJunction() const {
346  return myFromJunction;
347  }
348 
349  const MSJunction* getToJunction() const {
350  return myToJunction;
351  }
352 
353 
354  void setJunctions(MSJunction* from, MSJunction* to) {
355  myFromJunction = from;
356  myToJunction = to;
357  }
359 
360 
361 
364 
368  bool isVaporizing() const {
369  return myVaporizationRequests > 0;
370  }
371 
372 
383 
384 
396 
397 
406  SUMOReal getCurrentTravelTime(const SUMOReal minSpeed = NUMERICAL_EPS) const;
407 
408 
410  inline SUMOReal getMinimumTravelTime(const SUMOVehicle* const veh) const {
411  if (veh != 0) {
412  return getLength() / getVehicleMaxSpeed(veh);
413  } else {
414  return getLength() / getSpeedLimit();
415  }
416  }
417 
418 
426  static inline SUMOReal getTravelTimeStatic(const MSEdge* const edge, const SUMOVehicle* const veh, SUMOReal time) {
427  return MSNet::getInstance()->getTravelTime(edge, veh, time);
428  }
429 
430 
433 
450  bool insertVehicle(SUMOVehicle& v, SUMOTime time, const bool checkOnly = false) const;
451 
452 
467  MSLane* getFreeLane(const std::vector<MSLane*>* allowed, const SUMOVehicleClass vclass) const;
468 
469 
480  MSLane* getDepartLane(MSVehicle& veh) const;
481 
482 
488  }
489 
490 
494  inline void setLastFailedInsertionTime(SUMOTime time) const {
496  }
498 
499 
501  virtual void changeLanes(SUMOTime t);
502 
503 
504 #ifdef HAVE_INTERNAL_LANES
505  const MSEdge* getInternalFollowingEdge(MSEdge* followerAfterInternal) const;
507 #endif
508 
510  inline bool prohibits(const SUMOVehicle* const vehicle) const {
511  if (vehicle == 0) {
512  return false;
513  }
514  const SUMOVehicleClass svc = vehicle->getVehicleType().getVehicleClass();
515  return (myCombinedPermissions & svc) != svc;
516  }
517 
519  return myCombinedPermissions;
520  }
521 
522  void rebuildAllowedLanes();
523 
524 
529  SUMOReal getDistanceTo(const MSEdge* other) const;
530 
531 
535  inline SUMOReal getLength() const {
536  return myLength;
537  }
538 
539 
544  SUMOReal getSpeedLimit() const;
545 
546 
552  SUMOReal getVehicleMaxSpeed(const SUMOVehicle* const veh) const;
553 
554  virtual void addPerson(MSTransportable* p) const {
555  myPersons.insert(p);
556  }
557 
558  virtual void removePerson(MSTransportable* p) const {
559  std::set<MSTransportable*>::iterator i = myPersons.find(p);
560  if (i != myPersons.end()) {
561  myPersons.erase(i);
562  }
563  }
564 
566  virtual void addContainer(MSTransportable* container) const {
567  myContainers.insert(container);
568  }
569 
571  virtual void removeContainer(MSTransportable* container) const {
572  std::set<MSTransportable*>::iterator i = myContainers.find(container);
573  if (i != myContainers.end()) {
574  myContainers.erase(i);
575  }
576  }
577 
578  inline bool isRoundabout() const {
579  return myAmRoundabout;
580  }
581 
583  myAmRoundabout = true;
584  }
585 
586  void markDelayed() const {
587  myAmDelayed = true;
588  }
589 
593  static bool dictionary(const std::string& id, MSEdge* edge);
594 
596  static MSEdge* dictionary(const std::string& id);
597 
599  static MSEdge* dictionary(size_t index);
600 
602  static size_t dictSize();
603 
605  static size_t numericalDictSize();
606 
608  static void clear();
609 
611  static void insertIDs(std::vector<std::string>& into);
612 
613 
614 public:
617 
626  static void parseEdgesList(const std::string& desc, ConstMSEdgeVector& into,
627  const std::string& rid);
628 
629 
636  static void parseEdgesList(const std::vector<std::string>& desc, ConstMSEdgeVector& into,
637  const std::string& rid);
639 
640 
641 protected:
645  class by_id_sorter {
646  public:
648  explicit by_id_sorter() { }
649 
651  int operator()(const MSEdge* const e1, const MSEdge* const e2) const {
652  return e1->getID() < e2->getID();
653  }
654 
655  };
656 
661  public:
663  explicit transportable_by_position_sorter(SUMOTime timestep): myTime(timestep) { }
664 
666  int operator()(const MSTransportable* const c1, const MSTransportable* const c2) const;
667  private:
669  };
670 
671 
680  const std::vector<MSLane*>* allowedLanes(const MSEdge* destination,
681  SUMOVehicleClass vclass = SVC_IGNORING) const;
682 
683 
685  const std::vector<MSLane*>* getAllowedLanesWithDefault(const AllowedLanesCont& c, const MSEdge* dest) const;
686 
687 protected:
689  const int myNumericalID;
690 
692  const std::vector<MSLane*>* myLanes;
693 
696 
699 
702 
705 
708 
711 
715 
717  mutable std::set<MSTransportable*> myPersons;
718 
720  mutable std::set<MSTransportable*> myContainers;
721 
724 
726  AllowedLanesCont myAllowed;
727 
729  // @note: this map is filled on demand
730  mutable ClassedAllowedLanesCont myClassedAllowed;
731 
737 
739  std::string myStreetName;
740 
742  std::string myEdgeType;
743 
745  const int myPriority;
746 
749 
752 
754  mutable bool myAmDelayed;
755 
758 
761 
763  typedef std::map< std::string, MSEdge* > DictType;
764 
768  static DictType myDict;
769 
775 
776 
778  mutable std::map<SUMOVehicleClass, MSEdgeVector> myClassesSuccessorMap;
779 
780 private:
782  MSEdge(const MSEdge&);
783 
785  MSEdge& operator=(const MSEdge&);
786 
787 };
788 
789 
790 #endif
791 
792 /****************************************************************************/
793 
bool myAmDelayed
whether this edge had a vehicle with less than max speed on it
Definition: MSEdge.h:754
std::set< MSTransportable * > myContainers
Containers on the edge.
Definition: MSEdge.h:720
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:80
static void insertIDs(std::vector< std::string > &into)
Inserts IDs of all known edges into the given vector.
Definition: MSEdge.cpp:634
long long int SUMOTime
Definition: SUMOTime.h:43
SUMOReal myLength
the length of the edge (cached value for speedup)
Definition: MSEdge.h:748
SUMOVehicleClass getVehicleClass() const
Get this vehicle type&#39;s vehicle class.
Sorts edges by their ids.
Definition: MSEdge.h:645
void addSuccessor(MSEdge *edge)
Adds an edge to the list of edges which may be reached from this edge and to the incoming of the othe...
Definition: MSEdge.h:291
bool insertVehicle(SUMOVehicle &v, SUMOTime time, const bool checkOnly=false) const
Tries to insert the given vehicle into the network.
Definition: MSEdge.cpp:396
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:672
static size_t numericalDictSize()
Returns the number of edges with a numerical id.
Definition: MSEdge.cpp:619
void initialize(const std::vector< MSLane * > *lanes)
Initialize the edge.
Definition: MSEdge.cpp:109
const std::vector< MSLane * > & getLanes() const
Returns this edge&#39;s lanes.
Definition: MSEdge.h:186
unsigned int getNumPredecessors() const
Returns the number of edges this edge is connected to.
Definition: MSEdge.h:331
void recalcCache()
Recalculates the cached values.
Definition: MSEdge.cpp:129
virtual void addContainer(MSTransportable *container) const
Add a container to myContainers.
Definition: MSEdge.h:566
The base class for an intersection.
Definition: MSJunction.h:61
static MSEdgeVector myEdges
Static list of edges.
Definition: MSEdge.h:773
const EdgeBasicFunction myFunction
the purpose of the edge
Definition: MSEdge.h:698
int SVCPermissions
ClassedAllowedLanesCont myClassedAllowed
From vehicle class to lanes allowed to be used by it.
Definition: MSEdge.h:730
bool isWalkingArea() const
return whether this edge is walking area
Definition: MSEdge.h:250
void closeBuilding()
Definition: MSEdge.cpp:136
virtual ~MSEdge()
Destructor.
Definition: MSEdge.cpp:93
const std::string & getStreetName() const
Returns the street name of the edge.
Definition: MSEdge.h:264
The edge is a macroscopic connector (source/sink)
Definition: MSEdge.h:96
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:162
std::string myEdgeType
the type of the edge (optionally used during network creation)
Definition: MSEdge.h:742
SVCPermissions getPermissions() const
Definition: MSEdge.h:518
transportable_by_position_sorter(SUMOTime timestep)
constructor
Definition: MSEdge.h:663
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:579
const int myNumericalID
This edge&#39;s numerical id.
Definition: MSEdge.h:689
SUMOTime incVaporization(SUMOTime t)
Enables vaporization.
Definition: MSEdge.cpp:307
MSLane * getFreeLane(const std::vector< MSLane * > *allowed, const SUMOVehicleClass vclass) const
Finds the emptiest lane allowing the vehicle class.
Definition: MSEdge.cpp:321
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:79
int myVaporizationRequests
Vaporizer counter.
Definition: MSEdge.h:701
const MSEdgeVector & getIncomingEdges() const
Returns the list of edges from which this edge may be reached.
Definition: MSEdge.h:300
EdgeBasicFunction
Defines possible edge types.
Definition: MSEdge.h:90
bool prohibits(const SUMOVehicle *const vehicle) const
Returns whether the vehicle (class) is not allowed on the edge.
Definition: MSEdge.h:510
SUMOTime decVaporization(SUMOTime t)
Disables vaporization.
Definition: MSEdge.cpp:314
The purpose of the edge is not known.
Definition: MSEdge.h:92
virtual void removeContainer(MSTransportable *container) const
Remove container from myContainers.
Definition: MSEdge.h:571
std::map< std::string, MSEdge * > DictType
definition of the static dictionary type
Definition: MSEdge.h:763
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:65
A road/street connecting two junctions.
Definition: MSEdge.h:81
SUMOTime myLastFailedInsertionTime
The time of last insertion failure.
Definition: MSEdge.h:704
std::map< SUMOVehicleClass, MSEdgeVector > myClassesSuccessorMap
The successors available for a given vClass.
Definition: MSEdge.h:778
void rebuildAllowedLanes()
Definition: MSEdge.cpp:175
SUMOReal getLength() const
return the length of the edge
Definition: MSEdge.h:535
virtual void removePerson(MSTransportable *p) const
Definition: MSEdge.h:558
The edge is a district edge.
Definition: MSEdge.h:100
virtual void addPerson(MSTransportable *p) const
Definition: MSEdge.h:554
Representation of a vehicle.
Definition: SUMOVehicle.h:65
const MSEdgeVector & getPredecessors() const
Returns the edge at the given position from the list of reachable edges.
Definition: MSEdge.h:340
AllowedLanesCont myAllowed
Associative container from destination-edge to allowed-lanes.
Definition: MSEdge.h:726
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:112
static void clear()
Clears the dictionary.
Definition: MSEdge.cpp:625
SVCPermissions myMinimumPermissions
The intersection of lane permissions for this edge.
Definition: MSEdge.h:733
static SUMOReal getTravelTime(const MSEdge *const e, const SUMOVehicle *const v, SUMOReal t)
Returns the travel time to pass an edge.
Definition: MSNet.cpp:144
MSEdgeVector mySuccessors
The succeeding edges.
Definition: MSEdge.h:707
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:197
MSJunction * myToJunction
Definition: MSEdge.h:714
MSLaneChanger * myLaneChanger
This member will do the lane-change.
Definition: MSEdge.h:695
void markDelayed() const
Definition: MSEdge.h:586
MSEdge(const std::string &id, int numericalID, const EdgeBasicFunction function, const std::string &streetName, const std::string &edgeType, int priority)
Constructor.
Definition: MSEdge.cpp:75
bool isRoundabout() const
Definition: MSEdge.h:578
bool isVaporizing() const
Returns whether vehicles on this edge shall be vaporized.
Definition: MSEdge.h:368
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:692
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:682
bool isInternal() const
return whether this edge is an internal edge
Definition: MSEdge.h:240
const std::string & getEdgeType() const
Returns the type of the edge.
Definition: MSEdge.h:270
MSLane * getDepartLane(MSVehicle &veh) const
Finds a depart lane for the given vehicle parameters.
Definition: MSEdge.cpp:341
Base class for objects which have an id.
Definition: Named.h:45
std::vector< MSTransportable * > getSortedContainers(SUMOTime timestep) const
Returns this edge&#39;s containers sorted by pos.
Definition: MSEdge.cpp:704
SVCPermissions myCombinedPermissions
The union of lane permissions for this edge.
Definition: MSEdge.h:735
The edge is a pedestrian walking area (a special type of internal edge)
Definition: MSEdge.h:104
EdgeBasicFunction getPurpose() const
Returns the edge type (EdgeBasicFunction)
Definition: MSEdge.h:235
Structure representing possible vehicle parameter.
int operator()(const MSEdge *const e1, const MSEdge *const e2) const
comparing operator
Definition: MSEdge.h:651
int getNumericalID() const
Returns the numerical id of the edge.
Definition: MSEdge.h:257
int getPriority() const
Returns the priority of the edge.
Definition: MSEdge.h:276
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:209
virtual void changeLanes(SUMOTime t)
Performs lane changing on this edge.
Definition: MSEdge.cpp:498
The edge is a normal street.
Definition: MSEdge.h:94
SUMOReal myEmptyTraveltime
the traveltime on the empty edge (cached value for speedup)
Definition: MSEdge.h:751
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:224
bool myAmRoundabout
whether this edge belongs to a roundabout
Definition: MSEdge.h:757
The edge is a pedestrian crossing (a special type of internal edge)
Definition: MSEdge.h:102
static size_t dictSize()
Returns the number of edges.
Definition: MSEdge.cpp:613
std::string myStreetName
the real-world name of this edge (need not be unique)
Definition: MSEdge.h:739
MSJunction * myFromJunction
the junctions for this edge
Definition: MSEdge.h:713
SUMOTime getLastFailedInsertionTime() const
Returns the last time a vehicle could not be inserted.
Definition: MSEdge.h:486
void setJunctions(MSJunction *from, MSJunction *to)
Definition: MSEdge.h:354
by_id_sorter()
constructor
Definition: MSEdge.h:648
std::map< const MSEdge *, std::vector< MSLane * > * > AllowedLanesCont
Suceeding edges (keys) and allowed lanes to reach these edges (values).
Definition: MSEdge.h:109
const int myPriority
the priority of the edge (used during network creation)
Definition: MSEdge.h:745
void setLastFailedInsertionTime(SUMOTime time) const
Sets the last time a vehicle could not be inserted.
Definition: MSEdge.h:494
static DictType myDict
Static dictionary to associate string-ids with objects.
Definition: MSEdge.h:768
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
#define SUMOReal
Definition: config.h:214
Sorts transportables by their positions.
Definition: MSEdge.h:660
SUMOReal getMinimumTravelTime(const SUMOVehicle *const veh) const
returns the minimum travel time for the given vehicle
Definition: MSEdge.h:410
bool isCrossing() const
return whether this edge is a pedestrian crossing
Definition: MSEdge.h:245
unsigned int getNumSuccessors() const
Returns the number of edges that may be reached from this edge.
Definition: MSEdge.h:308
const MSJunction * getFromJunction() const
Definition: MSEdge.h:345
const MSEdgeVector & getSuccessors() const
Returns the following edges.
Definition: MSEdge.h:315
#define NUMERICAL_EPS
Definition: config.h:161
SUMOReal getVehicleMaxSpeed(const SUMOVehicle *const veh) const
Returns the maximum speed the vehicle may use on this edge.
Definition: MSEdge.cpp:689
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:78
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:203
void markAsRoundabout()
Definition: MSEdge.h:582
The edge is an internal edge.
Definition: MSEdge.h:98
const std::vector< MSLane * > * getAllowedLanesWithDefault(const AllowedLanesCont &c, const MSEdge *dest) const
lookup in map and return 0 if not found
Definition: MSEdge.cpp:236
MSEdgeVector myPredecessors
The preceeding edges.
Definition: MSEdge.h:710
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:549
static void parseEdgesList(const std::string &desc, ConstMSEdgeVector &into, const std::string &rid)
Parses the given string assuming it contains a list of edge ids divided by spaces.
Definition: MSEdge.cpp:642
vehicles ignoring classes
std::vector< MSTransportable * > getSortedPersons(SUMOTime timestep) const
Returns this edge&#39;s persons sorted by pos.
Definition: MSEdge.cpp:696
static SUMOReal getTravelTimeStatic(const MSEdge *const edge, const SUMOVehicle *const veh, SUMOReal time)
Returns the travel time for the given edge.
Definition: MSEdge.h:426
const MSJunction * getToJunction() const
Definition: MSEdge.h:349
std::set< MSTransportable * > myPersons
Persons on the edge (only for drawing)
Definition: MSEdge.h:717
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle&#39;s type.