Eclipse SUMO - Simulation of Urban MObility
MSEdgeWeightsStorage.cpp
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 /****************************************************************************/
16 // A storage for edge travel times and efforts
17 /****************************************************************************/
18 
19 // ===========================================================================
20 // included modules
21 // ===========================================================================
22 #include <config.h>
23 
24 #include "MSEdgeWeightsStorage.h"
25 
26 
27 // ===========================================================================
28 // method definitions
29 // ===========================================================================
31 }
32 
33 
35 }
36 
37 
38 bool
39 MSEdgeWeightsStorage::retrieveExistingTravelTime(const MSEdge* const e, const double t, double& value) const {
40  std::map<const MSEdge*, ValueTimeLine<double> >::const_iterator i = myTravelTimes.find(e);
41  if (i == myTravelTimes.end()) {
42  return false;
43  }
44  const ValueTimeLine<double>& tl = (*i).second;
45  if (!tl.describesTime(t)) {
46  return false;
47  }
48  value = tl.getValue(t);
49  return true;
50 }
51 
52 
53 bool
54 MSEdgeWeightsStorage::retrieveExistingEffort(const MSEdge* const e, const double t, double& value) const {
55  std::map<const MSEdge*, ValueTimeLine<double> >::const_iterator i = myEfforts.find(e);
56  if (i == myEfforts.end()) {
57  return false;
58  }
59  const ValueTimeLine<double>& tl = (*i).second;
60  if (!tl.describesTime(t)) {
61  return false;
62  }
63  value = tl.getValue(t);
64  return true;
65 }
66 
67 
68 void
70  double begin, double end,
71  double value) {
72  std::map<const MSEdge*, ValueTimeLine<double> >::iterator i = myTravelTimes.find(e);
73  if (i == myTravelTimes.end()) {
75  i = myTravelTimes.find(e);
76  }
77  (*i).second.add(begin, end, value);
78 }
79 
80 
81 void
83  double begin, double end,
84  double value) {
85  std::map<const MSEdge*, ValueTimeLine<double> >::iterator i = myEfforts.find(e);
86  if (i == myEfforts.end()) {
88  i = myEfforts.find(e);
89  }
90  (*i).second.add(begin, end, value);
91 }
92 
93 
94 void
96  std::map<const MSEdge*, ValueTimeLine<double> >::iterator i = myTravelTimes.find(e);
97  if (i != myTravelTimes.end()) {
98  myTravelTimes.erase(i);
99  }
100 }
101 
102 
103 void
105  std::map<const MSEdge*, ValueTimeLine<double> >::iterator i = myEfforts.find(e);
106  if (i != myEfforts.end()) {
107  myEfforts.erase(i);
108  }
109 }
110 
111 
112 bool
114  return myTravelTimes.find(e) != myTravelTimes.end();
115 }
116 
117 
118 bool
120  return myEfforts.find(e) != myEfforts.end();
121 }
122 
123 
124 
125 /****************************************************************************/
126 
MSEdgeWeightsStorage::knowsEffort
bool knowsEffort(const MSEdge *const e) const
Returns the information whether any effort is known for the given edge.
Definition: MSEdgeWeightsStorage.cpp:119
MSEdgeWeightsStorage::MSEdgeWeightsStorage
MSEdgeWeightsStorage()
Constructor.
Definition: MSEdgeWeightsStorage.cpp:30
ValueTimeLine::describesTime
bool describesTime(double time) const
Returns whether a value for the given time is known.
Definition: ValueTimeLine.h:112
MSEdgeWeightsStorage::addEffort
void addEffort(const MSEdge *const e, double begin, double end, double value)
Adds an effort information for an edge and a time span.
Definition: MSEdgeWeightsStorage.cpp:82
MSEdgeWeightsStorage::knowsTravelTime
bool knowsTravelTime(const MSEdge *const e) const
Returns the information whether any travel time is known for the given edge.
Definition: MSEdgeWeightsStorage.cpp:113
MSEdgeWeightsStorage::myEfforts
std::map< const MSEdge *, ValueTimeLine< double > > myEfforts
A map of edge->time->effort.
Definition: MSEdgeWeightsStorage.h:120
MSEdgeWeightsStorage::retrieveExistingTravelTime
bool retrieveExistingTravelTime(const MSEdge *const e, const double t, double &value) const
Returns a travel time for an edge and time if stored.
Definition: MSEdgeWeightsStorage.cpp:39
MSEdgeWeightsStorage.h
MSEdge
A road/street connecting two junctions.
Definition: MSEdge.h:78
MSEdgeWeightsStorage::removeEffort
void removeEffort(const MSEdge *const e)
Removes the effort information for an edge.
Definition: MSEdgeWeightsStorage.cpp:104
MSEdgeWeightsStorage::retrieveExistingEffort
bool retrieveExistingEffort(const MSEdge *const e, const double t, double &value) const
Returns an effort for an edge and time if stored.
Definition: MSEdgeWeightsStorage.cpp:54
ValueTimeLine::getValue
T getValue(double time) const
Returns the value for the given time.
Definition: ValueTimeLine.h:94
MSEdgeWeightsStorage::addTravelTime
void addTravelTime(const MSEdge *const e, double begin, double end, double value)
Adds a travel time information for an edge and a time span.
Definition: MSEdgeWeightsStorage.cpp:69
config.h
MSEdgeWeightsStorage::~MSEdgeWeightsStorage
~MSEdgeWeightsStorage()
Destructor.
Definition: MSEdgeWeightsStorage.cpp:34
MSEdgeWeightsStorage::removeTravelTime
void removeTravelTime(const MSEdge *const e)
Removes the travel time information for an edge.
Definition: MSEdgeWeightsStorage.cpp:95
ValueTimeLine< double >
MSEdgeWeightsStorage::myTravelTimes
std::map< const MSEdge *, ValueTimeLine< double > > myTravelTimes
A map of edge->time->travel time.
Definition: MSEdgeWeightsStorage.h:117