Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netload/NLTriggerBuilder.h
169666 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2002-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 NLTriggerBuilder.h
15
/// @author Daniel Krajzewicz
16
/// @author Tino Morenz
17
/// @author Eric Nicolay
18
/// @author Michael Behrisch
19
/// @author Jakob Erdmann
20
/// @date Thu, 17 Oct 2002
21
///
22
// Builds trigger objects for microsim
23
/****************************************************************************/
24
#pragma once
25
#include <config.h>
26
27
#include <string>
28
#include <vector>
29
#include <utils/common/RGBColor.h>
30
31
32
// ===========================================================================
33
// class declarations
34
// ===========================================================================
35
class MSTrigger;
36
class MSNet;
37
class MSLaneSpeedTrigger;
38
class NLHandler;
39
class MSTriggeredRerouter;
40
class MSLane;
41
class MSEdge;
42
class MSStoppingPlace;
43
class MSCalibrator;
44
class MSRouteProbe;
45
46
class METriggeredCalibrator;
47
48
49
// ===========================================================================
50
// class definitions
51
// ===========================================================================
52
/**
53
* @class NLTriggerBuilder
54
* @brief Builds trigger objects for microsim
55
*
56
* The building methods may be overridden, to build guisim-instances of the triggers,
57
* for example.
58
*
59
*/
60
class NLTriggerBuilder {
61
public:
62
/// @brief Constructor
63
NLTriggerBuilder();
64
65
66
/// @brief Destructor
67
virtual ~NLTriggerBuilder();
68
69
/** @brief Sets the parent handler to use for nested parsing
70
*
71
* @param[in] handler The netload handler to set
72
*/
73
void setHandler(NLHandler* handler);
74
75
76
/** @brief Builds a vaporization
77
*
78
* Parses the attributes, reporting errors if the time values are false
79
* or the edge is not known.
80
* Instatiates events for enabling and disabling the vaporization otherwise.
81
*
82
* @param[in] attrs SAX-attributes which define the vaporizer
83
* @note recheck throwing the exception
84
*/
85
void buildVaporizer(const SUMOSAXAttributes& attrs);
86
87
88
/// @name parsing methods
89
///
90
/// These methods parse the attributes for each of the described trigger
91
/// and call the according methods to build the trigger
92
//@{
93
/** @brief Parses his values and builds a lane speed trigger
94
*
95
* If one of the declaration values is errornous, an InvalidArgument is thrown.
96
*
97
* If the XML-file parsed during initialisation is errornous, and the
98
* MSLaneSpeedTrigger-constructor throws a ProcessError due to this, this
99
* exception is catched and an InvalidArgument with the message given in the
100
* ProcessError is thrown.
101
*
102
* @param[in] net The network the lane speed trigger belongs to
103
* @param[in] attrs SAX-attributes which define the trigger
104
* @param[in] base The base path
105
* @exception InvalidArgument If a parameter (lane/position) is not valid or the read definition is errornous
106
* @see buildLaneSpeedTrigger
107
*/
108
void parseAndBuildLaneSpeedTrigger(MSNet& net, const SUMOSAXAttributes& attrs,
109
const std::string& base);
110
111
112
/** @brief Parses his values and builds a rerouter
113
*
114
* @param[in] net The network the rerouter belongs to
115
* @param[in] attrs SAX-attributes which define the trigger
116
* @exception InvalidArgument If a parameter (edge) is not valid
117
*/
118
void parseAndBuildRerouter(MSNet& net, const SUMOSAXAttributes& attrs);
119
120
121
/** @brief Parses the values and builds a stopping places for busses, trains or container vehicles
122
*
123
* @param[in] net The network the stop belongs to
124
* @param[in] attrs SAX-attributes which define the stop
125
* @param[in] element which kind of stop is to be built
126
* @exception InvalidArgument If a parameter (lane/position) is not valid
127
*/
128
void parseAndBuildStoppingPlace(MSNet& net, const SUMOSAXAttributes& attrs, const SumoXMLTag element);
129
130
131
/** @brief Begin a parking area
132
*
133
* Simply calls the MSParkingArea constructor.
134
*
135
* @param[in] net The net the parking area belongs to
136
* @param[in] id The id of the parking area
137
* @param[in] lines Names of the lines that halt on this parking area
138
* @param[in] badges Names which grant access to this parking area
139
* @param[in] lane The lane the parking area is placed on
140
* @param[in] frompos Begin position of the parking area on the lane
141
* @param[in] topos End position of the parking area on the lane
142
* @param[in] capacity Capacity of the parking area
143
* @param[in] width Width of the default lot rectangle
144
* @param[in] length Length of the default lot rectangle
145
* @param[in] angle Angle of the default lot rectangle
146
* @exception InvalidArgument If the parking area can not be added to the net (is duplicate)
147
*/
148
virtual void beginParkingArea(MSNet& net,
149
const std::string& id, const std::vector<std::string>& lines,
150
const std::vector<std::string>& badges,
151
MSLane* lane, double frompos, double topos,
152
unsigned int capacity,
153
double width, double length, double angle, const std::string& name,
154
bool onRoad,
155
const std::string& departPos,
156
bool lefthand);
157
158
159
/** @brief Add a lot entry to current parking area
160
*
161
* Simply calls the addLotEntry method for current parking area.
162
*
163
* @param[in] x X position of the lot center
164
* @param[in] y Y position of the lot center
165
* @param[in] z Z position of the lot center
166
* @param[in] width Width of the lot rectangle
167
* @param[in] length Length of the lot rectangle
168
* @param[in] angle Angle of the lot rectangle
169
* @param[in] slope Slope of the lot rectangle
170
* @exception InvalidArgument If the current parking area is 0
171
*/
172
void addLotEntry(double x, double y, double z,
173
double width, double length,
174
double angle, double slope);
175
176
177
178
/** @brief Parses the values and adds an access point to the currently parsed stopping place
179
*
180
* @param[in] net The network the stop belongs to
181
* @param[in] attrs SAX-attributes which define the access
182
* @exception InvalidArgument If a parameter (lane/position) is not valid
183
*/
184
void addAccess(MSNet& net, const SUMOSAXAttributes& attrs);
185
186
187
/** @brief Parses his values and builds a parking area
188
*
189
* @param[in] net The network the parking area belongs to
190
* @param[in] attrs SAX-attributes which define the trigger
191
* @exception InvalidArgument If a parameter (lane/position) is not valid
192
*/
193
void parseAndBeginParkingArea(MSNet& net, const SUMOSAXAttributes& attrs);
194
195
196
/** @brief Parses his values and adds a lot entry to current parking area
197
*
198
* @param[in] attrs SAX-attributes which define the lot entry
199
*/
200
void parseAndAddLotEntry(const SUMOSAXAttributes& attrs);
201
202
203
/** @brief End a parking area
204
*
205
* @exception InvalidArgument If the current parking area is 0
206
*/
207
virtual void endParkingArea();
208
209
/** @brief End a stopping place
210
*
211
* @exception InvalidArgument If the current stopping place is 0
212
*/
213
virtual void endStoppingPlace();
214
215
216
/** @brief Parses his values and builds a charging station
217
*
218
* @param[in] net The network the charging station belongs to
219
* @param[in] attrs SAXattributes which define the trigger
220
* @exception InvalidArgument If a parameter (lane/position) is not valid
221
*/
222
void parseAndBuildChargingStation(MSNet& net, const SUMOSAXAttributes& attrs);
223
224
/** @brief Parses its values and builds an overhead wire segment
225
*
226
* @param[in] net The network the overhead wire segment belongs to
227
* @param[in] attrs SAXattributes which define the trigger
228
* @exception InvalidArgument If a parameter (lane/position) is not valid
229
*/
230
void parseAndBuildOverheadWireSegment(MSNet& net, const SUMOSAXAttributes& attrs);
231
232
/** @brief Parses its values and builds an overhead wire section
233
*
234
* @param[in] net The network the overhead wire segment belongs to
235
* @param[in] attrs SAXattributes which define the trigger
236
* @exception InvalidArgument If a substationId is not known, a segment is not known or is assigned to another overheadWireSection
237
*/
238
void parseAndBuildOverheadWireSection(MSNet& net, const SUMOSAXAttributes& attrs);
239
240
/** @brief Parses its values and builds a traction substation
241
*
242
* @param[in] net The network the overhead wire segment belongs to
243
* @param[in] attrs SAXattributes which define the trigger
244
* @exception InvalidArgument If the id is not given or is empty...
245
*/
246
void parseAndBuildTractionSubstation(MSNet& net, const SUMOSAXAttributes& attrs);
247
248
/** @brief Parses its values and builds an overhead wire clamp
249
*
250
* An overhead wire clamp is a conductive connection of wires in the opposite direction over the road
251
*
252
* @param[in] net The network the overhead wire clamp belongs to
253
* @param[in] attrs SAXattributes which define the trigger
254
* @exception InvalidArgument If the traction substation is not found in the net or if the start or end segment belongs to a different traction substation
255
*/
256
void parseAndBuildOverheadWireClamp(MSNet& net, const SUMOSAXAttributes& attrs);
257
258
/** @brief Parses his values and builds a mesoscopic or microscopic calibrator
259
*
260
* @param[in] net The network the calibrator belongs to
261
* @param[in] attrs SAX-attributes which define the trigger
262
* @param[in] base The base path
263
* @exception InvalidArgument If a parameter (edge/position) is not valid
264
*/
265
void parseAndBuildCalibrator(MSNet& net, const SUMOSAXAttributes& attrs,
266
const std::string& base);
267
268
/** @brief updates the parkingArea default capacity
269
*/
270
void updateParkingAreaDefaultCapacity();
271
//@}
272
273
274
MSStoppingPlace* getCurrentStop();
275
276
277
protected:
278
/// @name building methods
279
///
280
/// Called with parsed values, these methods build the trigger.
281
///
282
/// These methods should be overriden for the gui loader in order
283
/// to build visualizable versions of the triggers.
284
///
285
/// In most cases, these methods only call the constructor.
286
//@{
287
288
/** @brief Builds a lane speed trigger
289
*
290
* Simply calls the MSLaneSpeedTrigger constructor.
291
*
292
* @param[in] net The net the lane speed trigger belongs to
293
* @param[in] id The id of the lane speed trigger
294
* @param[in] destLanes List of lanes affected by this speed trigger
295
* @param[in] file Name of the file to read the speeds to set from
296
* @see MSLaneSpeedTrigger
297
* @exception ProcessError If the XML definition file is errornous
298
*/
299
virtual MSLaneSpeedTrigger* buildLaneSpeedTrigger(MSNet& net,
300
const std::string& id, const std::vector<MSLane*>& destLanes,
301
const std::string& file);
302
303
304
/** @brief Builds a stopping place
305
*
306
* Simply calls the MSStoppingPlace constructor.
307
*
308
* @param[in] net The net the stop belongs to
309
* @param[in] id The id of the stop
310
* @param[in] lines Names of the lines that halt on this bus stop
311
* @param[in] lane The lane the stop is placed on
312
* @param[in] frompos Begin position of the stop on the lane
313
* @param[in] topos End position of the stop on the lane
314
* @param[in] element which kind of stop is to be built
315
* @exception InvalidArgument If the stop can not be added to the net (is duplicate)
316
*/
317
virtual void buildStoppingPlace(MSNet& net, std::string id, std::vector<std::string> lines, MSLane* lane,
318
double frompos, double topos, const SumoXMLTag element, std::string string,
319
int personCapacity, double parkingLength, RGBColor& color, double angle);
320
321
/** @brief Builds a charging station
322
*
323
* Simply calls the MSChargingStation constructor and adds the result to the network.
324
*
325
* @param[in] net The net the charging station belongs to
326
* @param[in] id The id of the charging station
327
* @param[in] lane The lane the charging station is placed on
328
* @param[in] frompos Begin position of the charging station on the lane
329
* @param[in] topos End position of the charging station on the lane
330
* @param[in] chargingPower energy charged in every timeStep
331
* @param[in] efficiency efficiency of the charge
332
* @param[in] chargeInTransit enable or disable charge in transit
333
* @param[in] chargeDelay delay in the charge
334
* @param[in] chargeType charge type (normal, electric or fuel)
335
* @param[in] waitingTime waiting time until start charging
336
* @param[in] parkingArea The associated parking area
337
* @exception InvalidArgument If the charging station can not be added to the net (is duplicate)
338
*/
339
virtual void buildChargingStation(MSNet& net, const std::string& id, MSLane* lane, double frompos, double topos, const std::string& name,
340
double chargingPower, double efficiency, bool chargeInTransit, SUMOTime chargeDelay, std::string chargeType,
341
SUMOTime waitingTime, MSParkingArea* parkingArea);
342
343
/** @brief Builds an overhead wire segment
344
*
345
* Simply calls the MSOverheadWire constructor and adds the result to the network.
346
*
347
* @param[in] net The net the overhead wire segment belongs to
348
* @param[in] id The id of the overhead wire segment
349
* @param[in] lane The lane the overhead wire segment is placed on
350
* @param[in] frompos Begin position of the overhead wire segment on the lane
351
* @param[in] topos End position of the overhead wire segment on the lane
352
* @param[in] voltageSource default voltage of overhead wire segment (unused) TODORICE
353
* @exception InvalidArgument If the overhead wire segment can not be added to the net (is duplicate according to the id)
354
*/
355
virtual void buildOverheadWireSegment(MSNet& net, const std::string& id, MSLane* lane, double frompos, double topos, bool voltageSource);
356
357
/** @brief Builds an overhead wire inner segments
358
*
359
* Simply calls the buildOverheadWireSegment for inner edges connection, frontConnection and behindConnection if exists.
360
*
361
* @param[in] net The net the overhead wire inner segments belongs to
362
* @param[in] connection The inner lane that connects two regular lanes, or a regular lane with the inner "behindConnection" lane,
363
or the inner "frontConnection" lane with a regular lane, or the inner "frontConnection" lane with the inner "behindConnection" lane
364
* @param[in] frontConnection The inner lane that connects a regular lane with the inner "connection" lane
365
* @param[in] behindConnection The inner lane that connects the inner "connection" lane with a regular lane
366
* @exception InvalidArgument If the over can not be added to the net (is duplicate according to the id)
367
*/
368
void buildInnerOverheadWireSegments(MSNet& net, const MSLane* connection, const MSLane* frontConnection, const MSLane* behindConnection);
369
370
/** @brief Builds a traction substation
371
*
372
* Simply calls the MSTractionSubstaion cosnstructor and adds the substation to the list of substations in the net.
373
*
374
* @param[in] net The net the traction substation belongs to
375
* @param[in] id The id of the traction substation
376
* @param[in] voltage The voltage level of the voltage source representing the traction substation
377
* @param[in] currentLimit The electric current limit(max current flowing from(through) the traction substation)
378
* @exception InvalidArgument If the over can not be added to the net (is duplicate according to the id)
379
*/
380
void buildTractionSubstation(MSNet& net, std::string id, double voltage, double currentLimit);
381
382
virtual void buildOverheadWireClamp(MSNet& net, const std::string& id, MSLane* lane_start, MSLane* lane_end);
383
384
/** @brief builds a microscopic calibrator
385
*
386
* Simply calls the MSCalibrator constructor.
387
*
388
* @param[in] id The id of the calibrator
389
* @param[in] edge The edge the calibrator is placed at
390
* @param[in] lane The lane the calibrator is placed at if it is lane specific, nullptr otherwise
391
* @param[in] pos The position on the edge the calibrator lies at
392
* @param[in] file The file to read the flows from
393
* @param[in] outfile The file to write calibrator statistics to
394
* @param[in] freq The frequency for the statistics output
395
* @param[in] probe an optional route probe to get distributions from
396
* @param[in] invalidJamThreshold stop calibrating if the relative speed drops below the threshold
397
* @param[in] vTypes to which vehicle types the calibrator applies
398
* @todo Is the position correct/needed
399
*/
400
virtual MSCalibrator* buildCalibrator(const std::string& id, MSEdge* edge, MSLane* lane, MSJunction* node, double pos,
401
const std::string& file, const std::string& outfile,
402
const SUMOTime freq,
403
const MSRouteProbe* probe,
404
const double invalidJamThreshold,
405
const std::string& vTypes,
406
const bool local);
407
408
/** @brief builds a mesoscopic calibrator
409
*
410
* Simply calls the METriggeredCalibrator constructor.
411
*
412
* @param[in] id The id of the calibrator
413
* @param[in] edge The edge the calibrator is placed at
414
* @param[in] pos The position on the edge the calibrator lies at
415
* @param[in] file The file to read the flows from
416
* @param[in] outfile The file to write calibrator statistics to
417
* @param[in] freq The frequency for the statistics output
418
* @param[in] probe an optional route probe to get distributions from
419
* @param[in] invalidJamThreshold stop calibrating if the relative speed drops below the threshold
420
* @param[in] vTypes to which vehicle types the calibrator applies
421
* @todo Is the position correct/needed
422
*/
423
virtual METriggeredCalibrator* buildMECalibrator(const std::string& id, MSEdge* edge, double pos,
424
const std::string& file, const std::string& outfile,
425
const SUMOTime freq,
426
MSRouteProbe* probe,
427
const double invalidJamThreshold,
428
const std::string& vTypes);
429
430
431
/** @brief builds an rerouter
432
*
433
* Simply calls the MSTriggeredRerouter constructor.
434
*
435
* @param[in] net The net the rerouter belongs to
436
* @param[in] id The id of the rerouter
437
* @param[in] edges The edges the rerouter is placed at
438
* @param[in] prob The probability the rerouter reoutes vehicles with
439
*/
440
virtual MSTriggeredRerouter* buildRerouter(MSNet& net,
441
const std::string& id, MSEdgeVector& edges,
442
double prob, bool off, bool optional, SUMOTime timeThreshold,
443
const std::string& vTypes, const Position& pos, const double radius);
444
//@}
445
446
447
protected:
448
/// @name helper method for obtaining and checking values
449
/// @{
450
451
/** @brief Helper method to obtain the filename
452
*
453
* Retrieves "file" from attributes, checks whether it is absolute
454
* and extends it by the given base path if not. Returns this
455
* information.
456
*
457
* @param[in] attrs The attributes to obtain the file name from
458
* @param[in] base The base path (the path the loaded additional file lies in)
459
* @return The (expanded) path to the named file
460
* @todo Recheck usage of the helper class
461
*/
462
std::string getFileName(const SUMOSAXAttributes& attrs,
463
const std::string& base,
464
const bool allowEmpty = false);
465
466
467
/** @brief Returns the lane defined by attribute "lane"
468
*
469
* Retrieves the lane id from the given attrs. Tries to retrieve the lane,
470
* throws an InvalidArgument if it does not exist.
471
*
472
* @param[in] attrs The attributes to obtain the lane id from
473
* @param[in] tt The trigger type (for user output)
474
* @param[in] tid The trigger id (for user output)
475
* @return The named lane if it is known
476
* @exception InvalidArgument If the named lane does not exist or a lane is not named
477
*/
478
MSLane* getLane(const SUMOSAXAttributes& attrs,
479
const std::string& tt, const std::string& tid);
480
481
482
/** @brief Returns the parking area defined by attribute "parkingArea"
483
*
484
* Retrieves the parking area id from the given attrs. Tries to retrieve the parking area,
485
* throws an InvalidArgument if it does not exist.
486
*
487
* @param[in] attrs The attributes to obtain the parking area id from
488
* @param[in] tt The trigger type (for user output)
489
* @param[in] tid The trigger id (for user output)
490
* @return The named parking area if it is known, nullptr if empty ID is given
491
* @exception InvalidArgument If the named parking area does not exist
492
*/
493
MSParkingArea* getParkingArea(const SUMOSAXAttributes& attrs,
494
const std::string& tt, const std::string& tid);
495
496
497
/** @brief returns the position on the lane checking it
498
*
499
* This method extracts the position, checks whether it shall be mirrored
500
* and checks whether it is within the lane. If not, an error is reported
501
* and a InvalidArgument is thrown.
502
*
503
* @param[in] attrs The attributes to obtain the position from
504
* @param[in] lane The lane the position shall be valid for
505
* @param[in] tt The trigger type (for user output)
506
* @param[in] tid The trigger id (for user output)
507
* @return The position on the lane
508
* @exception InvalidArgument If the position is beyond the lane
509
*/
510
double getPosition(const SUMOSAXAttributes& attrs,
511
MSLane* lane, const std::string& tt, const std::string& tid, MSEdge* edge = 0);
512
513
/// @}
514
515
516
517
518
protected:
519
/// @brief The parent handler to set for subhandlers
520
NLHandler* myHandler;
521
/// @brief definition of the currently parsed parking area
522
MSParkingArea* myParkingArea;
523
/// @brief The currently parsed stop to add access points to
524
MSStoppingPlace* myCurrentStop;
525
526
bool myHaveWarnedAboutEigen = false;
527
bool myParkingAreaCapacitySet = false;
528
};
529
530