Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/utils/vehicle/SUMORouteHandler.h
193904 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2026 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 SUMORouteHandler.h
15
/// @author Daniel Krajzewicz
16
/// @author Jakob Erdmann
17
/// @author Michael Behrisch
18
/// @date Mon, 9 Jul 2001
19
///
20
// Parser for routes during their loading
21
/****************************************************************************/
22
#pragma once
23
#include <config.h>
24
25
#include <utils/common/IDSupplier.h>
26
#include <utils/common/SUMOTime.h>
27
#include <utils/vehicle/SUMOVehicleParameter.h>
28
#include <utils/xml/SUMOSAXHandler.h>
29
30
31
// ===========================================================================
32
// class declarations
33
// ===========================================================================
34
class MsgHandler;
35
class SUMOVTypeParameter;
36
37
38
// ===========================================================================
39
// class definitions
40
// ===========================================================================
41
/**
42
* @class SUMORouteHandler
43
* @brief Parser for routes during their loading
44
*
45
* SUMORouteHandler is the abstract super class for routers
46
* and simulation loading routes.
47
*/
48
class SUMORouteHandler : public SUMOSAXHandler {
49
public:
50
/// @brief enum for stops
51
enum StopPos {
52
STOPPOS_VALID,
53
STOPPOS_INVALID_STARTPOS,
54
STOPPOS_INVALID_ENDPOS,
55
STOPPOS_INVALID_LANELENGTH
56
};
57
58
/// @brief standard constructor
59
SUMORouteHandler(const std::string& file, const std::string& expectedRoot, const bool hardFail);
60
61
/// @brief standard destructor
62
virtual ~SUMORouteHandler();
63
64
/**@brief check start and end position of a stop
65
* @brief return */
66
static StopPos checkStopPos(double& startPos, double& endPos, const double laneLength, const double minLength, const bool friendlyPos);
67
68
/// @brief returns the first departure time that was ever read
69
SUMOTime getFirstDepart() const;
70
71
/// @brief Returns the last loaded depart time
72
SUMOTime getLastDepart() const;
73
74
protected:
75
/// @name inherited from GenericSAXHandler
76
//@{
77
78
/** @brief Called on the opening of a tag;
79
*
80
* @param[in] element ID of the currently opened element
81
* @param[in] attrs Attributes within the currently opened element
82
* @exception ProcessError If something fails
83
* @see GenericSAXHandler::myStartElement
84
*/
85
virtual void myStartElement(int element,
86
const SUMOSAXAttributes& attrs);
87
88
/** @brief Called when a closing tag occurs
89
*
90
* @param[in] element ID of the currently opened element
91
* @exception ProcessError If something fails
92
* @see GenericSAXHandler::myEndElement
93
*/
94
virtual void myEndElement(int element);
95
//@}
96
97
/// @name open element functions
98
//@{
99
100
/// @brief opens a type distribution for reading
101
virtual void openVehicleTypeDistribution(const SUMOSAXAttributes& attrs) = 0;
102
103
/// @brief closes (ends) the building of a distribution
104
virtual void closeVehicleTypeDistribution() = 0;
105
106
/// @brief opens a route for reading
107
virtual void openRoute(const SUMOSAXAttributes& attrs) = 0;
108
109
/// @brief opens a flow for reading
110
virtual void openFlow(const SUMOSAXAttributes& attrs) = 0;
111
112
/// @brief opens a route flow for reading
113
virtual void openRouteFlow(const SUMOSAXAttributes& attrs) = 0;
114
115
/// @brief opens a trip for reading
116
virtual void openTrip(const SUMOSAXAttributes& attrs) = 0;
117
//@}
118
119
/// @name close element functions
120
//@{
121
122
/**closes (ends) the building of a route.
123
* Afterwards no edges may be added to it;
124
* this method may throw exceptions when
125
* a) the route is empty or
126
* b) another route with the same id already exists
127
*/
128
virtual void closeRoute(const bool mayBeDisconnected = false) = 0;
129
130
/// @brief opens a route distribution for reading
131
virtual void openRouteDistribution(const SUMOSAXAttributes& attrs) = 0;
132
133
/// @brief closes (ends) the building of a distribution
134
virtual void closeRouteDistribution() = 0;
135
136
/// @brief Ends the processing of a vehicle
137
virtual void closeVehicle() = 0;
138
139
/// @brief Ends the processing of a vehicle type
140
virtual void closeVType() = 0;
141
142
/// @brief Ends the processing of a person
143
virtual void closePerson() = 0;
144
145
/// @brief Ends the processing of a person flow
146
virtual void closePersonFlow() = 0;
147
148
/// @brief Ends the processing of a container
149
virtual void closeContainer() = 0;
150
151
/// @brief Ends the processing of a container flow
152
virtual void closeContainerFlow() = 0;
153
154
/// @brief Ends the processing of a flow
155
virtual void closeFlow() = 0;
156
157
/// @brief Ends the processing of a trip
158
virtual void closeTrip() = 0;
159
//@}
160
161
/// @name add element functions
162
//@{
163
164
/// @brief Processing of a person or container
165
virtual void addTransportable(const SUMOSAXAttributes& attrs, const bool isPerson) {
166
UNUSED_PARAMETER(attrs);
167
UNUSED_PARAMETER(isPerson);
168
}
169
170
/// @brief Processing of a stop
171
virtual Parameterised* addStop(const SUMOSAXAttributes& attrs) = 0;
172
173
/// @brief add a routing request for a walking or intermodal person
174
virtual void addPersonTrip(const SUMOSAXAttributes& attrs) = 0;
175
176
/// @brief add a fully specified walk
177
virtual void addWalk(const SUMOSAXAttributes& attrs) = 0;
178
179
/// @brief Processing of a ride
180
virtual void addRide(const SUMOSAXAttributes& attrs) = 0;
181
182
/// @brief Processing of a transport
183
virtual void addTransport(const SUMOSAXAttributes& attrs) = 0;
184
185
/// @brief Processing of a tranship
186
virtual void addTranship(const SUMOSAXAttributes& attrs) = 0;
187
188
//@}
189
190
/// @brief Checks whether the route file is sorted by departure time if needed
191
virtual bool checkLastDepart();
192
193
/// @brief save last depart (only to be used if vehicle is not discarded)
194
void registerLastDepart();
195
196
/// @brief assign arbitrary vehicle parameters
197
void addParam(const SUMOSAXAttributes& attrs);
198
199
/// @brief parses attributes common to all stops
200
bool parseStop(SUMOVehicleParameter::Stop& stop, const SUMOSAXAttributes& attrs, std::string errorSuffix, MsgHandler* const errorOutput);
201
202
protected:
203
/// @brief flag to enable or disable hard fails
204
const bool myHardFail;
205
206
/// @brief Parameter of the current vehicle, trip, person, container or flow
207
SUMOVehicleParameter* myVehicleParameter;
208
209
/// @brief The stack of currently parsed parameterised objects
210
std::vector<Parameterised*> myParamStack;
211
212
/// @brief The insertion time of the vehicle read last
213
SUMOTime myLastDepart;
214
215
/// @brief The id of the current route
216
std::string myActiveRouteID;
217
218
/// @brief The id of the route the current route references to
219
std::string myActiveRouteRefID;
220
221
/// @brief The probability of the current route
222
double myActiveRouteProbability;
223
224
/// @brief The currently parsed route's color
225
const RGBColor* myActiveRouteColor;
226
227
/// @brief The currently parsed route costs
228
double myCurrentCosts;
229
230
/// @brief List of the stops on the parsed route
231
StopParVector myActiveRouteStops;
232
233
/// @brief The currently parsed vehicle type
234
SUMOVTypeParameter* myCurrentVType;
235
236
/// @brief The default value for flow begins
237
SUMOTime myBeginDefault;
238
239
/// @brief The default value for flow ends
240
SUMOTime myEndDefault;
241
242
/// @brief the first read departure time
243
SUMOTime myFirstDepart;
244
245
/// @brief where stop edges can be inserted into the current route (-1 means no insertion)
246
int myInsertStopEdgesAt;
247
248
/// @brief hierarchy of elements being parsed
249
std::vector<int> myElementStack;
250
251
/// @brief whether references to internal routes are allowed in this context
252
bool myAllowInternalRoutes;
253
254
/// @brief IDs of skipped vehicles to suppress errors for the triggered transportables within
255
std::set<std::string> mySkippedVehicles;
256
257
private:
258
/// @brief Invalidated copy constructor
259
SUMORouteHandler(const SUMORouteHandler& s) = delete;
260
261
/// @brief Invalidated assignment operator
262
SUMORouteHandler& operator=(const SUMORouteHandler& s) = delete;
263
};
264
265