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