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 
160  MSLane* parallelLane(const MSLane* const lane, int offset) const;
161 
162 
167  const std::vector<MSLane*>& getLanes() const {
168  return *myLanes;
169  }
170 
171 
180  const std::vector<MSLane*>* allowedLanes(const MSEdge& destination,
181  SUMOVehicleClass vclass = SVC_UNKNOWN) const;
182 
183 
191  const std::vector<MSLane*>* allowedLanes(SUMOVehicleClass vclass = SVC_UNKNOWN) const;
193 
194 
195 
198 
204  return myFunction;
205  }
206 
207 
211  int getNumericalID() const {
212  return myNumericalID;
213  }
214 
215 
218  const std::string& getStreetName() const {
219  return myStreetName;
220  }
222 
223 
224 
227 
231  void addFollower(MSEdge* edge) {
232  mySuccessors.push_back(edge);
233  }
234 
235 
239  const std::vector<MSEdge*>& getIncomingEdges() const {
240  return myPredeccesors;
241  }
242 
243 
247  unsigned int getNoFollowing() const {
248  return (unsigned int) mySuccessors.size();
249  }
250 
255  const MSEdge* getFollower(unsigned int n) const {
256  return mySuccessors[n];
257  }
259 
260 
261 
264 
268  bool isVaporizing() const {
269  return myVaporizationRequests > 0;
270  }
271 
272 
283 
284 
296 
297 
306  SUMOReal getCurrentTravelTime(const SUMOReal minSpeed = 0.00001) const;
307 
308 
310  inline SUMOReal getMinimumTravelTime(const SUMOVehicle* const veh) const {
311  if (veh != 0) {
312  return getLength() / MIN2(veh->getMaxSpeed(), getVehicleMaxSpeed(veh));
313  } else {
314  return getLength() / getSpeedLimit();
315  }
316  }
317 
318 
321 
335  bool insertVehicle(SUMOVehicle& v, SUMOTime time) const;
336 
337 
352  MSLane* getFreeLane(const std::vector<MSLane*>* allowed, const SUMOVehicleClass vclass) const;
353 
354 
365  MSLane* getDepartLane(const MSVehicle& veh) const;
366 
367 
373  }
374 
375 
379  inline void setLastFailedInsertionTime(SUMOTime time) const {
381  }
383 
384 
386  virtual void changeLanes(SUMOTime t);
387 
388 
389 #ifdef HAVE_INTERNAL_LANES
390  const MSEdge* getInternalFollowingEdge(MSEdge* followerAfterInternal) const;
392 #endif
393 
395  inline bool prohibits(const SUMOVehicle* const vehicle) const {
396  if (vehicle == 0) {
397  return false;
398  }
399  const SUMOVehicleClass svc = vehicle->getVehicleType().getVehicleClass();
400  return (myCombinedPermissions & svc) != svc;
401  }
402 
403  void rebuildAllowedLanes();
404 
405 
410  SUMOReal getDistanceTo(const MSEdge* other) const;
411 
412 
416  SUMOReal getLength() const;
417 
418 
423  SUMOReal getSpeedLimit() const;
424 
425 
433  SUMOReal getVehicleMaxSpeed(const SUMOVehicle* const veh) const;
434 
435  virtual void addPerson(MSPerson* p) const {
436  myPersons.insert(p);
437  }
438 
439  virtual void removePerson(MSPerson* p) const {
440  std::set<MSPerson*>::iterator i = myPersons.find(p);
441  if (i != myPersons.end()) {
442  myPersons.erase(i);
443  }
444  }
445 
446 
450  static bool dictionary(const std::string& id, MSEdge* edge);
451 
453  static MSEdge* dictionary(const std::string& id);
454 
456  static MSEdge* dictionary(size_t index);
457 
459  static size_t dictSize();
460 
462  static size_t numericalDictSize();
463 
465  static void clear();
466 
468  static void insertIDs(std::vector<std::string>& into);
469 
470 
471 public:
474 
483  static void parseEdgesList(const std::string& desc, std::vector<const MSEdge*>& into,
484  const std::string& rid);
485 
486 
493  static void parseEdgesList(const std::vector<std::string>& desc, std::vector<const MSEdge*>& into,
494  const std::string& rid);
496 
497 
498 protected:
502  class by_id_sorter {
503  public:
505  explicit by_id_sorter() { }
506 
508  int operator()(const MSEdge* const e1, const MSEdge* const e2) const {
509  return e1->getID() < e2->getID();
510  }
511 
512  };
513 
514 
523  const std::vector<MSLane*>* allowedLanes(const MSEdge* destination,
524  SUMOVehicleClass vclass = SVC_UNKNOWN) const;
525 
526 
528  const std::vector<MSLane*>* getAllowedLanesWithDefault(const AllowedLanesCont& c, const MSEdge* dest) const;
529 
530 protected:
533 
535  std::vector<MSLane*>* myLanes;
536 
539 
542 
545 
548 
550  std::vector<MSEdge*> mySuccessors;
551 
553  std::vector<MSEdge*> myPredeccesors;
554 
556  mutable std::set<MSPerson*> myPersons;
557 
560 
563 
565  // @note: this map is filled on demand
567 
572 
573  std::string myStreetName;
575 
576 
577 
580 
582  typedef std::map< std::string, MSEdge* > DictType;
583 
587  static DictType myDict;
588 
592  static std::vector<MSEdge*> myEdges;
594 
595 
596 
597 private:
599  MSEdge(const MSEdge&);
600 
602  MSEdge& operator=(const MSEdge&);
603 
604 };
605 
606 
607 #endif
608 
609 /****************************************************************************/
610 
std::set< MSPerson * > myPersons
Persons on the edge (only for drawing)
Definition: MSEdge.h:556
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:77
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:535
static void insertIDs(std::vector< std::string > &into)
Inserts IDs of all known edges into the given vector.
Definition: MSEdge.cpp:516
SUMOVehicleClass getVehicleClass() const
Get this vehicle type&#39;s vehicle class.
Sorts edges by their ids.
Definition: MSEdge.h:502
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:554
static size_t numericalDictSize()
Returns the number of edges with a numerical id.
Definition: MSEdge.cpp:501
const std::vector< MSLane * > & getLanes() const
Returns this edge&#39;s lanes.
Definition: MSEdge.h:167
std::vector< MSEdge * > mySuccessors
The succeeding edges.
Definition: MSEdge.h:550
const EdgeBasicFunction myFunction
the purpose of the edge
Definition: MSEdge.h:541
ClassedAllowedLanesCont myClassedAllowed
From vehicle class to lanes allowed to be used by it.
Definition: MSEdge.h:566
void closeBuilding()
Definition: MSEdge.cpp:107
virtual ~MSEdge()
Destructor.
Definition: MSEdge.cpp:78
const std::string & getStreetName() const
Returns the street name of the edge.
Definition: MSEdge.h:218
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:433
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:461
SUMOTime incVaporization(SUMOTime t)
Enables vaporization.
Definition: MSEdge.cpp:268
MSLane * getFreeLane(const std::vector< MSLane * > *allowed, const SUMOVehicleClass vclass) const
Finds the emptiest lane allowing the vehicle class.
Definition: MSEdge.cpp:282
virtual SUMOReal getMaxSpeed() const =0
Returns the vehicle&#39;s maximum speed.
int myVaporizationRequests
Vaporizer counter.
Definition: MSEdge.h:544
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:395
SUMOTime decVaporization(SUMOTime t)
Disables vaporization.
Definition: MSEdge.cpp:275
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:582
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:592
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:524
SUMOTime myLastFailedInsertionTime
The time of last insertion failure.
Definition: MSEdge.h:547
void rebuildAllowedLanes()
Definition: MSEdge.cpp:144
SUMOReal getLength() const
return the length of the edge
Definition: MSEdge.cpp:564
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:562
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:507
SVCPermissions myMinimumPermissions
The intersection of lane permissions for this edge.
Definition: MSEdge.h:569
unsigned int getNoFollowing() const
Returns the number of edges that may be reached from this edge.
Definition: MSEdge.h:247
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:165
MSLaneChanger * myLaneChanger
This member will do the lane-change.
Definition: MSEdge.h:538
bool isVaporizing() const
Returns whether vehicles on this edge shall be vaporized.
Definition: MSEdge.h:268
T MIN2(T a, T b)
Definition: StdDefs.h:57
std::vector< MSEdge * > myPredeccesors
The preceeding edges.
Definition: MSEdge.h:553
virtual void removePerson(MSPerson *p) const
Definition: MSEdge.h:439
MSLane * getDepartLane(const MSVehicle &veh) const
Finds a depart lane for the given vehicle parameters.
Definition: MSEdge.cpp:301
virtual void addPerson(MSPerson *p) const
Definition: MSEdge.h:435
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:570
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:571
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:207
EdgeBasicFunction getPurpose() const
Returns the edge type (EdgeBasicFunction)
Definition: MSEdge.h:203
const std::vector< MSEdge * > & getIncomingEdges() const
Returns the list of edges from which this edge may be reached.
Definition: MSEdge.h:239
Structure representing possible vehicle parameter.
int operator()(const MSEdge *const e1, const MSEdge *const e2) const
comparing operator
Definition: MSEdge.h:508
int getNumericalID() const
Returns the numerical id of the edge.
Definition: MSEdge.h:211
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:177
virtual void changeLanes(SUMOTime t)
Performs lane changing on this edge.
Definition: MSEdge.cpp:399
The edge is a normal street.
Definition: MSEdge.h:86
void addFollower(MSEdge *edge)
Returns the list of edges which may be reached from this edge.
Definition: MSEdge.h:231
static size_t dictSize()
Returns the number of edges.
Definition: MSEdge.cpp:495
std::string myStreetName
Definition: MSEdge.h:573
int SUMOTime
Definition: SUMOTime.h:43
SUMOTime getLastFailedInsertionTime() const
Returns the last time a vehicle could not be inserted.
Definition: MSEdge.h:371
by_id_sorter()
constructor
Definition: MSEdge.h:505
const MSEdge * getFollower(unsigned int n) const
Returns the n-th of the following edges.
Definition: MSEdge.h:255
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&#39;s numerical id.
Definition: MSEdge.h:532
void setLastFailedInsertionTime(SUMOTime time) const
Sets the last time a vehicle could not be inserted.
Definition: MSEdge.h:379
static DictType myDict
Static dictionary to associate string-ids with objects.
Definition: MSEdge.h:587
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
#define SUMOReal
Definition: config.h:221
SUMOReal getMinimumTravelTime(const SUMOVehicle *const veh) const
returns the minimum travel time for the given vehicle
Definition: MSEdge.h:310
SUMOReal getVehicleMaxSpeed(const SUMOVehicle *const veh) const
Returns the maximum speed the vehicle may use on this edge.
Definition: MSEdge.cpp:577
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:171
bool insertVehicle(SUMOVehicle &v, SUMOTime time) const
Tries to insert the given vehicle into the network.
Definition: MSEdge.cpp:348
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:219
Representation of a lane in the micro simulation.
Definition: MSLane.h:73
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle&#39;s type.