Line data Source code
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 SUMOVTypeParameter.h
15 : /// @author Daniel Krajzewicz
16 : /// @author Jakob Erdmann
17 : /// @author Michael Behrisch
18 : /// @date 10.09.2009
19 : ///
20 : // Structure representing possible vehicle parameter
21 : /****************************************************************************/
22 : #pragma once
23 : #include <config.h>
24 :
25 : #include <string>
26 : #include <map>
27 : #include <utils/common/Parameterised.h>
28 : #include <utils/common/RGBColor.h>
29 : #include <utils/common/SUMOTime.h>
30 : #include <utils/common/SUMOVehicleClass.h>
31 : #include <utils/common/LinearApproxHelpers.h>
32 : #include <utils/distribution/Distribution_Parameterized.h>
33 :
34 : // ===========================================================================
35 : // class declarations
36 : // ===========================================================================
37 : class OutputDevice;
38 : class OptionsCont;
39 :
40 :
41 : // ===========================================================================
42 : // value definitions
43 : // ===========================================================================
44 : const long long int VTYPEPARS_LENGTH_SET = 1;
45 : const long long int VTYPEPARS_MINGAP_SET = 1 << 1;
46 : const long long int VTYPEPARS_MAXSPEED_SET = 1 << 2;
47 : const long long int VTYPEPARS_PROBABILITY_SET = 1 << 3;
48 : const long long int VTYPEPARS_SPEEDFACTOR_SET = 1 << 4;
49 : const long long int VTYPEPARS_EMISSIONCLASS_SET = 1 << 5;
50 : const long long int VTYPEPARS_COLOR_SET = 1 << 6;
51 : const long long int VTYPEPARS_VEHICLECLASS_SET = 1 << 7;
52 : const long long int VTYPEPARS_WIDTH_SET = 1 << 8;
53 : const long long int VTYPEPARS_HEIGHT_SET = 1 << 9;
54 : const long long int VTYPEPARS_SHAPE_SET = 1 << 10;
55 : const long long int VTYPEPARS_OSGFILE_SET = 1 << 11;
56 : const long long int VTYPEPARS_IMGFILE_SET = 1 << 12;
57 : const long long int VTYPEPARS_IMPATIENCE_SET = 1 << 13;
58 : const long long int VTYPEPARS_LANE_CHANGE_MODEL_SET = 1 << 14;
59 : const long long int VTYPEPARS_PERSON_CAPACITY = 1 << 15;
60 : const long long int VTYPEPARS_BOARDING_DURATION = 1 << 16;
61 : const long long int VTYPEPARS_CONTAINER_CAPACITY = 1 << 17;
62 : const long long int VTYPEPARS_LOADING_DURATION = 1 << 18;
63 : const long long int VTYPEPARS_CAR_FOLLOW_MODEL = 1 << 19;
64 : const long long int VTYPEPARS_MAXSPEED_LAT_SET = 1 << 20;
65 : const long long int VTYPEPARS_LATALIGNMENT_SET = 1 << 21;
66 : const long long int VTYPEPARS_MINGAP_LAT_SET = 1 << 22;
67 : const long long int VTYPEPARS_ACTIONSTEPLENGTH_SET = 1 << 23;
68 : const long long int VTYPEPARS_DESIRED_MAXSPEED_SET = 1 << 24;
69 : const long long int VTYPEPARS_CARRIAGE_LENGTH_SET = 1 << 25;
70 : const long long int VTYPEPARS_LOCOMOTIVE_LENGTH_SET = 1 << 26;
71 : const long long int VTYPEPARS_CARRIAGE_GAP_SET = 1 << 27;
72 : const long long int VTYPEPARS_CARRIAGE_DOORS_SET = 1 << 28;
73 : const long long int VTYPEPARS_MANEUVER_ANGLE_TIMES_SET = 1 << 29;
74 : const long long int VTYPEPARS_FRONT_SEAT_POS_SET = 1 << 30;
75 : const long long int VTYPEPARS_SCALE_SET = (long long int)1 << 31;
76 : const long long int VTYPEPARS_MASS_SET = (long long int)1 << 32;
77 : const long long int VTYPEPARS_TTT_SET = (long long int)1 << 33;
78 : const long long int VTYPEPARS_TTT_BIDI_SET = (long long int)1 << 34;
79 : const long long int VTYPEPARS_SEATING_WIDTH_SET = (long long int)1 << 35;
80 : const long long int VTYPEPARS_SPEEDFACTOR_PREMATURE_SET = (long long int)1 << 36;
81 : const long long int VTYPEPARS_PARKING_BADGES_SET = (long long int)1 << 37;
82 : const long long int VTYPEPARS_BOARDING_FACTOR_SET = (long long int)1 << 38;
83 :
84 :
85 : const int VTYPEPARS_DEFAULT_EMERGENCYDECEL_DEFAULT = -1;
86 : const int VTYPEPARS_DEFAULT_EMERGENCYDECEL_DECEL = -2;
87 :
88 :
89 : // ===========================================================================
90 : // enum definitions
91 : // ===========================================================================
92 : /**
93 : * @enum LatAlignmentDefinition
94 : * @brief Possible ways to choose the lateral alignment, i.e., how vehicles align themselves within their lane
95 : */
96 : enum class LatAlignmentDefinition {
97 : /// @brief No information given; use default
98 : DEFAULT,
99 : /// @brief The alignment as offset is given
100 : GIVEN,
101 : /// @brief drive on the right side
102 : RIGHT,
103 : /// @brief drive in the middle
104 : CENTER,
105 : /// @brief maintain the current alignment
106 : ARBITRARY,
107 : /// @brief align with the closest sublane border
108 : NICE,
109 : /// @brief align with the rightmost sublane that allows keeping the current speed
110 : COMPACT,
111 : /// @brief drive on the left side
112 : LEFT
113 : };
114 :
115 :
116 : // ===========================================================================
117 : // struct definitions
118 : // ===========================================================================
119 : /**
120 : * @class SUMOVTypeParameter
121 : * @brief Structure representing possible vehicle parameter
122 : */
123 : class SUMOVTypeParameter : public Parameterised {
124 :
125 : public:
126 : /// @brief struct for default values that depend of VClass
127 350845 : struct VClassDefaultValues {
128 : /// @brief parameter constructor
129 : VClassDefaultValues(SUMOVehicleClass vClass);
130 :
131 : /// @brief The physical vehicle length
132 : double length;
133 :
134 : /// @brief This class' free space in front of the vehicle itself
135 : double minGap;
136 :
137 : /// @brief The vehicle type's minimum lateral gap [m]
138 : double minGapLat;
139 :
140 : /// @brief The vehicle type's maximum speed [m/s] (technical limit, not subject to speed deviation)
141 : double maxSpeed;
142 :
143 : /// @brief The vehicle type's desired maximum speed [m/s]
144 : double desiredMaxSpeed;
145 :
146 : /// @brief This class' width
147 : double width;
148 :
149 : /// @brief This class' height
150 : double height;
151 :
152 : /// @brief This class' shape
153 : SUMOVehicleShape shape;
154 :
155 : /// @brief The emission class of this vehicle
156 : SUMOEmissionClass emissionClass;
157 :
158 : /// @brief This class' mass
159 : double mass;
160 :
161 : /// @brief The factor by which the maximum speed may deviate from the allowed max speed on the street
162 : Distribution_Parameterized speedFactor;
163 :
164 : /// @brief The person capacity of the vehicle
165 : int personCapacity;
166 :
167 : /// @brief The container capacity of the vehicle
168 : int containerCapacity;
169 :
170 : /// @brief 3D model file for this class
171 : std::string osgFile;
172 :
173 : /// @brief the length of train carriages
174 : double carriageLength;
175 :
176 : /// @brief the length of train locomotive
177 : double locomotiveLength;
178 :
179 : /// @brief the number of doors per carriage
180 : int carriageDoors;
181 :
182 : /// @brief the width of the carriage doors
183 : double carriageDoorWidth;
184 :
185 : /// @brief the maximum distance between platform and train
186 : double maxPlatformDistance;
187 :
188 : /// @brief the lateral alignment procedure
189 : LatAlignmentDefinition latAlignmentProcedure;
190 :
191 : private:
192 : /// @brief default constructor
193 : VClassDefaultValues();
194 : };
195 :
196 : /** @brief Constructor
197 : *
198 : * Initialises the structure with default values
199 : */
200 : SUMOVTypeParameter(const std::string& vtid, const SUMOVehicleClass vc = SVC_IGNORING);
201 :
202 : /// @brief virtual destructor
203 1320167 : virtual ~SUMOVTypeParameter() {};
204 :
205 : /** @brief Returns whether the given parameter was set
206 : * @param[in] what The parameter which one asks for
207 : * @return Whether the given parameter was set
208 : */
209 : bool wasSet(long long int what) const {
210 1095666 : return (parametersSet & what) != 0;
211 : }
212 :
213 : /** @brief Writes the vtype
214 : *
215 : * @param[in, out] dev The device to write into
216 : * @exception IOError not yet implemented
217 : */
218 : void write(OutputDevice& dev) const;
219 :
220 : /** @brief Returns the named value from the map, or the default if it is not contained there
221 : * @param[in] attr The corresponding xml attribute
222 : * @param[in] defaultValue The value to return if the given map does not contain the named variable
223 : * @return The named value from the map or the default if it does not exist there
224 : */
225 : double getCFParam(const SumoXMLAttr attr, const double defaultValue) const;
226 :
227 : /// @brief retrieve value table from cfParameter
228 : std::vector<double> getCFValueTable(SumoXMLAttr attr) const;
229 :
230 : /** @brief Returns the named value from the map, or the default if it is not contained there
231 : * @param[in] attr The corresponding xml attribute
232 : * @param[in] defaultValue The value to return if the given map does not contain the named variable
233 : * @return The named value from the map or the default if it does not exist there
234 : */
235 : std::string getCFParamString(const SumoXMLAttr attr, const std::string defaultValue) const;
236 :
237 : /** @brief Returns the named value from the map, or the default if it is not contained there
238 : * @param[in] attr The corresponding xml attribute
239 : * @param[in] defaultValue The value to return if the given map does not contain the named variable
240 : * @return The named value from the map or the default if it does not exist there
241 : */
242 : double getLCParam(const SumoXMLAttr attr, const double defaultValue) const;
243 :
244 : /** @brief Returns the named value from the map, or the default if it is not contained there
245 : * @param[in] attr The corresponding xml attribute
246 : * @param[in] defaultValue The value to return if the given map does not contain the named variable
247 : * @return The named value from the map or the default if it does not exist there
248 : */
249 : std::string getLCParamString(const SumoXMLAttr attr, const std::string& defaultValue) const;
250 :
251 : /// @brief sub-model parameters
252 : typedef std::map<SumoXMLAttr, std::string> SubParams;
253 :
254 : /// @brief Returns the LC parameter
255 : const SubParams& getLCParams() const;
256 :
257 : /** @brief Returns the named value from the map, or the default if it is not contained there
258 : * @param[in] attr The corresponding xml attribute
259 : * @param[in] defaultValue The value to return if the given map does not contain the named variable
260 : * @return The named value from the map or the default if it does not exist there
261 : */
262 : double getJMParam(const SumoXMLAttr attr, const double defaultValue) const;
263 :
264 : /** @brief Returns the named value from the map, or the default if it is not contained there
265 : * @param[in] attr The corresponding xml attribute
266 : * @param[in] defaultValue The value to return if the given map does not contain the named variable
267 : * @return The named value from the map or the default if it does not exist there
268 : */
269 : std::string getJMParamString(const SumoXMLAttr attr, const std::string defaultValue) const;
270 :
271 : void cacheParamRestrictions(const std::vector<std::string>& restrictionKeys);
272 :
273 : /// @brief init Rail Visualization Parameters
274 : void initRailVisualizationParameters(const std::string fileName = "");
275 :
276 : /// @brief The vehicle type's id
277 : std::string id;
278 :
279 : /// @brief The physical vehicle length
280 : double length;
281 :
282 : /// @brief This class' free space in front of the vehicle itself
283 : double minGap;
284 :
285 : /// @brief The vehicle type's (technical) maximum speed [m/s]
286 : double maxSpeed;
287 :
288 : /// @brief The vehicle type's desired maximum speed [m/s]
289 : double desiredMaxSpeed;
290 :
291 : /// @brief The vehicle type's default actionStepLength [ms], i.e. the interval between two control actions.
292 : /// The default value of 0ms. induces the value to be traced from MSGlobals::gActionStepLength
293 : SUMOTime actionStepLength;
294 :
295 : /// @brief The probability when being added to a distribution without an explicit probability
296 : double defaultProbability;
297 :
298 : /// @brief The factor by which the maximum speed may deviate from the allowed max speed on the street
299 : Distribution_Parameterized speedFactor;
300 :
301 : /// @brief The emission class of this vehicle
302 : SUMOEmissionClass emissionClass;
303 :
304 : /// @brief The mass
305 : double mass;
306 :
307 : /// @brief The color
308 : RGBColor color;
309 :
310 : /// @brief The vehicle's class
311 : SUMOVehicleClass vehicleClass;
312 :
313 : /// @brief The vehicle's impatience (willingness to obstruct others)
314 : double impatience;
315 :
316 : /// @brief The person capacity of the vehicle
317 : int personCapacity;
318 :
319 : /// @brief The container capacity of the vehicle
320 : int containerCapacity;
321 :
322 : /// @brief The time a person needs to board the vehicle
323 : SUMOTime boardingDuration;
324 :
325 : /// @brief The time a container needs to get loaded on the vehicle
326 : SUMOTime loadingDuration;
327 :
328 : /// @brief individual scaling factor (-1 for undefined)
329 : double scale;
330 :
331 : /// @name Values for drawing this class' vehicles
332 : /// @{
333 :
334 : /// @brief This class' width
335 : double width;
336 :
337 : /// @brief This class' height
338 : double height;
339 :
340 : /// @brief This class' shape
341 : SUMOVehicleShape shape;
342 :
343 : /// @brief 3D model file for this class
344 : std::string osgFile;
345 :
346 : /// @brief Image file for this class
347 : std::string imgFile;
348 :
349 : /// @brief Image files for additional carriages
350 : std::vector<std::string> carriageImages;
351 : /// @}
352 :
353 :
354 : /// @brief The enum-representation of the car-following model to use
355 : SumoXMLTag cfModel;
356 :
357 : /// @brief Car-following parameter
358 : SubParams cfParameter;
359 :
360 : /// @brief Lane-changing parameter
361 : SubParams lcParameter;
362 :
363 : /// @brief Junction-model parameter
364 : SubParams jmParameter;
365 :
366 : /// @brief The lane-change model to use
367 : LaneChangeModel lcModel;
368 :
369 : /// @brief The vehicle type's maximum lateral speed [m/s]
370 : double maxSpeedLat;
371 :
372 : /// @brief (optional) The vehicle's desired lateral alignment as offset in m from center line
373 : double latAlignmentOffset;
374 :
375 : /// @brief Information on how the vehicle shall choose the lateral alignment
376 : LatAlignmentDefinition latAlignmentProcedure;
377 :
378 : /// @brief The vehicle type's minimum lateral gap [m]
379 : double minGapLat;
380 :
381 : /// @brief the scaling factor when drawing the object
382 : double scaleVisual;
383 :
384 : /// @brief the length of train carriages
385 : double carriageLength;
386 :
387 : /// @brief the length of the locomotive
388 : double locomotiveLength;
389 :
390 : /// @brief the length of the gap between carriages
391 : double carriageGap;
392 :
393 : /// @brief the number of doors per carriage
394 : int carriageDoors;
395 :
396 : /// @brief the width of the carriage doors
397 : double carriageDoorWidth;
398 :
399 : /// @brief the maximum distance between platform and train
400 : double maxPlatformDistance;
401 :
402 : /// @brief the custom time-to-teleport for this type
403 : SUMOTime timeToTeleport;
404 :
405 : /// @brief the custom time-to-teleport.bidi for this type
406 : SUMOTime timeToTeleportBidi;
407 :
408 : /// @brief the possible speed reduction when a train is ahead of schedule
409 : double speedFactorPremature;
410 :
411 : /// @brief the offset of the first person seat from the front of the vehicle
412 : double frontSeatPos;
413 :
414 : /// @brief width to be used when comping seats
415 : double seatingWidth;
416 :
417 : /// @brief the parking access rights
418 : std::vector<std::string> parkingBadges;
419 :
420 : /// @brief factor for boardingDuration / loadingDuration
421 : double boardingFactor;
422 :
423 : /// @brief Information for the router which parameter were set
424 : long long int parametersSet;
425 :
426 : /// @brief Information whether this type was already saved (needed by routers)
427 : mutable bool saved;
428 :
429 : /// @brief Information whether this is a type-stub, being only referenced but not defined (needed by routers)
430 : bool onlyReferenced;
431 :
432 : /// @brief cached value of parameters which may restrict access to certain edges
433 : std::vector<double> paramRestrictions;
434 :
435 : /// @brief allowed attrs for the junction model
436 : static std::set<SumoXMLAttr> AllowedJMAttrs;
437 :
438 : /// @brief satisfy vType / router template requirements
439 : inline double getLength() const {
440 : return length;
441 : }
442 :
443 : /** @brief Returns the default acceleration for the given vehicle class
444 : * This needs to be a function because the actual value is stored in the car following model
445 : * @param[in] vc the vehicle class
446 : * @return the acceleration in m/s^2
447 : */
448 : static double getDefaultAccel(const SUMOVehicleClass vc = SVC_IGNORING);
449 :
450 : /** @brief Returns the default deceleration for the given vehicle class
451 : * This needs to be a function because the actual value is stored in the car following model
452 : * @param[in] vc the vehicle class
453 : * @return the deceleration in m/s^2
454 : */
455 : static double getDefaultDecel(const SUMOVehicleClass vc = SVC_IGNORING);
456 :
457 : /** @brief Returns the default emergency deceleration for the given vehicle class
458 : * This needs to be a function because the actual value is stored in the car following model
459 : * @param[in] vc the vehicle class
460 : * @param[in] decel the deceleration of the vehicle type
461 : * @return the emergency deceleration in m/s^2
462 : */
463 : static double getDefaultEmergencyDecel(const SUMOVehicleClass vc, double decel, double defaultOption);
464 :
465 : /** @brief Returns the default driver's imperfection (sigma or epsilon in Krauss' model) for the given vehicle class
466 : * This needs to be a function because the actual value is stored in the car following model
467 : * @param[in] vc the vehicle class
468 : * @return the imperfection as a value between 0 and 1
469 : */
470 : static double getDefaultImperfection(const SUMOVehicleClass vc = SVC_IGNORING);
471 :
472 : /// @brief return the default parameters, this is a function due to the http://www.parashift.com/c++-faq/static-init-order.html
473 : static const SUMOVTypeParameter& getDefault();
474 :
475 : /** @brief Parses and validates a given latAlignment value
476 : * @param[in] val The latAlignment value to parse
477 : * @param[out] lao The parsed lateral alignment offset, if given
478 : * @param[out] lad The parsed latAlignment definition
479 : * @return Whether the given value is a valid latAlignment definition
480 : */
481 : static bool parseLatAlignment(const std::string& val, double& lao, LatAlignmentDefinition& lad);
482 :
483 : static inline bool isValidLatAlignment(const std::string& val) {
484 : double lao;
485 : LatAlignmentDefinition lad;
486 : return SUMOVTypeParameter::parseLatAlignment(val, lao, lad);
487 : }
488 :
489 : /// @brief return all valid strings for latAlignment
490 : // XXX: does not include valid float strings
491 : static inline std::vector<std::string> getLatAlignmentStrings() {
492 : std::vector<std::string> result;
493 : result.push_back("right");
494 : result.push_back("center");
495 : result.push_back("arbitrary");
496 : result.push_back("nice");
497 : result.push_back("compact");
498 : result.push_back("left");
499 : return result;
500 : }
501 :
502 : /// @brief Map of manoeuver angles versus the times (entry, exit) to execute the manoeuver
503 : std::map<int, std::pair<SUMOTime, SUMOTime>> myManoeuverAngleTimes;
504 :
505 : /** @brief Initialise the default mapping between manoeuver angle and times dependant on vehicle class
506 : * @param[in] vclass The vehicle class
507 : * @note These default values were 'informed' by a paper by Purnawan, and Yousif:
508 : * @note usir.salford.ac.uk/id/eprint/9729/3/Paper_Kassel_%28Seminar%29.pdf (no reverse park values in paper)
509 : * @note truck values were simply doubled - all are modifiable in the vehicle type definition and there is no limit to the no of triplets
510 : * TODO:
511 : * optionality for 90 degree bay entry (forwards or reverse) not implemented - probably should be a driver propensity
512 : * the defaults assume reverse entry - a reverse manoeuvre has to happen and there will be a small difference in timings depending whether its reverse in or out
513 : */
514 : void setManoeuverAngleTimes(const SUMOVehicleClass vclass);
515 :
516 : /** @brief Returns the time that will be needed for the vehicle type to execute the (entry) manoeuvre (and be blocking the lane)
517 : * @param[in] angle The angle, in degrees through which the vehicle needs to manoeuver (0-180 degrees)
518 : * @return The SUMOTime value
519 : */
520 : SUMOTime getEntryManoeuvreTime(const int angle) const;
521 :
522 : /** @brief Returns the time that will be needed for the vehicle type to execute the (exit) manoeuvre (and be blocking the lane)
523 : * @param[in] angle The angle, in degrees through which the vehicle needs to manoeuver (0-180 degrees)
524 : * @return The SUMOTime value
525 : */
526 : SUMOTime getExitManoeuvreTime(const int angle) const;
527 :
528 : /** @brief Returns myManoeuverAngleTimes as a string for xml output
529 : * @return A string of , separated triplets (angle entry-time exit-time)
530 : */
531 : std::string getManoeuverAngleTimesS() const;
532 :
533 : /// @brief return time-to-teleport (either custom or default)
534 : SUMOTime getTimeToTeleport(SUMOTime defaultValue) const;
535 :
536 : /// @brief return time-to-teleport.bidi (either custom or default)
537 : SUMOTime getTimeToTeleportBidi(SUMOTime defaultValue) const;
538 :
539 : /** @brief Returns the default maximum acceleration profile for the given vehicle class
540 : * This needs to be a function because the actual profile is stored in the car following model
541 : * @param[in] vc the vehicle class
542 : * @param[in] maxAccel the maximum acceleration for all speeds
543 : * @return the maximum acceleration profile in m/s^2
544 : */
545 : static LinearApproxHelpers::LinearApproxMap getDefaultMaxAccelProfile(const SUMOVehicleClass vc, double maxAccel);
546 :
547 : /** @brief Returns the default desired acceleration profile for the given vehicle class
548 : * This needs to be a function because the actual profile is stored in the car following model
549 : * @param[in] vc the vehicle class
550 : * @param[in] desAccel the desired acceleration for all speeds
551 : * @return the desired acceleration profile in m/s^2
552 : */
553 : static LinearApproxHelpers::LinearApproxMap getDefaultDesAccelProfile(const SUMOVehicleClass vc, double desAccel);
554 :
555 : /** @brief Returns the named value from the map, or the default if it is not contained there
556 : * @param[in] attr The corresponding xml attribute
557 : * @param[in] defaultValue The value to return if the given map does not contain the named variable
558 : * @return The named value from the map or the default if it does not exist there
559 : */
560 : LinearApproxHelpers::LinearApproxMap getCFProfile(const SumoXMLAttr attr, const LinearApproxHelpers::LinearApproxMap& defaultProfile) const;
561 :
562 : /** @brief Creates a vector of pairs from a string
563 : * @param[in] profile The string containing pairs
564 : * @return The vector of pairs
565 : */
566 : std::vector<std::pair<double, double> > createCFProfile(const SumoXMLAttr attr, const std::string profile) const;
567 : };
|