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-2020 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 // ===========================================================================
33 // class definitions
34 // ===========================================================================
36 template<class E, class L, class N, class V>
37 class IntermodalEdge : public Named {
38 public:
39  IntermodalEdge(const std::string id, int numericalID, const E* edge, const std::string& line, const double length = -1) :
40  Named(id),
41  myNumericalID(numericalID),
42  myEdge(edge),
43  myLine(line),
44  myLength(edge == nullptr || length >= 0. ? MAX2(0.0, length) : edge->getLength()),
45  myEfforts(nullptr) { }
46 
47  virtual ~IntermodalEdge() {}
48 
49  virtual bool includeInRoute(bool /* allEdges */) const {
50  return false;
51  }
52 
53  inline const std::string& getLine() const {
54  return myLine;
55  }
56 
57  inline const E* getEdge() const {
58  return myEdge;
59  }
60 
61  int getNumericalID() const {
62  return myNumericalID;
63  }
64 
65  void addSuccessor(IntermodalEdge* const s, IntermodalEdge* const via = nullptr) {
66  myFollowingEdges.push_back(s);
67  myFollowingViaEdges.push_back(std::make_pair(s, via));
68  }
69 
73  myFollowingEdges.clear();
74  myFollowingViaEdges.clear();
75  }
76 
77  bool removeSuccessor(const IntermodalEdge* const edge) {
78  auto it = std::find(myFollowingEdges.begin(), myFollowingEdges.end(), edge);
79  if (it != myFollowingEdges.end()) {
80  myFollowingEdges.erase(it);
81  } else {
82  return false;
83  }
84  for (auto viaIt = myFollowingViaEdges.begin(); viaIt != myFollowingViaEdges.end();) {
85  if (viaIt->first == edge) {
86  viaIt = myFollowingViaEdges.erase(viaIt);
87  } else {
88  ++viaIt;
89  }
90  }
91  return true;
92  }
93 
94  virtual const std::vector<IntermodalEdge*>& getSuccessors(SUMOVehicleClass vClass = SVC_IGNORING) const {
95  UNUSED_PARAMETER(vClass);
96  // the network is already tailored. No need to check for permissions here
97  return myFollowingEdges;
98  }
99 
100  virtual const std::vector<std::pair<const IntermodalEdge*, const IntermodalEdge*> >& getViaSuccessors(SUMOVehicleClass vClass = SVC_IGNORING) const {
101  UNUSED_PARAMETER(vClass);
102  // the network is already tailored. No need to check for permissions here
103  return myFollowingViaEdges;
104  }
105 
106  virtual bool prohibits(const IntermodalTrip<E, N, V>* const /* trip */) const {
107  return false;
108  }
109 
110  virtual bool restricts(const IntermodalTrip<E, N, V>* const /* trip */) const {
111  return false;
112  }
113 
114  virtual inline double getPartialLength(const IntermodalTrip<E, N, V>* const /*trip*/) const {
115  return myLength;
116  }
117 
118 
119  virtual inline double getTravelTime(const IntermodalTrip<E, N, V>* const /* trip */, double /* time */) const {
120  return 0.;
121  }
122 
123  virtual inline double getTravelTimeAggregated(const IntermodalTrip<E, N, V>* const trip, double time) const {
124  return getTravelTime(trip, time);
125  }
126 
128  virtual inline double getIntended(const double /* time */, std::string& /* intended */) const {
129  return 0.;
130  }
131 
132  static inline double getTravelTimeStatic(const IntermodalEdge* const edge, const IntermodalTrip<E, N, V>* const trip, double time) {
133  return edge == nullptr ? 0. : edge->getTravelTime(trip, time);
134  }
135 
136  static inline double getTravelTimeStaticRandomized(const IntermodalEdge* const edge, const IntermodalTrip<E, N, V>* const trip, double time) {
137  return edge == nullptr ? 0. : edge->getTravelTime(trip, time) * RandHelper::rand(1., gWeightsRandomFactor);
138  }
139 
140  static inline double getTravelTimeAggregated(const IntermodalEdge* const edge, const IntermodalTrip<E, N, V>* const trip, double time) {
141  return edge == nullptr ? 0. : edge->getTravelTimeAggregated(trip, time);
142  }
143 
144 
145  virtual double getEffort(const IntermodalTrip<E, N, V>* const /* trip */, double /* time */) const {
146  return 0.;
147  }
148 
149  static inline double getEffortStatic(const IntermodalEdge* const edge, const IntermodalTrip<E, N, V>* const trip, double time) {
150  return edge == nullptr || !edge->hasEffort() ? 0. : edge->getEffort(trip, time);
151  }
152 
154  inline double getLength() const {
155  return myLength;
156  }
157 
158  inline void setLength(const double length) {
159  myLength = length;
160  }
161 
162  inline bool isInternal() const {
163  return myEdge != nullptr && myEdge->isInternal();
164  }
165 
166  virtual bool hasEffort() const {
167  return myEfforts != nullptr;
168  }
169 
170  virtual double getStartPos() const {
171  return 0.;
172  }
173 
174  virtual double getEndPos() const {
175  return myLength;
176  }
177 
178  // only used by AStar
179  inline double getSpeedLimit() const {
180  return myEdge != nullptr ? myEdge->getSpeedLimit() : 200. / 3.6;
181  }
182 
183  // only used by AStar
184  inline double getLengthGeometryFactor() const {
185  return myEdge != nullptr ? myEdge->getLengthGeometryFactor() : 1;
186  }
187 
188  // only used by AStar
189  inline double getDistanceTo(const IntermodalEdge* other) const {
190  return myEdge != nullptr && other->myEdge != nullptr && myEdge != other->myEdge ? myEdge->getDistanceTo(other->myEdge, true) : 0.;
191  }
192 
193  // only used by AStar
194  inline double getMinimumTravelTime(const IntermodalTrip<E, N, V>* const trip) const {
195  return myLength / trip->getMaxSpeed();
196  }
197 
200  return nullptr;
201  }
202 
203 protected:
205  std::vector<IntermodalEdge*> myFollowingEdges;
206 
208  std::vector<std::pair<const IntermodalEdge*, const IntermodalEdge*> > myFollowingViaEdges;
209 
210 private:
212  const int myNumericalID;
213 
215  const E* const myEdge;
216 
218  const std::string myLine;
219 
221  double myLength;
222 
225 
226 private:
229 
232 
233 };
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_IGNORING
vehicles ignoring classes
double gWeightsRandomFactor
Definition: StdDefs.cpp:29
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:29
T MAX2(T a, T b)
Definition: StdDefs.h:79
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:53
static double rand(std::mt19937 *rng=nullptr)
Returns a random real number in [0, 1)
Definition: RandHelper.h:51