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.dev/sumo
3 // Copyright (C) 2001-2024 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>
30 #include <utils/common/Named.h>
31 #include "IntermodalTrip.h"
32 
33 // ===========================================================================
34 // function definitions
35 // ===========================================================================
36 template <class E, class L>
37 inline const L* getSidewalk(const E* edge, SUMOVehicleClass svc = SVC_PEDESTRIAN) {
38  if (edge == nullptr) {
39  return nullptr;
40  }
41  // prefer lanes that are exclusive to pedestrians
42  const std::vector<L*>& lanes = edge->getLanes();
43  for (const L* const lane : lanes) {
44  if (lane->getPermissions() == svc) {
45  return lane;
46  }
47  }
48  for (const L* const lane : lanes) {
49  if (lane->allowsVehicleClass(svc)) {
50  return lane;
51  }
52  }
53  if (svc != SVC_PEDESTRIAN) {
54  // persons should always be able to use the sidewalk
55  for (const L* const lane : lanes) {
56  if (lane->getPermissions() == SVC_PEDESTRIAN) {
57  return lane;
58  }
59  }
60  for (const L* const lane : lanes) {
61  if (lane->allowsVehicleClass(SVC_PEDESTRIAN)) {
62  return lane;
63  }
64  }
65  }
66  return nullptr;
67 }
68 
69 
70 
71 // ===========================================================================
72 // class definitions
73 // ===========================================================================
75 template<class E, class L, class N, class V>
76 class IntermodalEdge : public Named {
77 public:
78  IntermodalEdge(const std::string id, int numericalID, const E* edge, const std::string& line, const double length = -1) :
79  Named(id),
80  myNumericalID(numericalID),
81  myEdge(edge),
82  myLine(line),
83  myLength(edge == nullptr || length >= 0. ? MAX2(0.0, length) : edge->getLength()),
84  myEfforts(nullptr) { }
85 
86  virtual ~IntermodalEdge() {}
87 
88  virtual bool includeInRoute(bool /* allEdges */) const {
89  return false;
90  }
91 
92  inline const std::string& getLine() const {
93  return myLine;
94  }
95 
96  inline const E* getEdge() const {
97  return myEdge;
98  }
99 
100  int getNumericalID() const {
101  return myNumericalID;
102  }
103 
104  void addSuccessor(IntermodalEdge* const s, IntermodalEdge* const via = nullptr) {
105  myFollowingEdges.push_back(s);
106  myFollowingViaEdges.push_back(std::make_pair(s, via));
107  }
108 
112  myFollowingEdges.clear();
113  myFollowingViaEdges.clear();
114  }
115 
116  bool removeSuccessor(const IntermodalEdge* const edge) {
117  auto it = std::find(myFollowingEdges.begin(), myFollowingEdges.end(), edge);
118  if (it != myFollowingEdges.end()) {
119  myFollowingEdges.erase(it);
120  } else {
121  return false;
122  }
123  for (auto viaIt = myFollowingViaEdges.begin(); viaIt != myFollowingViaEdges.end();) {
124  if (viaIt->first == edge) {
125  viaIt = myFollowingViaEdges.erase(viaIt);
126  } else {
127  ++viaIt;
128  }
129  }
130  return true;
131  }
132 
133  virtual const std::vector<IntermodalEdge*>& getSuccessors(SUMOVehicleClass vClass = SVC_IGNORING) const {
134  UNUSED_PARAMETER(vClass);
135  // the network is already tailored. No need to check for permissions here
136  return myFollowingEdges;
137  }
138 
139  virtual const std::vector<std::pair<const IntermodalEdge*, const IntermodalEdge*> >& getViaSuccessors(SUMOVehicleClass vClass = SVC_IGNORING, bool ignoreTransientPermissions = false) const {
140  UNUSED_PARAMETER(vClass);
141  UNUSED_PARAMETER(ignoreTransientPermissions);
142  // the network is already tailored. No need to check for permissions here
143  return myFollowingViaEdges;
144  }
145 
146  virtual bool prohibits(const IntermodalTrip<E, N, V>* const /* trip */) const {
147  return false;
148  }
149 
150  virtual bool restricts(const IntermodalTrip<E, N, V>* const /* trip */) const {
151  return false;
152  }
153 
154  virtual inline double getPartialLength(const IntermodalTrip<E, N, V>* const /*trip*/) const {
155  return myLength;
156  }
157 
158 
159  virtual inline double getTravelTime(const IntermodalTrip<E, N, V>* const /* trip */, double /* time */) const {
160  return 0.;
161  }
162 
163  virtual inline double getTravelTimeAggregated(const IntermodalTrip<E, N, V>* const trip, double time) const {
164  return getTravelTime(trip, time);
165  }
166 
168  virtual inline double getIntended(const double /* time */, std::string& /* intended */) const {
169  return 0.;
170  }
171 
172  static inline double getTravelTimeStatic(const IntermodalEdge* const edge, const IntermodalTrip<E, N, V>* const trip, double time) {
173  return edge == nullptr ? 0. : edge->getTravelTime(trip, time);
174  }
175 
176  static inline double getTravelTimeStaticRandomized(const IntermodalEdge* const edge, const IntermodalTrip<E, N, V>* const trip, double time) {
177  return edge == nullptr ? 0. : edge->getTravelTime(trip, time) * RandHelper::rand(1., gWeightsRandomFactor);
178  }
179 
180  static inline double getTravelTimeAggregated(const IntermodalEdge* const edge, const IntermodalTrip<E, N, V>* const trip, double time) {
181  return edge == nullptr ? 0. : edge->getTravelTimeAggregated(trip, time);
182  }
183 
184 
185  virtual double getEffort(const IntermodalTrip<E, N, V>* const /* trip */, double /* time */) const {
186  return 0.;
187  }
188 
189  static inline double getEffortStatic(const IntermodalEdge* const edge, const IntermodalTrip<E, N, V>* const trip, double time) {
190  return edge == nullptr || !edge->hasEffort() ? 0. : edge->getEffort(trip, time);
191  }
192 
194  inline double getLength() const {
195  return myLength;
196  }
197 
198  inline void setLength(const double length) {
199  assert(length >= 0);
200  myLength = length;
201  }
202 
203  inline bool isInternal() const {
204  return myEdge != nullptr && myEdge->isInternal();
205  }
206 
207  virtual bool hasEffort() const {
208  return myEfforts != nullptr;
209  }
210 
211  virtual double getStartPos() const {
212  return 0.;
213  }
214 
215  virtual double getEndPos() const {
216  return myLength;
217  }
218 
219  // only used by AStar
220  inline double getSpeedLimit() const {
221  return myEdge != nullptr ? myEdge->getSpeedLimit() : 200. / 3.6;
222  }
223 
224  // only used by AStar
225  inline double getLengthGeometryFactor() const {
226  return myEdge != nullptr ? myEdge->getLengthGeometryFactor() : 1;
227  }
228 
229  // only used by AStar
230  inline double getDistanceTo(const IntermodalEdge* other) const {
231  return myEdge != nullptr && other->myEdge != nullptr && myEdge != other->myEdge ? myEdge->getDistanceTo(other->myEdge, true) : 0.;
232  }
233 
234  // only used by AStar
235  inline double getMinimumTravelTime(const IntermodalTrip<E, N, V>* const trip) const {
236  return myLength / trip->getMaxSpeed();
237  }
238 
241  return nullptr;
242  }
243 
244 protected:
246  std::vector<IntermodalEdge*> myFollowingEdges;
247 
249  std::vector<std::pair<const IntermodalEdge*, const IntermodalEdge*> > myFollowingViaEdges;
250 
251 private:
253  const int myNumericalID;
254 
256  const E* const myEdge;
257 
259  const std::string myLine;
260 
262  double myLength;
263 
266 
267 private:
270 
273 
274 };
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:32
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:30
T MAX2(T a, T b)
Definition: StdDefs.h:82
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
virtual const std::vector< std::pair< const IntermodalEdge *, const IntermodalEdge * > > & getViaSuccessors(SUMOVehicleClass vClass=SVC_IGNORING, bool ignoreTransientPermissions=false) 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< 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.cpp:94