Eclipse SUMO - Simulation of Urban MObility
CarEdge.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 /****************************************************************************/
18 // The CarEdge is a special intermodal edge representing the SUMO network edge
19 /****************************************************************************/
20 #pragma once
21 #include <config.h>
22 
23 #ifdef HAVE_FOX
24 #include <fx.h>
25 #endif
26 #include "IntermodalEdge.h"
27 
28 
29 // ===========================================================================
30 // class definitions
31 // ===========================================================================
33 template<class E, class L, class N, class V>
34 class CarEdge : public IntermodalEdge<E, L, N, V> {
35 private:
37 
38 public:
39  CarEdge(int numericalID, const E* edge, const double pos = -1.) :
40  _IntermodalEdge(edge->getID() + "_car" + toString(pos), numericalID, edge, "!car"),
41  myStartPos(pos >= 0 ? pos : 0.) { }
42 
43  bool includeInRoute(bool /* allEdges */) const {
44  return true;
45  }
46 
47  const std::vector<_IntermodalEdge*>& getSuccessors(SUMOVehicleClass vClass = SVC_IGNORING) const {
48  if (vClass == SVC_IGNORING) {
49  return this->myFollowingEdges;
50  }
51 #ifdef HAVE_FOX
52  FXMutexLock locker(myLock);
53 #endif
54  typename std::map<SUMOVehicleClass, std::vector<_IntermodalEdge*> >::const_iterator i = myClassesSuccessorMap.find(vClass);
55  if (i != myClassesSuccessorMap.end()) {
56  // can use cached value
57  return i->second;
58  } else {
59  // this vClass is requested for the first time. rebuild all successors
60  const std::set<const E*> classedCarFollowers = std::set<const E*>(this->getEdge()->getSuccessors(vClass).begin(), this->getEdge()->getSuccessors(vClass).end());
61  for (_IntermodalEdge* const e : this->myFollowingEdges) {
62  if (!e->includeInRoute(false) || e->getEdge() == this->getEdge() || classedCarFollowers.count(e->getEdge()) > 0) {
63  myClassesSuccessorMap[vClass].push_back(e);
64  }
65  }
66  return myClassesSuccessorMap[vClass];
67  }
68  }
69 
70  virtual const std::vector<std::pair<const _IntermodalEdge*, const _IntermodalEdge*> >& getViaSuccessors(SUMOVehicleClass vClass = SVC_IGNORING) const {
71  if (vClass == SVC_IGNORING) {
72  return this->myFollowingViaEdges;
73  }
74 #ifdef HAVE_FOX
75  FXMutexLock locker(myLock);
76 #endif
77  typename std::map<SUMOVehicleClass, std::vector<std::pair<const _IntermodalEdge*, const _IntermodalEdge*> > >::const_iterator i = myClassesViaSuccessorMap.find(vClass);
78  if (i != myClassesViaSuccessorMap.end()) {
79  // can use cached value
80  return i->second;
81  } else {
82  // this vClass is requested for the first time. rebuild all successors
83  std::set<const E*> classedCarFollowers;
84  for (const auto& pair : this->getEdge()->getViaSuccessors(vClass)) {
85  classedCarFollowers.insert(pair.first);
86  }
87  for (const std::pair<const _IntermodalEdge*, const _IntermodalEdge*>& e : this->myFollowingViaEdges) {
88  if (!e.first->includeInRoute(false) || e.first->getEdge() == this->getEdge() || classedCarFollowers.count(e.first->getEdge()) > 0) {
89  myClassesViaSuccessorMap[vClass].push_back(e);
90  }
91  }
92  return myClassesViaSuccessorMap[vClass];
93  }
94  }
95 
96  bool prohibits(const IntermodalTrip<E, N, V>* const trip) const {
97  return trip->vehicle == 0 || this->getEdge()->prohibits(trip->vehicle);
98  }
99 
100  double getPartialLength(const IntermodalTrip<E, N, V>* const trip) const {
101  double length = this->getLength();
102  // checking arrivalPos first to have it correct for identical depart and arrival edge
103  if (this->getEdge() == trip->to && trip->arrivalPos >= myStartPos && trip->arrivalPos < myStartPos + this->getLength()) {
104  length = trip->arrivalPos - myStartPos;
105  }
106  if (this->getEdge() == trip->from && trip->departPos >= myStartPos && trip->departPos < myStartPos + this->getLength()) {
107  length -= trip->departPos - myStartPos;
108  }
109  return length;
110  }
111 
112  double getTravelTime(const IntermodalTrip<E, N, V>* const trip, double time) const {
113  assert(E::getTravelTimeStatic(this->getEdge(), trip->vehicle, time) >= 0.);
114  return getPartialTravelTime(E::getTravelTimeStatic(this->getEdge(), trip->vehicle, time), trip);
115  }
116 
117  double getTravelTimeAggregated(const IntermodalTrip<E, N, V>* const trip, double time) const {
118  assert(E::getTravelTimeAggregated(this->getEdge(), trip->vehicle, time) >= 0.);
119  return getPartialTravelTime(E::getTravelTimeAggregated(this->getEdge(), trip->vehicle, time), trip);
120  }
121 
122  double getStartPos() const {
123  return myStartPos;
124  }
125 
126  double getEndPos() const {
127  return myStartPos + this->getLength();
128  }
129 
130 private:
131 
132  inline double getPartialTravelTime(double fullTravelTime, const IntermodalTrip<E, N, V>* const trip) const {
133  const double distTravelled = getPartialLength(trip);
134  assert(fullTravelTime * distTravelled / this->getEdge()->getLength() >= 0.);
135  return fullTravelTime * distTravelled / this->getEdge()->getLength();
136  }
137 
138 private:
140  const double myStartPos;
141 
143  mutable std::map<SUMOVehicleClass, std::vector<_IntermodalEdge*> > myClassesSuccessorMap;
144 
146  mutable std::map<SUMOVehicleClass, std::vector<std::pair<const _IntermodalEdge*, const _IntermodalEdge*> > > myClassesViaSuccessorMap;
147 
148 #ifdef HAVE_FOX
150  mutable FXMutex myLock;
151 #endif
152 };
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_IGNORING
vehicles ignoring classes
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:44
the car edge type that is given to the internal router (SUMOAbstractRouter)
Definition: CarEdge.h:34
CarEdge(int numericalID, const E *edge, const double pos=-1.)
Definition: CarEdge.h:39
double getEndPos() const
Definition: CarEdge.h:126
std::map< SUMOVehicleClass, std::vector< _IntermodalEdge * > > myClassesSuccessorMap
The successors available for a given vClass.
Definition: CarEdge.h:143
double getTravelTimeAggregated(const IntermodalTrip< E, N, V > *const trip, double time) const
Definition: CarEdge.h:117
std::map< SUMOVehicleClass, std::vector< std::pair< const _IntermodalEdge *, const _IntermodalEdge * > > > myClassesViaSuccessorMap
The successors available for a given vClass.
Definition: CarEdge.h:146
double getStartPos() const
Definition: CarEdge.h:122
double getPartialTravelTime(double fullTravelTime, const IntermodalTrip< E, N, V > *const trip) const
Definition: CarEdge.h:132
bool prohibits(const IntermodalTrip< E, N, V > *const trip) const
Definition: CarEdge.h:96
virtual const std::vector< std::pair< const _IntermodalEdge *, const _IntermodalEdge * > > & getViaSuccessors(SUMOVehicleClass vClass=SVC_IGNORING) const
Definition: CarEdge.h:70
bool includeInRoute(bool) const
Definition: CarEdge.h:43
double getTravelTime(const IntermodalTrip< E, N, V > *const trip, double time) const
Definition: CarEdge.h:112
const std::vector< _IntermodalEdge * > & getSuccessors(SUMOVehicleClass vClass=SVC_IGNORING) const
Definition: CarEdge.h:47
double getPartialLength(const IntermodalTrip< E, N, V > *const trip) const
Definition: CarEdge.h:100
const double myStartPos
the starting position for split edges
Definition: CarEdge.h:140
IntermodalEdge< E, L, N, V > _IntermodalEdge
Definition: CarEdge.h:36
the base edge type that is given to the internal router (SUMOAbstractRouter)
std::vector< IntermodalEdge * > myFollowingEdges
List of edges that may be approached from this edge.
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.
the "vehicle" type that is given to the internal router (SUMOAbstractRouter)
const E *const to
const double departPos
const E *const from
const double arrivalPos
const V *const vehicle
const std::string & getID() const
Returns the id.
Definition: Named.h:73