Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netload/NLTriggerBuilder.h
193874 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2002-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 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 nominal energy charged in every timeStep per vehicle
331
* @param[in] totalPower max energy charged in every timestep by all vehicles together
332
* @param[in] efficiency efficiency of the charge
333
* @param[in] chargeInTransit enable or disable charge in transit
334
* @param[in] chargeDelay delay in the charge
335
* @param[in] chargeType charge type (normal, electric or fuel)
336
* @param[in] waitingTime waiting time until start charging
337
* @param[in] parkingArea The associated parking area
338
* @exception InvalidArgument If the charging station can not be added to the net (is duplicate)
339
*/
340
virtual void buildChargingStation(MSNet& net, const std::string& id, MSLane* lane, double frompos, double topos, const std::string& name,
341
double chargingPower, double totalPower, double efficiency, bool chargeInTransit, SUMOTime chargeDelay,
342
std::string chargeType, SUMOTime waitingTime, MSParkingArea* parkingArea);
343
344
/** @brief Builds an overhead wire segment
345
*
346
* Simply calls the MSOverheadWire constructor and adds the result to the network.
347
*
348
* @param[in] net The net the overhead wire segment belongs to
349
* @param[in] id The id of the overhead wire segment
350
* @param[in] lane The lane the overhead wire segment is placed on
351
* @param[in] frompos Begin position of the overhead wire segment on the lane
352
* @param[in] topos End position of the overhead wire segment on the lane
353
* @param[in] voltageSource default voltage of overhead wire segment (unused) TODORICE
354
* @exception InvalidArgument If the overhead wire segment can not be added to the net (is duplicate according to the id)
355
*/
356
virtual void buildOverheadWireSegment(MSNet& net, const std::string& id, MSLane* lane, double frompos, double topos, bool voltageSource);
357
358
/** @brief Builds an overhead wire inner segments
359
*
360
* Simply calls the buildOverheadWireSegment for inner edges connection, frontConnection and behindConnection if exists.
361
*
362
* @param[in] net The net the overhead wire inner segments belongs to
363
* @param[in] connection The inner lane that connects two regular lanes, or a regular lane with the inner "behindConnection" lane,
364
or the inner "frontConnection" lane with a regular lane, or the inner "frontConnection" lane with the inner "behindConnection" lane
365
* @param[in] frontConnection The inner lane that connects a regular lane with the inner "connection" lane
366
* @param[in] behindConnection The inner lane that connects the inner "connection" lane with a regular lane
367
* @exception InvalidArgument If the over can not be added to the net (is duplicate according to the id)
368
*/
369
void buildInnerOverheadWireSegments(MSNet& net, const MSLane* connection, const MSLane* frontConnection, const MSLane* behindConnection);
370
371
/** @brief Builds a traction substation
372
*
373
* Simply calls the MSTractionSubstaion cosnstructor and adds the substation to the list of substations in the net.
374
*
375
* @param[in] net The net the traction substation belongs to
376
* @param[in] id The id of the traction substation
377
* @param[in] voltage The voltage level of the voltage source representing the traction substation
378
* @param[in] currentLimit The electric current limit(max current flowing from(through) the traction substation)
379
* @exception InvalidArgument If the over can not be added to the net (is duplicate according to the id)
380
*/
381
void buildTractionSubstation(MSNet& net, std::string id, double voltage, double currentLimit);
382
383
virtual void buildOverheadWireClamp(MSNet& net, const std::string& id, MSLane* lane_start, MSLane* lane_end);
384
385
/** @brief builds a microscopic calibrator
386
*
387
* Simply calls the MSCalibrator constructor.
388
*
389
* @param[in] id The id of the calibrator
390
* @param[in] edge The edge the calibrator is placed at
391
* @param[in] lane The lane the calibrator is placed at if it is lane specific, nullptr otherwise
392
* @param[in] pos The position on the edge the calibrator lies at
393
* @param[in] file The file to read the flows from
394
* @param[in] outfile The file to write calibrator statistics to
395
* @param[in] freq The frequency for the statistics output
396
* @param[in] probe an optional route probe to get distributions from
397
* @param[in] invalidJamThreshold stop calibrating if the relative speed drops below the threshold
398
* @param[in] vTypes to which vehicle types the calibrator applies
399
* @todo Is the position correct/needed
400
*/
401
virtual MSCalibrator* buildCalibrator(const std::string& id, MSEdge* edge, MSLane* lane, MSJunction* node, double pos,
402
const std::string& file, const std::string& outfile,
403
const SUMOTime freq,
404
const MSRouteProbe* probe,
405
const double invalidJamThreshold,
406
const std::string& vTypes,
407
const bool local);
408
409
/** @brief builds a mesoscopic calibrator
410
*
411
* Simply calls the METriggeredCalibrator constructor.
412
*
413
* @param[in] id The id of the calibrator
414
* @param[in] edge The edge the calibrator is placed at
415
* @param[in] pos The position on the edge the calibrator lies at
416
* @param[in] file The file to read the flows from
417
* @param[in] outfile The file to write calibrator statistics to
418
* @param[in] freq The frequency for the statistics output
419
* @param[in] probe an optional route probe to get distributions from
420
* @param[in] invalidJamThreshold stop calibrating if the relative speed drops below the threshold
421
* @param[in] vTypes to which vehicle types the calibrator applies
422
* @todo Is the position correct/needed
423
*/
424
virtual METriggeredCalibrator* buildMECalibrator(const std::string& id, MSEdge* edge, double pos,
425
const std::string& file, const std::string& outfile,
426
const SUMOTime freq,
427
MSRouteProbe* probe,
428
const double invalidJamThreshold,
429
const std::string& vTypes);
430
431
432
/** @brief builds an rerouter
433
*
434
* Simply calls the MSTriggeredRerouter constructor.
435
*
436
* @param[in] net The net the rerouter belongs to
437
* @param[in] id The id of the rerouter
438
* @param[in] edges The edges the rerouter is placed at
439
* @param[in] prob The probability the rerouter reoutes vehicles with
440
*/
441
virtual MSTriggeredRerouter* buildRerouter(MSNet& net,
442
const std::string& id, MSEdgeVector& edges,
443
double prob, bool off, bool optional, SUMOTime timeThreshold,
444
const std::string& vTypes, const Position& pos, const double radius);
445
//@}
446
447
448
protected:
449
/// @name helper method for obtaining and checking values
450
/// @{
451
452
/** @brief Helper method to obtain the filename
453
*
454
* Retrieves "file" from attributes, checks whether it is absolute
455
* and extends it by the given base path if not. Returns this
456
* information.
457
*
458
* @param[in] attrs The attributes to obtain the file name from
459
* @param[in] base The base path (the path the loaded additional file lies in)
460
* @return The (expanded) path to the named file
461
* @todo Recheck usage of the helper class
462
*/
463
std::string getFileName(const SUMOSAXAttributes& attrs,
464
const std::string& base,
465
const bool allowEmpty = false);
466
467
468
/** @brief Returns the lane defined by attribute "lane"
469
*
470
* Retrieves the lane id from the given attrs. Tries to retrieve the lane,
471
* throws an InvalidArgument if it does not exist.
472
*
473
* @param[in] attrs The attributes to obtain the lane id from
474
* @param[in] tt The trigger type (for user output)
475
* @param[in] tid The trigger id (for user output)
476
* @return The named lane if it is known
477
* @exception InvalidArgument If the named lane does not exist or a lane is not named
478
*/
479
MSLane* getLane(const SUMOSAXAttributes& attrs,
480
const std::string& tt, const std::string& tid);
481
482
483
/** @brief Returns the parking area defined by attribute "parkingArea"
484
*
485
* Retrieves the parking area id from the given attrs. Tries to retrieve the parking area,
486
* throws an InvalidArgument if it does not exist.
487
*
488
* @param[in] attrs The attributes to obtain the parking area id from
489
* @param[in] tt The trigger type (for user output)
490
* @param[in] tid The trigger id (for user output)
491
* @return The named parking area if it is known, nullptr if empty ID is given
492
* @exception InvalidArgument If the named parking area does not exist
493
*/
494
MSParkingArea* getParkingArea(const SUMOSAXAttributes& attrs,
495
const std::string& tt, const std::string& tid);
496
497
498
/** @brief returns the position on the lane checking it
499
*
500
* This method extracts the position, checks whether it shall be mirrored
501
* and checks whether it is within the lane. If not, an error is reported
502
* and a InvalidArgument is thrown.
503
*
504
* @param[in] attrs The attributes to obtain the position from
505
* @param[in] lane The lane the position shall be valid for
506
* @param[in] tt The trigger type (for user output)
507
* @param[in] tid The trigger id (for user output)
508
* @return The position on the lane
509
* @exception InvalidArgument If the position is beyond the lane
510
*/
511
double getPosition(const SUMOSAXAttributes& attrs,
512
MSLane* lane, const std::string& tt, const std::string& tid, MSEdge* edge = 0);
513
514
/// @}
515
516
517
518
519
protected:
520
/// @brief The parent handler to set for subhandlers
521
NLHandler* myHandler;
522
/// @brief definition of the currently parsed parking area
523
MSParkingArea* myParkingArea;
524
/// @brief The currently parsed stop to add access points to
525
MSStoppingPlace* myCurrentStop;
526
527
bool myHaveWarnedAboutEigen = false;
528
bool myParkingAreaCapacitySet = false;
529
};
530
531