Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/utils/xml/SAXWeightsHandler.h
169678 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2007-2025 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
/****************************************************************************/
14
/// @file SAXWeightsHandler.h
15
/// @author Daniel Krajzewicz
16
/// @author Jakob Erdmann
17
/// @author Michael Behrisch
18
/// @date Fri, 30 Mar 2007
19
///
20
// An XML-handler for network weights
21
/****************************************************************************/
22
#pragma once
23
#include <config.h>
24
25
#include <string>
26
#include <utils/xml/SUMOSAXHandler.h>
27
#include <utils/common/SUMOTime.h>
28
29
30
// ===========================================================================
31
// class definitions
32
// ===========================================================================
33
/**
34
* @class SAXWeightsHandler
35
* @brief An XML-handler for network weights
36
*
37
* As network weights are used both in the simulation and the routers, a base
38
* class for loading them was built. Instances of this class should be supplied
39
* with at least one definition about what shall be retrieved
40
* (ToRetrieveDefinition, defined as inner class) which also contains the information
41
* about the retriever (EdgeFloatTimeLineRetriever, defined as inner class).
42
*
43
* The ToRetrieveDefinition names the attribute which the SAXWeightsHandler shall
44
* parse and reporte. Within the parsed xml-file these attributes may be embedded
45
* in "lane" or "edge" elements, one for each edge or for each lane (see below).
46
* These elements should be embedded in interval-tags which specify the time the
47
* weight is valid at.
48
* The boolean "edgeBased" tells SAXWeightsHandler whether the weights are supplied
49
* on edge- or on lane-basis (whether it shall parse the "edge" or the "lane" elements).
50
*
51
* Examples for files the SAXWeightsHandler can handle are the edgedump and the lanedump
52
* generated by the simulation.
53
*
54
* The EdgeFloatTimeLineRetriever to which read values will be reported should have the
55
* method "addEdgeWeight" implemented. It wil be supplied with the current edge name,
56
* the interval the weight is valid for and the value.
57
*/
58
class SAXWeightsHandler : public SUMOSAXHandler {
59
public:
60
/**
61
* @class EdgeFloatTimeLineRetriever
62
* @brief Interface for a class which obtains read weights for named edges
63
*/
64
class EdgeFloatTimeLineRetriever {
65
66
public:
67
/// @brief Constructor
68
EdgeFloatTimeLineRetriever() { }
69
70
/// @brief Destructor
71
virtual ~EdgeFloatTimeLineRetriever() { }
72
73
/** @brief Adds a weight for a given edge and time period
74
*
75
* @param[in] id The id of the object to add a weight for
76
* @param[in] val The weight
77
* @param[in] beg The begin of the interval the weight is valid for
78
* @param[in] end The end of the interval the weight is valid for
79
*/
80
virtual void addEdgeWeight(const std::string& id, double val, double beg, double end) const {
81
UNUSED_PARAMETER(id);
82
UNUSED_PARAMETER(val);
83
UNUSED_PARAMETER(beg);
84
UNUSED_PARAMETER(end);
85
}
86
87
virtual void addEdgeRelWeight(const std::string& from, const std::string& to,
88
double val, double beg, double end) const {
89
UNUSED_PARAMETER(from);
90
UNUSED_PARAMETER(to);
91
UNUSED_PARAMETER(val);
92
UNUSED_PARAMETER(beg);
93
UNUSED_PARAMETER(end);
94
}
95
96
/// @note: note sure why the other functions are const
97
virtual void addTazRelWeight(const std::string intervalID, const std::string& from, const std::string& to,
98
double val, double beg, double end) {
99
UNUSED_PARAMETER(intervalID);
100
UNUSED_PARAMETER(from);
101
UNUSED_PARAMETER(to);
102
UNUSED_PARAMETER(val);
103
UNUSED_PARAMETER(beg);
104
UNUSED_PARAMETER(end);
105
}
106
107
private:
108
/// @brief we made the assignment operator invalid
109
EdgeFloatTimeLineRetriever& operator=(const EdgeFloatTimeLineRetriever&) = delete;
110
};
111
112
/**
113
* @class ToRetrieveDefinition
114
* @brief Complete definition about what shall be retrieved and where to store it
115
*/
116
class ToRetrieveDefinition {
117
public:
118
/// @brief Constructor
119
ToRetrieveDefinition(const std::string& attributeName, bool edgeBased,
120
EdgeFloatTimeLineRetriever& destination);
121
122
/// Destructor
123
~ToRetrieveDefinition();
124
125
public:
126
/// @brief The attribute name that shall be parsed
127
std::string myAttributeName;
128
129
/// @brief Information whether edge values shall be used (lane value if false)
130
bool myAmEdgeBased;
131
132
/// @brief The class that shall be called when new data is avaiable
133
EdgeFloatTimeLineRetriever& myDestination;
134
135
/// @brief Aggregated value over the lanes read within the current edge
136
double myAggValue;
137
138
/// @brief The number of lanes read for the current edge
139
int myNoLanes;
140
141
/// @brief Information whether the attribute has been found for the current edge
142
bool myHadAttribute;
143
144
/// @brief Information whether the attribute was found to contain non-numerical data (for any edge)
145
bool myHadNonNumeric;
146
147
private:
148
/// @brief Invalidated copy constructor.
149
ToRetrieveDefinition(const ToRetrieveDefinition&) = delete;
150
151
/// @brief Invalidated assignment operator.
152
ToRetrieveDefinition& operator=(const ToRetrieveDefinition&) = delete;
153
};
154
155
/**
156
* @brief Constructor
157
*
158
* Gets a list of retriever definitions. Please note that the retrievers are
159
* not deleted!
160
*/
161
SAXWeightsHandler(const std::vector<ToRetrieveDefinition*>& defs, const std::string& file);
162
163
/**
164
* @brief Constructor
165
*
166
* Gets a single definition. Please note that the retrievers are not deleted!
167
*/
168
SAXWeightsHandler(ToRetrieveDefinition* def, const std::string& file);
169
170
/// @brief Destructor
171
~SAXWeightsHandler();
172
173
protected:
174
/// @name inherited from GenericSAXHandler
175
//@{
176
177
/** @brief Called on the opening of a tag;
178
*
179
* @param[in] element ID of the currently opened element
180
* @param[in] attrs Attributes within the currently opened element
181
* @exception ProcessError If something fails
182
* @see GenericSAXHandler::myStartElement
183
*/
184
void myStartElement(int element, const SUMOSAXAttributes& attrs);
185
186
/** @brief Called when a closing tag occurs
187
*
188
* @param[in] element ID of the currently opened element
189
* @exception ProcessError If something fails
190
* @see GenericSAXHandler::myEndElement
191
*/
192
void myEndElement(int elemente);
193
194
//@}
195
196
private:
197
/// @brief Parses the data of an edge or lane for the previously read times
198
void tryParse(const SUMOSAXAttributes& attrs, bool isEdge);
199
200
/// @brief Parses the data of an edgeRelation for the previously read times
201
void tryParseEdgeRel(const SUMOSAXAttributes& attrs);
202
203
/// @brief Parses the data of an tazRelation for the previously read times
204
void tryParseTazRel(const SUMOSAXAttributes& attrs);
205
206
/// @brief List of definitions what shall be read and whereto stored while parsing the file
207
std::vector<ToRetrieveDefinition*> myDefinitions;
208
209
/// @brief the id of the interval being parsed
210
std::string myCurrentID;
211
212
/// @brief the begin of the time period that is currently processed
213
double myCurrentTimeBeg;
214
215
/// @brief the end of the time period that is currently processed
216
double myCurrentTimeEnd;
217
218
/// @brief the edge which is currently being processed
219
std::string myCurrentEdgeID;
220
221
/// @brief we made the copy constructor invalid
222
SAXWeightsHandler(const SAXWeightsHandler& src) = delete;
223
224
/// @brief we made the assignment operator invalid
225
SAXWeightsHandler& operator=(const SAXWeightsHandler& src) = delete;
226
};
227
228