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.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 // A storage for edge travel times and efforts
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 /****************************************************************************/
A road/street connecting two junctions.
Definition: MSEdge.h:77
bool retrieveExistingTravelTime(const MSEdge *const e, const double t, double &value) const
Returns a travel time for an edge and time if stored.
std::map< const MSEdge *, ValueTimeLine< double > > myTravelTimes
A map of edge->time->travel time.
bool knowsTravelTime(const MSEdge *const e) const
Returns the information whether any travel time is known for the given edge.
void addTravelTime(const MSEdge *const e, double begin, double end, double value)
Adds a travel time information for an edge and a time span.
void removeEffort(const MSEdge *const e)
Removes the effort information for an edge.
bool knowsEffort(const MSEdge *const e) const
Returns the information whether any effort is known for the given edge.
MSEdgeWeightsStorage()
Constructor.
void addEffort(const MSEdge *const e, double begin, double end, double value)
Adds an effort information for an edge and a time span.
std::map< const MSEdge *, ValueTimeLine< double > > myEfforts
A map of edge->time->effort.
bool retrieveExistingEffort(const MSEdge *const e, const double t, double &value) const
Returns an effort for an edge and time if stored.
void removeTravelTime(const MSEdge *const e)
Removes the travel time information for an edge.
bool describesTime(double time) const
Returns whether a value for the given time is known.
T getValue(double time) const
Returns the value for the given time.
Definition: ValueTimeLine.h:93