Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/utils/vehicle/SUMORouteHandler.h
169678 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-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 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 check if start and end position of a stop is valid
69
static bool isStopPosValid(const double startPos, const double endPos, const double laneLength, const double minLength, const bool friendlyPos);
70
71
/// @brief returns the first departure time that was ever read
72
SUMOTime getFirstDepart() const;
73
74
/// @brief Returns the last loaded depart time
75
SUMOTime getLastDepart() const;
76
77
protected:
78
/// @name inherited from GenericSAXHandler
79
//@{
80
81
/** @brief Called on the opening of a tag;
82
*
83
* @param[in] element ID of the currently opened element
84
* @param[in] attrs Attributes within the currently opened element
85
* @exception ProcessError If something fails
86
* @see GenericSAXHandler::myStartElement
87
*/
88
virtual void myStartElement(int element,
89
const SUMOSAXAttributes& attrs);
90
91
/** @brief Called when a closing tag occurs
92
*
93
* @param[in] element ID of the currently opened element
94
* @exception ProcessError If something fails
95
* @see GenericSAXHandler::myEndElement
96
*/
97
virtual void myEndElement(int element);
98
//@}
99
100
/// @name open element functions
101
//@{
102
103
/// @brief opens a type distribution for reading
104
virtual void openVehicleTypeDistribution(const SUMOSAXAttributes& attrs) = 0;
105
106
/// @brief closes (ends) the building of a distribution
107
virtual void closeVehicleTypeDistribution() = 0;
108
109
/// @brief opens a route for reading
110
virtual void openRoute(const SUMOSAXAttributes& attrs) = 0;
111
112
/// @brief opens a flow for reading
113
virtual void openFlow(const SUMOSAXAttributes& attrs) = 0;
114
115
/// @brief opens a route flow for reading
116
virtual void openRouteFlow(const SUMOSAXAttributes& attrs) = 0;
117
118
/// @brief opens a trip for reading
119
virtual void openTrip(const SUMOSAXAttributes& attrs) = 0;
120
//@}
121
122
/// @name close element functions
123
//@{
124
125
/**closes (ends) the building of a route.
126
* Afterwards no edges may be added to it;
127
* this method may throw exceptions when
128
* a) the route is empty or
129
* b) another route with the same id already exists
130
*/
131
virtual void closeRoute(const bool mayBeDisconnected = false) = 0;
132
133
/// @brief opens a route distribution for reading
134
virtual void openRouteDistribution(const SUMOSAXAttributes& attrs) = 0;
135
136
/// @brief closes (ends) the building of a distribution
137
virtual void closeRouteDistribution() = 0;
138
139
/// @brief Ends the processing of a vehicle
140
virtual void closeVehicle() = 0;
141
142
/// @brief Ends the processing of a vehicle type
143
virtual void closeVType() = 0;
144
145
/// @brief Ends the processing of a person
146
virtual void closePerson() = 0;
147
148
/// @brief Ends the processing of a person flow
149
virtual void closePersonFlow() = 0;
150
151
/// @brief Ends the processing of a container
152
virtual void closeContainer() = 0;
153
154
/// @brief Ends the processing of a container flow
155
virtual void closeContainerFlow() = 0;
156
157
/// @brief Ends the processing of a flow
158
virtual void closeFlow() = 0;
159
160
/// @brief Ends the processing of a trip
161
virtual void closeTrip() = 0;
162
//@}
163
164
/// @name add element functions
165
//@{
166
167
/// @brief Processing of a person or container
168
virtual void addTransportable(const SUMOSAXAttributes& attrs, const bool isPerson) {
169
UNUSED_PARAMETER(attrs);
170
UNUSED_PARAMETER(isPerson);
171
}
172
173
/// @brief Processing of a stop
174
virtual Parameterised* addStop(const SUMOSAXAttributes& attrs) = 0;
175
176
/// @brief add a routing request for a walking or intermodal person
177
virtual void addPersonTrip(const SUMOSAXAttributes& attrs) = 0;
178
179
/// @brief add a fully specified walk
180
virtual void addWalk(const SUMOSAXAttributes& attrs) = 0;
181
182
/// @brief Processing of a ride
183
virtual void addRide(const SUMOSAXAttributes& attrs) = 0;
184
185
/// @brief Processing of a transport
186
virtual void addTransport(const SUMOSAXAttributes& attrs) = 0;
187
188
/// @brief Processing of a tranship
189
virtual void addTranship(const SUMOSAXAttributes& attrs) = 0;
190
191
//@}
192
193
/// @brief Checks whether the route file is sorted by departure time if needed
194
virtual bool checkLastDepart();
195
196
/// @brief save last depart (only to be used if vehicle is not discarded)
197
void registerLastDepart();
198
199
/// @brief assign arbitrary vehicle parameters
200
void addParam(const SUMOSAXAttributes& attrs);
201
202
/// @brief parses attributes common to all stops
203
bool parseStop(SUMOVehicleParameter::Stop& stop, const SUMOSAXAttributes& attrs, std::string errorSuffix, MsgHandler* const errorOutput);
204
205
protected:
206
/// @brief flag to enable or disable hard fails
207
const bool myHardFail;
208
209
/// @brief Parameter of the current vehicle, trip, person, container or flow
210
SUMOVehicleParameter* myVehicleParameter;
211
212
/// @brief The stack of currently parsed parameterised objects
213
std::vector<Parameterised*> myParamStack;
214
215
/// @brief The insertion time of the vehicle read last
216
SUMOTime myLastDepart;
217
218
/// @brief The id of the current route
219
std::string myActiveRouteID;
220
221
/// @brief The id of the route the current route references to
222
std::string myActiveRouteRefID;
223
224
/// @brief The probability of the current route
225
double myActiveRouteProbability;
226
227
/// @brief The currently parsed route's color
228
const RGBColor* myActiveRouteColor;
229
230
/// @brief The currently parsed route costs
231
double myCurrentCosts;
232
233
/// @brief List of the stops on the parsed route
234
StopParVector myActiveRouteStops;
235
236
/// @brief The currently parsed vehicle type
237
SUMOVTypeParameter* myCurrentVType;
238
239
/// @brief The default value for flow begins
240
SUMOTime myBeginDefault;
241
242
/// @brief The default value for flow ends
243
SUMOTime myEndDefault;
244
245
/// @brief the first read departure time
246
SUMOTime myFirstDepart;
247
248
/// @brief where stop edges can be inserted into the current route (-1 means no insertion)
249
int myInsertStopEdgesAt;
250
251
/// @brief hierarchy of elements being parsed
252
std::vector<int> myElementStack;
253
254
/// @brief whether references to internal routes are allowed in this context
255
bool myAllowInternalRoutes;
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