Eclipse SUMO - Simulation of Urban MObility
ROEdge.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2002-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
20 // A basic edge for routing applications
21 /****************************************************************************/
22 #ifndef ROEdge_h
23 #define ROEdge_h
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #include <config.h>
30 
31 #include <string>
32 #include <map>
33 #include <vector>
34 #include <algorithm>
35 #include <utils/common/Named.h>
36 #include <utils/common/StdDefs.h>
41 #include <utils/geom/Boundary.h>
42 #ifdef HAVE_FOX
43 #include <fx.h>
44 #endif
46 #include "RONode.h"
47 #include "ROVehicle.h"
48 
49 
50 // ===========================================================================
51 // class declarations
52 // ===========================================================================
53 class ROLane;
54 class ROEdge;
55 
56 typedef std::vector<ROEdge*> ROEdgeVector;
57 typedef std::vector<const ROEdge*> ConstROEdgeVector;
58 typedef std::vector<std::pair<const ROEdge*, const ROEdge*> > ROConstEdgePairVector;
59 
60 
61 // ===========================================================================
62 // class definitions
63 // ===========================================================================
73 class ROEdge : public Named {
74 public:
82  ROEdge(const std::string& id, RONode* from, RONode* to, int index, const int priority);
83 
84 
86  virtual ~ROEdge();
87 
88 
90 
91 
100  virtual void addLane(ROLane* lane);
101 
102 
109  virtual void addSuccessor(ROEdge* s, ROEdge* via = nullptr, std::string dir = "");
110 
111 
115  inline void setFunction(SumoXMLEdgeFunc func) {
116  myFunction = func;
117  }
118 
119 
123  inline void setSource(const bool isSource = true) {
124  myAmSource = isSource;
125  }
126 
127 
131  inline void setSink(const bool isSink = true) {
132  myAmSink = isSink;
133  }
134 
135 
139  inline void setRestrictions(const std::map<SUMOVehicleClass, double>* restrictions) {
140  myRestrictions = restrictions;
141  }
142 
143  inline void setTimePenalty(double value) {
144  myTimePenalty = value;
145  }
146 
148  inline bool isInternal() const {
149  return myFunction == EDGEFUNC_INTERNAL;
150  }
151 
153  inline bool isCrossing() const {
154  return myFunction == EDGEFUNC_CROSSING;
155  }
156 
158  inline bool isWalkingArea() const {
160  }
161 
162  inline bool isTazConnector() const {
163  return myFunction == EDGEFUNC_CONNECTOR;
164  }
165 
175  void buildTimeLines(const std::string& measure, const bool boundariesOverride);
177 
178 
179 
181 
182 
187  inline SumoXMLEdgeFunc getFunction() const {
188  return myFunction;
189  }
190 
191 
195  inline bool isSink() const {
196  return myAmSink;
197  }
198 
199 
203  double getLength() const {
204  return myLength;
205  }
206 
210  int getNumericalID() const {
211  return myIndex;
212  }
213 
214 
218  double getSpeedLimit() const {
219  return mySpeed;
220  }
221 
223  // sufficient for the astar air-distance heuristic
224  double getLengthGeometryFactor() const;
225 
230  inline double getVClassMaxSpeed(SUMOVehicleClass vclass) const {
231  if (myRestrictions != 0) {
232  std::map<SUMOVehicleClass, double>::const_iterator r = myRestrictions->find(vclass);
233  if (r != myRestrictions->end()) {
234  return r->second;
235  }
236  }
237  return mySpeed;
238  }
239 
240 
244  int getNumLanes() const {
245  return (int) myLanes.size();
246  }
247 
248 
255  bool isConnectedTo(const ROEdge* const e, const ROVehicle* const vehicle) const;
256 
257 
262  inline bool prohibits(const ROVehicle* const vehicle) const {
263  const SUMOVehicleClass vclass = vehicle->getVClass();
264  return (myCombinedPermissions & vclass) != vclass;
265  }
266 
268  return myCombinedPermissions;
269  }
270 
271 
276  bool allFollowersProhibit(const ROVehicle* const vehicle) const;
278 
279 
280 
282 
283 
290  void addEffort(double value, double timeBegin, double timeEnd);
291 
292 
299  void addTravelTime(double value, double timeBegin, double timeEnd);
300 
301 
309  int getNumSuccessors() const;
310 
311 
317 
323 
324 
332  int getNumPredecessors() const;
333 
334 
339  const ROEdgeVector& getPredecessors() const {
340  return myApproachingEdges;
341  }
342 
344  const ROEdge* getNormalBefore() const;
345 
347  const ROEdge* getNormalAfter() const;
348 
356  double getEffort(const ROVehicle* const veh, double time) const;
357 
358 
364  bool hasLoadedTravelTime(double time) const;
365 
366 
373  double getTravelTime(const ROVehicle* const veh, double time) const;
374 
375 
384  static inline double getEffortStatic(const ROEdge* const edge, const ROVehicle* const veh, double time) {
385  return edge->getEffort(veh, time);
386  }
387 
388 
396  static inline double getTravelTimeStatic(const ROEdge* const edge, const ROVehicle* const veh, double time) {
397  return edge->getTravelTime(veh, time);
398  }
399 
400  static inline double getTravelTimeStaticRandomized(const ROEdge* const edge, const ROVehicle* const veh, double time) {
401  return edge->getTravelTime(veh, time) * RandHelper::rand(1., gWeightsRandomFactor);
402  }
403 
404 
410  inline double getMinimumTravelTime(const ROVehicle* const veh) const {
411  if (isTazConnector()) {
412  return 0;
413  } else if (veh != 0) {
414  return myLength / MIN2(veh->getType()->maxSpeed, veh->getChosenSpeedFactor() * mySpeed);
415  } else {
416  return myLength / mySpeed;
417  }
418  }
419 
420 
421  template<PollutantsInterface::EmissionType ET>
422  static double getEmissionEffort(const ROEdge* const edge, const ROVehicle* const veh, double time) {
423  double ret = 0;
424  if (!edge->getStoredEffort(time, ret)) {
425  const SUMOVTypeParameter* const type = veh->getType();
426  const double vMax = MIN2(type->maxSpeed, edge->mySpeed);
428  ret = PollutantsInterface::computeDefault(type->emissionClass, ET, vMax, accel, 0, edge->getTravelTime(veh, time)); // @todo: give correct slope
429  }
430  return ret;
431  }
432 
433 
434  static double getNoiseEffort(const ROEdge* const edge, const ROVehicle* const veh, double time);
436 
437 
439  double getDistanceTo(const ROEdge* other, const bool doBoundaryEstimate = false) const;
440 
441 
443  static const ROEdgeVector& getAllEdges();
444 
446  static int dictSize() {
447  return (int)myEdges.size();
448  };
449 
450  static void setGlobalOptions(const bool interpolate) {
451  myInterpolate = interpolate;
452  }
453 
455  static const Position getStopPosition(const SUMOVehicleParameter::Stop& stop);
456 
458  int getPriority() const {
459  return myPriority;
460  }
461 
462  const RONode* getFromJunction() const {
463  return myFromJunction;
464  }
465 
466  const RONode* getToJunction() const {
467  return myToJunction;
468  }
469 
470 
475  const std::vector<ROLane*>& getLanes() const {
476  return myLanes;
477  }
478 protected:
485  bool getStoredEffort(double time, double& ret) const;
486 
487 
488 
489 protected:
493 
495  const int myIndex;
496 
498  const int myPriority;
499 
501  double mySpeed;
502 
504  double myLength;
505 
512 
517 
519  static bool myInterpolate;
520 
522  static bool myHaveEWarned;
524  static bool myHaveTTWarned;
525 
528 
530 
533 
536 
538  const std::map<SUMOVehicleClass, double>* myRestrictions;
539 
541  std::vector<ROLane*> myLanes;
542 
545 
548 
551 
553 
554 
556  mutable std::map<SUMOVehicleClass, ROEdgeVector> myClassesSuccessorMap;
557 
559  mutable std::map<SUMOVehicleClass, ROConstEdgePairVector> myClassesViaSuccessorMap;
560 
561 #ifdef HAVE_FOX
562  mutable FXMutex myLock;
564 #endif
565 
566 private:
568  ROEdge(const ROEdge& src);
569 
571  ROEdge& operator=(const ROEdge& src);
572 
573 };
574 
575 
576 #endif
577 
578 /****************************************************************************/
579 
static ROEdgeVector myEdges
Definition: ROEdge.h:552
std::map< SUMOVehicleClass, ROEdgeVector > myClassesSuccessorMap
The successors available for a given vClass.
Definition: ROEdge.h:556
static double getEffortStatic(const ROEdge *const edge, const ROVehicle *const veh, double time)
Returns the effort for the given edge.
Definition: ROEdge.h:384
const ROEdgeVector & getPredecessors() const
Returns the edge at the given position from the list of incoming edges.
Definition: ROEdge.h:339
SUMOVehicleClass getVClass() const
Definition: RORoutable.h:108
bool isTazConnector() const
Definition: ROEdge.h:162
double myLength
The length of the edge.
Definition: ROEdge.h:504
void addTravelTime(double value, double timeBegin, double timeEnd)
Adds a travel time value.
Definition: ROEdge.cpp:141
int getNumericalID() const
Returns the index (numeric id) of the edge.
Definition: ROEdge.h:210
A single lane the router may use.
Definition: ROLane.h:51
double mySpeed
The maximum speed allowed on this edge.
Definition: ROEdge.h:501
bool allFollowersProhibit(const ROVehicle *const vehicle) const
Returns whether this edge succeeding edges prohibit the given vehicle to pass them.
Definition: ROEdge.cpp:325
int getNumSuccessors() const
Returns the number of edges this edge is connected to.
Definition: ROEdge.cpp:245
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types...
int getNumLanes() const
Returns the number of lanes this edge has.
Definition: ROEdge.h:244
const std::map< SUMOVehicleClass, double > * myRestrictions
The vClass speed restrictions for this edge.
Definition: ROEdge.h:538
static bool myInterpolate
Information whether to interpolate at interval boundaries.
Definition: ROEdge.h:519
Structure representing possible vehicle parameter.
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
const RONode * getFromJunction() const
Definition: ROEdge.h:462
void setSource(const bool isSource=true)
Sets whether the edge is a source.
Definition: ROEdge.h:123
static double rand(std::mt19937 *rng=0)
Returns a random real number in [0, 1)
Definition: RandHelper.h:60
bool prohibits(const ROVehicle *const vehicle) const
Returns whether this edge prohibits the given vehicle to pass it.
Definition: ROEdge.h:262
double getLengthGeometryFactor() const
return a lower bound on shape.length() / myLength that is
Definition: ROEdge.cpp:319
virtual void addLane(ROLane *lane)
Adds a lane to the edge while loading.
Definition: ROEdge.cpp:92
SUMOVehicleClass vehicleClass
The vehicle&#39;s class.
void setSink(const bool isSink=true)
Sets whether the edge is a sink.
Definition: ROEdge.h:131
ROConstEdgePairVector myFollowingViaEdges
Definition: ROEdge.h:529
bool myAmSource
Definition: ROEdge.h:507
double getEffort(const ROVehicle *const veh, double time) const
Returns the effort for this edge.
Definition: ROEdge.cpp:148
double getLength() const
Returns the length of the edge.
Definition: ROEdge.h:203
std::vector< const ROEdge * > ConstROEdgeVector
Definition: ROEdge.h:57
const RONode * getToJunction() const
Definition: ROEdge.h:466
SVCPermissions myCombinedPermissions
The list of allowed vehicle classes combined across lanes.
Definition: ROEdge.h:544
bool isCrossing() const
return whether this edge is a pedestrian crossing
Definition: ROEdge.h:153
SVCPermissions getPermissions() const
Definition: ROEdge.h:267
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:42
double getChosenSpeedFactor() const
Returns an upper bound for the speed factor of this vehicle.
Definition: ROVehicle.h:112
static double getDefaultAccel(const SUMOVehicleClass vc=SVC_IGNORING)
Returns the default acceleration for the given vehicle class This needs to be a function because the ...
ROEdgeVector myFollowingEdges
List of edges that may be approached from this edge.
Definition: ROEdge.h:527
double getMinimumTravelTime(const ROVehicle *const veh) const
Returns a lower bound for the travel time on this edge without using any stored timeLine.
Definition: ROEdge.h:410
static double getDefaultImperfection(const SUMOVehicleClass vc=SVC_IGNORING)
Returns the default driver&#39;s imperfection (sigma or epsilon in Krauss&#39; model) for the given vehicle c...
int getNumPredecessors() const
Returns the number of edges connected to this edge.
Definition: ROEdge.cpp:254
SumoXMLEdgeFunc myFunction
The function of the edge.
Definition: ROEdge.h:535
std::vector< ROEdge * > ROEdgeVector
Definition: ROEdge.h:54
bool hasLoadedTravelTime(double time) const
Returns whether a travel time for this edge was loaded.
Definition: ROEdge.cpp:178
A vehicle as used by router.
Definition: ROVehicle.h:53
static double getEmissionEffort(const ROEdge *const edge, const ROVehicle *const veh, double time)
Definition: ROEdge.h:422
double myTimePenalty
flat penalty when computing traveltime
Definition: ROEdge.h:550
static double getTravelTimeStatic(const ROEdge *const edge, const ROVehicle *const veh, double time)
Returns the travel time for the given edge.
Definition: ROEdge.h:396
double getDistanceTo(const ROEdge *other, const bool doBoundaryEstimate=false) const
optimistic distance heuristic for use in routing
Definition: ROEdge.cpp:158
double maxSpeed
The vehicle type&#39;s maximum speed [m/s].
RONode * myFromJunction
the junctions for this edge
Definition: ROEdge.h:491
void buildTimeLines(const std::string &measure, const bool boundariesOverride)
Builds the internal representation of the travel time/effort.
Definition: ROEdge.cpp:285
bool myUsingTTTimeLine
Information whether the time line shall be used instead of the length value.
Definition: ROEdge.h:511
const ROEdge * getNormalAfter() const
if this edge is an internal edge, return its first normal successor, otherwise the edge itself ...
Definition: ROEdge.cpp:274
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
static bool myHaveEWarned
Information whether the edge has reported missing weights.
Definition: ROEdge.h:522
bool myUsingETimeLine
Information whether the time line shall be used instead of the length value.
Definition: ROEdge.h:516
std::vector< ROEdge * > ROEdgeVector
Definition: RODFRouteDesc.h:36
void addEffort(double value, double timeBegin, double timeEnd)
Adds a weight value.
Definition: ROEdge.cpp:134
SumoXMLEdgeFunc getFunction() const
Returns the function of the edge.
Definition: ROEdge.h:187
bool myAmSink
whether the edge is a source or a sink
Definition: ROEdge.h:507
Boundary myBoundary
The bounding rectangle of end nodes incoming or outgoing edges for taz connectors or of my own start ...
Definition: ROEdge.h:547
bool getStoredEffort(double time, double &ret) const
Retrieves the stored effort.
Definition: ROEdge.cpp:220
bool isWalkingArea() const
return whether this edge is walking area
Definition: ROEdge.h:158
T MIN2(T a, T b)
Definition: StdDefs.h:74
void setTimePenalty(double value)
Definition: ROEdge.h:143
static const Position getStopPosition(const SUMOVehicleParameter::Stop &stop)
return the coordinates of the center of the given stop
Definition: ROEdge.cpp:342
std::vector< std::pair< const ROEdge *, const ROEdge * > > ROConstEdgePairVector
Definition: ROEdge.h:58
static int dictSize()
Returns the number of edges.
Definition: ROEdge.h:446
std::vector< ROLane * > myLanes
This edge&#39;s lanes.
Definition: ROEdge.h:541
ValueTimeLine< double > myEfforts
Container storing passing time varying over time for the edge.
Definition: ROEdge.h:514
virtual ~ROEdge()
Destructor.
Definition: ROEdge.cpp:84
A basic edge for routing applications.
Definition: ROEdge.h:73
Base class for objects which have an id.
Definition: Named.h:57
double gWeightsRandomFactor
Definition: StdDefs.cpp:31
Definition of vehicle stop (position and duration)
double getCFParam(const SumoXMLAttr attr, const double defaultValue) const
Returns the named value from the map, or the default if it is not contained there.
bool isSink() const
Returns whether the edge acts as a sink.
Definition: ROEdge.h:195
bool isInternal() const
return whether this edge is an internal edge
Definition: ROEdge.h:148
int getPriority() const
get edge priority (road class)
Definition: ROEdge.h:458
const SUMOVTypeParameter * getType() const
Returns the type of the routable.
Definition: RORoutable.h:85
RONode * myToJunction
Definition: ROEdge.h:492
ROEdge(const std::string &id, RONode *from, RONode *to, int index, const int priority)
Constructor.
Definition: ROEdge.cpp:55
ROEdgeVector myApproachingEdges
List of edges that approached this edge.
Definition: ROEdge.h:532
bool isConnectedTo(const ROEdge *const e, const ROVehicle *const vehicle) const
returns the information whether this edge is directly connected to the given
Definition: ROEdge.cpp:422
virtual void addSuccessor(ROEdge *s, ROEdge *via=nullptr, std::string dir="")
Adds information about a connected edge.
Definition: ROEdge.cpp:105
std::map< SUMOVehicleClass, ROConstEdgePairVector > myClassesViaSuccessorMap
The successors with vias available for a given vClass.
Definition: ROEdge.h:559
static const ROEdgeVector & getAllEdges()
Returns all ROEdges.
Definition: ROEdge.cpp:336
double getTravelTime(const ROVehicle *const veh, double time) const
Returns the travel time for this edge.
Definition: ROEdge.cpp:184
SumoXMLEdgeFunc
Numbers representing special SUMO-XML-attribute values for representing edge functions used in netbui...
double getSpeedLimit() const
Returns the speed allowed on this edge.
Definition: ROEdge.h:218
const ROEdgeVector & getSuccessors(SUMOVehicleClass vClass=SVC_IGNORING) const
Returns the following edges, restricted by vClass.
Definition: ROEdge.cpp:350
static double getNoiseEffort(const ROEdge *const edge, const ROVehicle *const veh, double time)
Definition: ROEdge.cpp:209
const std::vector< ROLane * > & getLanes() const
Returns this edge&#39;s lanes.
Definition: ROEdge.h:475
ValueTimeLine< double > myTravelTimes
Container storing passing time varying over time for the edge.
Definition: ROEdge.h:509
static void setGlobalOptions(const bool interpolate)
Definition: ROEdge.h:450
double getVClassMaxSpeed(SUMOVehicleClass vclass) const
Returns the lane&#39;s maximum speed, given a vehicle&#39;s speed limit adaptation.
Definition: ROEdge.h:230
const ROConstEdgePairVector & getViaSuccessors(SUMOVehicleClass vClass=SVC_IGNORING) const
Returns the following edges including vias, restricted by vClass.
Definition: ROEdge.cpp:386
Base class for nodes used by the router.
Definition: RONode.h:46
static bool myHaveTTWarned
Information whether the edge has reported missing weights.
Definition: ROEdge.h:524
const ROEdge * getNormalBefore() const
if this edge is an internal edge, return its first normal predecessor, otherwise the edge itself ...
Definition: ROEdge.cpp:263
void setRestrictions(const std::map< SUMOVehicleClass, double > *restrictions)
Sets the vehicle class specific speed limits of the edge.
Definition: ROEdge.h:139
static double computeDefault(const SUMOEmissionClass c, const EmissionType e, const double v, const double a, const double slope, const double tt, const std::map< int, double > *param=0)
Returns the amount of emitted pollutant given the vehicle type and default values for the state (in m...
static double getTravelTimeStaticRandomized(const ROEdge *const edge, const ROVehicle *const veh, double time)
Definition: ROEdge.h:400
const int myIndex
The index (numeric id) of the edge.
Definition: ROEdge.h:495
ROEdge & operator=(const ROEdge &src)
Invalidated assignment operator.
const int myPriority
The edge priority (road class)
Definition: ROEdge.h:498
SUMOEmissionClass emissionClass
The emission class of this vehicle.
vehicles ignoring classes
void setFunction(SumoXMLEdgeFunc func)
Sets the function of the edge.
Definition: ROEdge.h:115