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