Eclipse SUMO - Simulation of Urban MObility
IntermodalEdge.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2022 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
20 // The Edge definition for the Intermodal Router
21 /****************************************************************************/
22 #pragma once
23 #include <config.h>
24 
25 #include <string>
26 #include <vector>
29 #include "IntermodalTrip.h"
30 
31 // ===========================================================================
32 // function definitions
33 // ===========================================================================
34 template <class E, class L>
35 inline const L* getSidewalk(const E* edge, SUMOVehicleClass svc = SVC_PEDESTRIAN) {
36  if (edge == nullptr) {
37  return nullptr;
38  }
39  // prefer lanes that are exclusive to pedestrians
40  const std::vector<L*>& lanes = edge->getLanes();
41  for (const L* const lane : lanes) {
42  if (lane->getPermissions() == svc) {
43  return lane;
44  }
45  }
46  for (const L* const lane : lanes) {
47  if (lane->allowsVehicleClass(svc)) {
48  return lane;
49  }
50  }
51  if (svc != SVC_PEDESTRIAN) {
52  // persons should always be able to use the sidewalk
53  for (const L* const lane : lanes) {
54  if (lane->getPermissions() == SVC_PEDESTRIAN) {
55  return lane;
56  }
57  }
58  for (const L* const lane : lanes) {
59  if (lane->allowsVehicleClass(SVC_PEDESTRIAN)) {
60  return lane;
61  }
62  }
63  }
64  return nullptr;
65 }
66 
67 
68 
69 // ===========================================================================
70 // class definitions
71 // ===========================================================================
73 template<class E, class L, class N, class V>
74 class IntermodalEdge : public Named {
75 public:
76  IntermodalEdge(const std::string id, int numericalID, const E* edge, const std::string& line, const double length = -1) :
77  Named(id),
78  myNumericalID(numericalID),
79  myEdge(edge),
80  myLine(line),
81  myLength(edge == nullptr || length >= 0. ? MAX2(0.0, length) : edge->getLength()),
82  myEfforts(nullptr) { }
83 
84  virtual ~IntermodalEdge() {}
85 
86  virtual bool includeInRoute(bool /* allEdges */) const {
87  return false;
88  }
89 
90  inline const std::string& getLine() const {
91  return myLine;
92  }
93 
94  inline const E* getEdge() const {
95  return myEdge;
96  }
97 
98  int getNumericalID() const {
99  return myNumericalID;
100  }
101 
102  void addSuccessor(IntermodalEdge* const s, IntermodalEdge* const via = nullptr) {
103  myFollowingEdges.push_back(s);
104  myFollowingViaEdges.push_back(std::make_pair(s, via));
105  }
106 
110  myFollowingEdges.clear();
111  myFollowingViaEdges.clear();
112  }
113 
114  bool removeSuccessor(const IntermodalEdge* const edge) {
115  auto it = std::find(myFollowingEdges.begin(), myFollowingEdges.end(), edge);
116  if (it != myFollowingEdges.end()) {
117  myFollowingEdges.erase(it);
118  } else {
119  return false;
120  }
121  for (auto viaIt = myFollowingViaEdges.begin(); viaIt != myFollowingViaEdges.end();) {
122  if (viaIt->first == edge) {
123  viaIt = myFollowingViaEdges.erase(viaIt);
124  } else {
125  ++viaIt;
126  }
127  }
128  return true;
129  }
130 
131  virtual const std::vector<IntermodalEdge*>& getSuccessors(SUMOVehicleClass vClass = SVC_IGNORING) const {
132  UNUSED_PARAMETER(vClass);
133  // the network is already tailored. No need to check for permissions here
134  return myFollowingEdges;
135  }
136 
137  virtual const std::vector<std::pair<const IntermodalEdge*, const IntermodalEdge*> >& getViaSuccessors(SUMOVehicleClass vClass = SVC_IGNORING) const {
138  UNUSED_PARAMETER(vClass);
139  // the network is already tailored. No need to check for permissions here
140  return myFollowingViaEdges;
141  }
142 
143  virtual bool prohibits(const IntermodalTrip<E, N, V>* const /* trip */) const {
144  return false;
145  }
146 
147  virtual bool restricts(const IntermodalTrip<E, N, V>* const /* trip */) const {
148  return false;
149  }
150 
151  virtual inline double getPartialLength(const IntermodalTrip<E, N, V>* const /*trip*/) const {
152  return myLength;
153  }
154 
155 
156  virtual inline double getTravelTime(const IntermodalTrip<E, N, V>* const /* trip */, double /* time */) const {
157  return 0.;
158  }
159 
160  virtual inline double getTravelTimeAggregated(const IntermodalTrip<E, N, V>* const trip, double time) const {
161  return getTravelTime(trip, time);
162  }
163 
165  virtual inline double getIntended(const double /* time */, std::string& /* intended */) const {
166  return 0.;
167  }
168 
169  static inline double getTravelTimeStatic(const IntermodalEdge* const edge, const IntermodalTrip<E, N, V>* const trip, double time) {
170  return edge == nullptr ? 0. : edge->getTravelTime(trip, time);
171  }
172 
173  static inline double getTravelTimeStaticRandomized(const IntermodalEdge* const edge, const IntermodalTrip<E, N, V>* const trip, double time) {
174  return edge == nullptr ? 0. : edge->getTravelTime(trip, time) * RandHelper::rand(1., gWeightsRandomFactor);
175  }
176 
177  static inline double getTravelTimeAggregated(const IntermodalEdge* const edge, const IntermodalTrip<E, N, V>* const trip, double time) {
178  return edge == nullptr ? 0. : edge->getTravelTimeAggregated(trip, time);
179  }
180 
181 
182  virtual double getEffort(const IntermodalTrip<E, N, V>* const /* trip */, double /* time */) const {
183  return 0.;
184  }
185 
186  static inline double getEffortStatic(const IntermodalEdge* const edge, const IntermodalTrip<E, N, V>* const trip, double time) {
187  return edge == nullptr || !edge->hasEffort() ? 0. : edge->getEffort(trip, time);
188  }
189 
191  inline double getLength() const {
192  return myLength;
193  }
194 
195  inline void setLength(const double length) {
196  assert(length >= 0);
197  myLength = length;
198  }
199 
200  inline bool isInternal() const {
201  return myEdge != nullptr && myEdge->isInternal();
202  }
203 
204  virtual bool hasEffort() const {
205  return myEfforts != nullptr;
206  }
207 
208  virtual double getStartPos() const {
209  return 0.;
210  }
211 
212  virtual double getEndPos() const {
213  return myLength;
214  }
215 
216  // only used by AStar
217  inline double getSpeedLimit() const {
218  return myEdge != nullptr ? myEdge->getSpeedLimit() : 200. / 3.6;
219  }
220 
221  // only used by AStar
222  inline double getLengthGeometryFactor() const {
223  return myEdge != nullptr ? myEdge->getLengthGeometryFactor() : 1;
224  }
225 
226  // only used by AStar
227  inline double getDistanceTo(const IntermodalEdge* other) const {
228  return myEdge != nullptr && other->myEdge != nullptr && myEdge != other->myEdge ? myEdge->getDistanceTo(other->myEdge, true) : 0.;
229  }
230 
231  // only used by AStar
232  inline double getMinimumTravelTime(const IntermodalTrip<E, N, V>* const trip) const {
233  return myLength / trip->getMaxSpeed();
234  }
235 
238  return nullptr;
239  }
240 
241 protected:
243  std::vector<IntermodalEdge*> myFollowingEdges;
244 
246  std::vector<std::pair<const IntermodalEdge*, const IntermodalEdge*> > myFollowingViaEdges;
247 
248 private:
250  const int myNumericalID;
251 
253  const E* const myEdge;
254 
256  const std::string myLine;
257 
259  double myLength;
260 
263 
264 private:
267 
270 
271 };
const L * getSidewalk(const E *edge, SUMOVehicleClass svc=SVC_PEDESTRIAN)
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_IGNORING
vehicles ignoring classes
@ SVC_PEDESTRIAN
pedestrian
double gWeightsRandomFactor
Definition: StdDefs.cpp:29
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:30
T MAX2(T a, T b)
Definition: StdDefs.h:80
the base edge type that is given to the internal router (SUMOAbstractRouter)
double getSpeedLimit() const
static double getTravelTimeStatic(const IntermodalEdge *const edge, const IntermodalTrip< E, N, V > *const trip, double time)
double getMinimumTravelTime(const IntermodalTrip< E, N, V > *const trip) const
double getLengthGeometryFactor() const
void setLength(const double length)
virtual double getTravelTime(const IntermodalTrip< E, N, V > *const, double) const
virtual bool restricts(const IntermodalTrip< E, N, V > *const) const
void transferSuccessors(IntermodalEdge *to)
std::vector< IntermodalEdge * > myFollowingEdges
List of edges that may be approached from this edge.
virtual double getPartialLength(const IntermodalTrip< E, N, V > *const) const
bool removeSuccessor(const IntermodalEdge *const edge)
double myLength
adaptable length (for splitted edges)
void addSuccessor(IntermodalEdge *const s, IntermodalEdge *const via=nullptr)
ValueTimeLine< double > * myEfforts
Container for passing effort varying over time for the edge.
IntermodalEdge * getBidiEdge() const
only used by mono-modal routing
const E * getEdge() const
double getLength() const
required by DijkstraRouter et al for external effort computation
std::vector< std::pair< const IntermodalEdge *, const IntermodalEdge * > > myFollowingViaEdges
List of edges that may be approached from this edge with optional internal vias.
double getDistanceTo(const IntermodalEdge *other) const
const E *const myEdge
the original edge
int getNumericalID() const
virtual double getStartPos() const
virtual bool prohibits(const IntermodalTrip< E, N, V > *const) const
virtual ~IntermodalEdge()
const std::string & getLine() const
virtual double getIntended(const double, std::string &) const
get intended vehicle id and departure time of next public transport ride
IntermodalEdge(const IntermodalEdge &src)
Invalidated copy constructor.
virtual double getEffort(const IntermodalTrip< E, N, V > *const, double) const
static double getEffortStatic(const IntermodalEdge *const edge, const IntermodalTrip< E, N, V > *const trip, double time)
virtual const std::vector< std::pair< const IntermodalEdge *, const IntermodalEdge * > > & getViaSuccessors(SUMOVehicleClass vClass=SVC_IGNORING) const
virtual const std::vector< IntermodalEdge * > & getSuccessors(SUMOVehicleClass vClass=SVC_IGNORING) const
virtual bool hasEffort() const
virtual bool includeInRoute(bool) const
IntermodalEdge(const std::string id, int numericalID, const E *edge, const std::string &line, const double length=-1)
virtual double getEndPos() const
IntermodalEdge & operator=(const IntermodalEdge &src)
Invalidated assignment operator.
static double getTravelTimeAggregated(const IntermodalEdge *const edge, const IntermodalTrip< E, N, V > *const trip, double time)
virtual double getTravelTimeAggregated(const IntermodalTrip< E, N, V > *const trip, double time) const
bool isInternal() const
const int myNumericalID
the index in myEdges
const std::string myLine
public transport line or ped vs car
static double getTravelTimeStaticRandomized(const IntermodalEdge *const edge, const IntermodalTrip< E, N, V > *const trip, double time)
the "vehicle" type that is given to the internal router (SUMOAbstractRouter)
double getMaxSpeed() const
Base class for objects which have an id.
Definition: Named.h:54
static double rand(SumoRNG *rng=nullptr)
Returns a random real number in [0, 1)
Definition: RandHelper.h:119