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-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 
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  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 
std::set< MSPerson * > myPersons
Persons on the edge (only for drawing)
Definition: MSEdge.h:568
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:547
static void insertIDs(std::vector< std::string > &into)
Inserts IDs of all known edges into the given vector.
Definition: MSEdge.cpp:520
SUMOVehicleClass getVehicleClass() const
Get this vehicle type's vehicle class.
Sorts edges by their ids.
Definition: MSEdge.h:514
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:558
static size_t numericalDictSize()
Returns the number of edges with a numerical id.
Definition: MSEdge.cpp:505
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition: MSEdge.h:168
std::vector< MSEdge * > mySuccessors
The succeeding edges.
Definition: MSEdge.h:562
const EdgeBasicFunction myFunction
the purpose of the edge
Definition: MSEdge.h:553
ClassedAllowedLanesCont myClassedAllowed
From vehicle class to lanes allowed to be used by it.
Definition: MSEdge.h:578
void closeBuilding()
Definition: MSEdge.cpp:128
virtual ~MSEdge()
Destructor.
Definition: MSEdge.cpp:78
const std::string & getStreetName() const
Returns the street name of the edge.
Definition: MSEdge.h:219
The edge is a macroscopic connector (source/sink)
Definition: MSEdge.h:88
SUMOReal getCurrentTravelTime(const SUMOReal minSpeed=0.00001) const
Computes and returns the current travel time for this edge.
Definition: MSEdge.cpp:437
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:465
SUMOTime incVaporization(SUMOTime t)
Enables vaporization.
Definition: MSEdge.cpp:274
MSLane * getFreeLane(const std::vector< MSLane * > *allowed, const SUMOVehicleClass vclass) const
Finds the emptiest lane allowing the vehicle class.
Definition: MSEdge.cpp:288
virtual SUMOReal getMaxSpeed() const =0
Returns the vehicle's maximum speed.
int myVaporizationRequests
Vaporizer counter.
Definition: MSEdge.h:556
EdgeBasicFunction
Defines possible edge types.
Definition: MSEdge.h:82
bool prohibits(const SUMOVehicle *const vehicle) const
Returns whether the vehicle (class) is not allowed on the edge.
Definition: MSEdge.h:397
SUMOTime decVaporization(SUMOTime t)
Disables vaporization.
Definition: MSEdge.cpp:281
The purpose of the edge is not known.
Definition: MSEdge.h:84
std::map< std::string, MSEdge * > DictType
definition of the static dictionary type
Definition: MSEdge.h:596
MSEdge(const std::string &id, int numericalID, const EdgeBasicFunction function, const std::string &streetName="")
Constructor.
Definition: MSEdge.cpp:70
void initialize(std::vector< MSLane * > *lanes)
Initialize the edge.
Definition: MSEdge.cpp:94
static std::vector< MSEdge * > myEdges
Static list of edges.
Definition: MSEdge.h:606
MSEdge & operator=(const MSEdge &)
assignment operator.
Performs lane changing of vehicles.
Definition: MSLaneChanger.h:54
const std::string & getID() const
Returns the id.
Definition: Named.h:60
A road/street connecting two junctions.
Definition: MSEdge.h:73
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:528
SUMOTime myLastFailedInsertionTime
The time of last insertion failure.
Definition: MSEdge.h:559
void rebuildAllowedLanes()
Definition: MSEdge.cpp:165
SUMOReal getLength() const
return the length of the edge
Definition: MSEdge.cpp:568
The edge is a district edge.
Definition: MSEdge.h:92
Representation of a vehicle.
Definition: SUMOVehicle.h:63
AllowedLanesCont myAllowed
Associative container from destination-edge to allowed-lanes.
Definition: MSEdge.h:574
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:100
static void clear()
Clears the dictionary.
Definition: MSEdge.cpp:511
SVCPermissions myMinimumPermissions
The intersection of lane permissions for this edge.
Definition: MSEdge.h:581
unsigned int getNoFollowing() const
Returns the number of edges that may be reached from this edge.
Definition: MSEdge.h:248
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:186
MSLaneChanger * myLaneChanger
This member will do the lane-change.
Definition: MSEdge.h:550
bool isRoundabout() const
Definition: MSEdge.h:448
bool isVaporizing() const
Returns whether vehicles on this edge shall be vaporized.
Definition: MSEdge.h:270
T MIN2(T a, T b)
Definition: StdDefs.h:65
std::vector< MSEdge * > myPredeccesors
The preceeding edges.
Definition: MSEdge.h:565
virtual void removePerson(MSPerson *p) const
Definition: MSEdge.h:441
MSLane * getDepartLane(const MSVehicle &veh) const
Finds a depart lane for the given vehicle parameters.
Definition: MSEdge.cpp:307
virtual void addPerson(MSPerson *p) const
Definition: MSEdge.h:437
An upper class for objects with additional parameters.
Definition: Parameterised.h:46
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:574
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:583
const std::vector< MSLane * > * allowedLanes(const MSEdge &destination, SUMOVehicleClass vclass=SVC_UNKNOWN) const
Get the allowed lanes to reach the destination-edge.
Definition: MSEdge.cpp:213
EdgeBasicFunction getPurpose() const
Returns the edge type (EdgeBasicFunction)
Definition: MSEdge.h:204
const std::vector< MSEdge * > & getIncomingEdges() const
Returns the list of edges from which this edge may be reached.
Definition: MSEdge.h:240
Structure representing possible vehicle parameter.
int operator()(const MSEdge *const e1, const MSEdge *const e2) const
comparing operator
Definition: MSEdge.h:520
int getNumericalID() const
Returns the numerical id of the edge.
Definition: MSEdge.h:212
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:198
virtual void changeLanes(SUMOTime t)
Performs lane changing on this edge.
Definition: MSEdge.cpp:405
The edge is a normal street.
Definition: MSEdge.h:86
bool myAmRoundabout
whether this edge belongs to a roundabout
Definition: MSEdge.h:590
void addFollower(MSEdge *edge)
Returns the list of edges which may be reached from this edge.
Definition: MSEdge.h:232
static size_t dictSize()
Returns the number of edges.
Definition: MSEdge.cpp:499
std::string myStreetName
the real-world name of this edge (need not be unique)
Definition: MSEdge.h:587
int SUMOTime
Definition: SUMOTime.h:43
SUMOTime getLastFailedInsertionTime() const
Returns the last time a vehicle could not be inserted.
Definition: MSEdge.h:373
by_id_sorter()
constructor
Definition: MSEdge.h:517
const MSEdge * getFollower(unsigned int n) const
Returns the n-th of the following edges.
Definition: MSEdge.h:257
std::map< const MSEdge *, std::vector< MSLane * > * > AllowedLanesCont
Suceeding edges (keys) and allowed lanes to reach these edges (values).
Definition: MSEdge.h:97
int myNumericalID
This edge's numerical id.
Definition: MSEdge.h:544
void setLastFailedInsertionTime(SUMOTime time) const
Sets the last time a vehicle could not be inserted.
Definition: MSEdge.h:381
static DictType myDict
Static dictionary to associate string-ids with objects.
Definition: MSEdge.h:601
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
#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:312
bool laneChangeAllowed() const
whether lane changing may be performed on this edge
Definition: MSEdge.cpp:107
SUMOReal getVehicleMaxSpeed(const SUMOVehicle *const veh) const
Returns the maximum speed the vehicle may use on this edge.
Definition: MSEdge.cpp:581
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:192
void markAsRoundabout()
Definition: MSEdge.h:452
bool insertVehicle(SUMOVehicle &v, SUMOTime time) const
Tries to insert the given vehicle into the network.
Definition: MSEdge.cpp:354
The edge is an internal edge.
Definition: MSEdge.h:90
const std::vector< MSLane * > * getAllowedLanesWithDefault(const AllowedLanesCont &c, const MSEdge *dest) const
lookup in map and return 0 if not found
Definition: MSEdge.cpp:225
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle's type.