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 MSVehicleType.h
15 : /// @author Christian Roessel
16 : /// @author Daniel Krajzewicz
17 : /// @author Jakob Erdmann
18 : /// @author Michael Behrisch
19 : /// @date Mon, 12 Mar 2001
20 : ///
21 : // The car-following model and parameter
22 : /****************************************************************************/
23 : #pragma once
24 : #include <config.h>
25 :
26 : #include <cassert>
27 : #include <map>
28 : #include <string>
29 : #include <microsim/cfmodels/MSCFModel.h>
30 : #include <utils/common/SUMOTime.h>
31 : #include <utils/common/StdDefs.h>
32 : #include <utils/common/SUMOVehicleClass.h>
33 : #include <utils/common/RandHelper.h>
34 : #include <utils/vehicle/SUMOVTypeParameter.h>
35 : #include <utils/common/RGBColor.h>
36 : #include <utils/emissions/EnergyParams.h>
37 :
38 :
39 : // ===========================================================================
40 : // class declarations
41 : // ===========================================================================
42 : class MSLane;
43 : class MSCFModel;
44 : class SUMOVTypeParameter;
45 :
46 :
47 : // ===========================================================================
48 : // class definitions
49 : // ===========================================================================
50 : /**
51 : * @class MSVehicleType
52 : * @brief The car-following model and parameter
53 : *
54 : * MSVehicleType stores the parameter of a single vehicle type and methods
55 : * that use these for computing the vehicle's car-following behavior
56 : *
57 : * It is assumed that within the simulation many vehicles are using the same
58 : * vehicle type, quite common is using only one vehicle type for all vehicles.
59 : *
60 : * You can think of it like of having a vehicle type for each VW Golf or
61 : * Ford Mustang in your simulation while the car instances just refer to it.
62 : */
63 : class MSVehicleType {
64 : public:
65 : /** @brief Constructor.
66 : *
67 : * @param[in] parameter The vehicle type's parameter
68 : */
69 : MSVehicleType(const SUMOVTypeParameter& parameter);
70 :
71 :
72 : /// @brief Destructor
73 : virtual ~MSVehicleType();
74 :
75 :
76 : /** @brief Returns whether the given parameter was set
77 : * @param[in] what The parameter which one asks for
78 : * @return Whether the given parameter was set
79 : */
80 : bool wasSet(long long int what) const {
81 12635945 : return (myParameter.parametersSet & what) != 0;
82 : }
83 :
84 :
85 : /// @name Atomar getter for simulation
86 : /// @{
87 :
88 : /** @brief Returns the name of the vehicle type
89 : * @return This type's id
90 : */
91 : const std::string& getID() const {
92 3105306 : return myParameter.id;
93 : }
94 :
95 :
96 : /** @brief Returns the running index of the vehicle type
97 : * @return This type's numerical id
98 : */
99 : int getNumericalID() const {
100 639 : return myIndex;
101 : }
102 :
103 :
104 : /** @brief Get vehicle's length [m]
105 : * @return The length vehicles of this type have in m
106 : */
107 : double getLength() const {
108 37480525477 : return myParameter.length;
109 : }
110 :
111 :
112 : /** @brief Get vehicle's length including the minimum gap [m]
113 : * @return The length vehicles of this type have (including the minimum gap in m
114 : */
115 : double getLengthWithGap() const {
116 8385777210 : return myParameter.length + myParameter.minGap;
117 : }
118 :
119 :
120 : /** @brief Get the free space in front of vehicles of this class
121 : * @return The place before the vehicle
122 : */
123 : double getMinGap() const {
124 11461181860 : return myParameter.minGap;
125 : }
126 :
127 : /** @brief Get the minimum lateral gap that vehicles of this type maintain
128 : * @return The place before the vehicle
129 : */
130 : double getMinGapLat() const {
131 33750322 : return myParameter.minGapLat;
132 : }
133 :
134 :
135 : /** @brief Returns the vehicle type's car following model definition (const version)
136 : * @return The vehicle type's car following model definition
137 : */
138 : inline const MSCFModel& getCarFollowModel() const {
139 14357542601 : return *myCarFollowModel;
140 : }
141 :
142 :
143 : /** @brief Returns the vehicle type's car following model definition (non-const version)
144 : * @return The vehicle type's car following model definition
145 : */
146 : inline MSCFModel& getCarFollowModel() {
147 4713504 : return *myCarFollowModel;
148 : }
149 :
150 :
151 : inline LaneChangeModel getLaneChangeModel() const {
152 4631135 : return myParameter.lcModel;
153 : }
154 :
155 :
156 : /** @brief Get vehicle's (technical) maximum speed [m/s].
157 : * @return The maximum speed (in m/s) of vehicles of this types
158 : */
159 : double getMaxSpeed() const {
160 6487946887 : return myParameter.maxSpeed;
161 : }
162 :
163 : /** @brief Returns the vehicles's desired maximum speed
164 : * @return The desired maximum speed of vehicles of this type
165 : */
166 : double getDesiredMaxSpeed() const {
167 6420207437 : return myParameter.desiredMaxSpeed;
168 : }
169 :
170 :
171 : /** @brief Computes and returns the speed deviation
172 : * @return A new, random speed deviation
173 : */
174 : double computeChosenSpeedDeviation(SumoRNG* rng, const double minDev = -1.) const;
175 :
176 :
177 : /** @brief Get the default probability of this vehicle type
178 : * @return The probability to use this type
179 : */
180 : double getDefaultProbability() const {
181 1044 : return myParameter.defaultProbability;
182 : }
183 :
184 :
185 : /** @brief Get this vehicle type's vehicle class
186 : * @return The class of this vehicle type
187 : * @see SUMOVehicleClass
188 : */
189 : SUMOVehicleClass getVehicleClass() const {
190 3795590749 : return myParameter.vehicleClass;
191 : }
192 :
193 :
194 : /** @brief Get this vehicle type's emission class
195 : * @return The emission class of this vehicle type
196 : * @see SUMOEmissionClass
197 : */
198 : SUMOEmissionClass getEmissionClass() const {
199 105808161 : return myParameter.emissionClass;
200 : }
201 :
202 :
203 : /** @brief Get this vehicle type's mass
204 : * @return The mass of this vehicle type
205 : */
206 : inline double getMass() const {
207 4738134 : return myEnergyParams.getDouble(SUMO_ATTR_MASS);
208 : }
209 :
210 :
211 : /** @brief Returns this type's color
212 : * @return The color of this type
213 : */
214 : const RGBColor& getColor() const {
215 22 : return myParameter.color;
216 : }
217 :
218 :
219 : /** @brief Returns the parking access rights of this type
220 : * @return The parking access rights
221 : */
222 : const std::vector<std::string>& getParkingBadges() const {
223 1649 : return myParameter.parkingBadges;
224 : }
225 :
226 :
227 : /** @brief Returns this type's speed factor
228 : * @return The speed factor of this type
229 : */
230 : const Distribution_Parameterized& getSpeedFactor() const {
231 7855 : return myParameter.speedFactor;
232 : }
233 :
234 :
235 : /** @brief Returns this type's default action step length
236 : * @return The default action step length of this type (in ms.)
237 : */
238 : SUMOTime getActionStepLength() const {
239 4742262423 : return myParameter.actionStepLength;
240 : }
241 :
242 :
243 : /** @brief Returns this type's default action step length in seconds
244 : * @return The default action step length of this type (in s.)
245 : */
246 : double getActionStepLengthSecs() const {
247 4289397542 : return myCachedActionStepLengthSecs;
248 : }
249 :
250 :
251 : /** @brief Returns this type's impatience
252 : * @return The impatience of this type
253 : */
254 : double getImpatience() const {
255 615457388 : return myParameter.impatience;
256 : }
257 : /// @}
258 :
259 :
260 :
261 : /// @name Atomar getter for visualization
262 : /// @{
263 :
264 : /** @brief Get the width which vehicles of this class shall have when being drawn
265 : * @return The width of this type's vehicles
266 : */
267 : double getWidth() const {
268 5077490691 : return myParameter.width;
269 : }
270 :
271 : /** @brief Get the width of the passenger compartment when being drawn
272 : * @return The seating space width of this type's vehicles
273 : */
274 : double getSeatingWidth() const {
275 12105 : return myParameter.seatingWidth >= 0 ? myParameter.seatingWidth : myParameter.width;
276 : }
277 :
278 : /** @brief Get the height which vehicles of this class shall have when being drawn
279 : * @return The height of this type's vehicles
280 : */
281 : double getHeight() const {
282 167476 : return myParameter.height;
283 : }
284 :
285 : /** @brief Get this vehicle type's shape
286 : * @return The shape of this vehicle type
287 : * @see SUMOVehicleShape
288 : */
289 : SUMOVehicleShape getGuiShape() const {
290 61379030 : return myParameter.shape;
291 : }
292 :
293 : /** @brief Get this vehicle type's 3D model file name
294 : * @return The model file name of this vehicle type
295 : */
296 : std::string getOSGFile() const {
297 33796 : return myParameter.osgFile;
298 : }
299 :
300 :
301 : /** @brief Get this vehicle type's raster model file name
302 : * @return The raster file name of this vehicle type
303 : */
304 : std::string getImgFile() const {
305 22005 : return myParameter.imgFile;
306 : }
307 :
308 :
309 : /** @brief Get this vehicle type's person capacity
310 : * @return The person capacity of this vehicle type
311 : */
312 : int getPersonCapacity() const {
313 15000679 : return myParameter.personCapacity;
314 : }
315 :
316 :
317 : /** @brief Get this vehicle type's container capacity
318 : * @return The container capacity of this vehicle type
319 : */
320 : int getContainerCapacity() const {
321 13097702 : return myParameter.containerCapacity;
322 : }
323 :
324 : /** @brief Get this vehicle type's loading duration
325 : * @return The time a container / person needs to get loaded on a vehicle of this type
326 : */
327 : SUMOTime getLoadingDuration(const bool isPerson) const {
328 81784 : return isPerson ? myParameter.boardingDuration : myParameter.loadingDuration;
329 : }
330 :
331 : /** @brief Get this vehicle type's boarding duration
332 : * @return The time a container / person needs to get loaded on a vehicle of this type
333 : */
334 : SUMOTime getBoardingDuration(const bool isPerson) const {
335 36 : return isPerson ? myParameter.boardingDuration : myParameter.loadingDuration;
336 : }
337 :
338 : /** @brief Get this person type's factor for loading/boarding duration
339 : * @return The multiplier for the time a container / person needs to get loaded
340 : */
341 : double getBoardingFactor() const {
342 15440 : return myParameter.boardingFactor;
343 : }
344 :
345 :
346 : /** @brief Get vehicle's maximum lateral speed [m/s].
347 : * @return The maximum lateral speed (in m/s) of vehicles of this class
348 : */
349 : double getMaxSpeedLat() const {
350 156563420 : return myParameter.maxSpeedLat;
351 : }
352 :
353 : /** @brief Get vehicle's preferred lateral alignment procedure
354 : * @return The vehicle's preferred lateral alignment procedure
355 : */
356 : const LatAlignmentDefinition& getPreferredLateralAlignment() const {
357 116 : return myParameter.latAlignmentProcedure;
358 : }
359 :
360 : /** @brief Get vehicle's preferred lateral alignment offset (in m from center line)
361 : * @return The vehicle's preferred lateral alignment offset
362 : */
363 : double getPreferredLateralAlignmentOffset() const {
364 441 : return myParameter.latAlignmentOffset;
365 : }
366 :
367 : /// @brief Get offset of first seat from vehicle front
368 : double getFrontSeatPos() const {
369 12105 : return myParameter.frontSeatPos;
370 : }
371 : /// @}
372 :
373 :
374 : /// @name Setter methods
375 : /// @{
376 :
377 : /** @brief Set a new value for this type's acceleration.
378 : * @param[in] accel The new acceleration of this type
379 : */
380 : void setAccel(double accel);
381 :
382 : /** @brief Set a new value for this type's deceleration.
383 : * @param[in] decel The new deceleration of this type
384 : */
385 : void setDecel(double decel);
386 :
387 : /** @brief Set a new value for this type's emergency deceleration.
388 : * @param[in] emergencyDecel The new emergency deceleration of this type
389 : */
390 : void setEmergencyDecel(double emergencyDecel);
391 :
392 : /** @brief Set a new value for this type's apparent deceleration.
393 : * @param[in] apparentDecel The new apparent deceleration of this type
394 : */
395 : void setApparentDecel(double apparentDecel);
396 :
397 : /** @brief Set a new value for this type's maximum acceleration profile.
398 : * @param[in] accelProfile The new acceleration profile of this type
399 : */
400 : void setMaxAccelProfile(std::vector<std::pair<double, double> > accelProfile);
401 :
402 : /** @brief Set a new value for this type's desired acceleration profile.
403 : * @param[in] accelProfile The new acceleration profile of this type
404 : */
405 : void setDesAccelProfile(std::vector<std::pair<double, double> > accelProfile);
406 :
407 : /** @brief Set a new value for this type's imperfection.
408 : * @param[in] imperfection The new imperfection of this type
409 : */
410 : void setImperfection(double imperfection);
411 :
412 : /** @brief Set a new value for this type's headway.
413 : * @param[in] tau The new headway of this type
414 : */
415 : void setTau(double tau);
416 :
417 : /** @brief Set a new value for this type's length
418 : *
419 : * If the given value<0 then the one from the original type will
420 : * be used.
421 : *
422 : * @param[in] length The new length of this type
423 : */
424 : void setLength(const double& length);
425 :
426 :
427 : /** @brief Set a new value for this type's height
428 : *
429 : * If the given value<0 then the one from the original type will
430 : * be used.
431 : *
432 : * @param[in] height The new height of this type
433 : */
434 : void setHeight(const double& height);
435 :
436 :
437 : /** @brief Set a new value for this type's minimum gap
438 : *
439 : * If the given value<0 then the one from the original type will
440 : * be used.
441 : *
442 : * @param[in] minGap The new minimum gap of this type
443 : */
444 : void setMinGap(const double& minGap);
445 :
446 :
447 : /** @brief Set a new value for this type's minimum lataral gap
448 : *
449 : * If the given value<0 then the one from the original type will
450 : * be used.
451 : *
452 : * @param[in] minGapLat The new minimum lateral gap of this type
453 : */
454 : void setMinGapLat(const double& minGapLat);
455 :
456 : /** @brief Set a new value for this type's maximum speed
457 : *
458 : * If the given value<0 then the one from the original type will
459 : * be used.
460 : *
461 : * @param[in] maxSpeed The new maximum speed of this type
462 : */
463 : void setMaxSpeed(const double& maxSpeed);
464 :
465 : /** @brief Set a new value for this type's maximum lateral speed
466 : *
467 : * If the given value<0 then the one from the original type will
468 : * be used.
469 : *
470 : * @param[in] maxSpeedLat The new maximum lateral speed of this type
471 : */
472 : void setMaxSpeedLat(const double& maxSpeedLat);
473 :
474 : /** @brief Set a new value for this type's vehicle class
475 : * @param[in] vclass The new vehicle class of this type
476 : */
477 : void setVClass(SUMOVehicleClass vclass);
478 :
479 : /** @brief Set a new value for this type's gui shape
480 : * @param[in] shapeClass The new shape class of this type
481 : */
482 : void setGUIShape(SUMOVehicleShape shape);
483 :
484 :
485 : /** @brief Set a new value for this type's default probability
486 : *
487 : * If the given value<0 then the one from the original type will
488 : * be used.
489 : *
490 : * @param[in] prob The new default probability of this type
491 : */
492 : void setDefaultProbability(const double& prob);
493 :
494 :
495 : /** @brief Set a new value for this type's speed factor
496 : *
497 : * If the given value<0 then the one from the original type will
498 : * be used.
499 : *
500 : * @param[in] factor The new speed factor of this type
501 : */
502 : void setSpeedFactor(const double& factor);
503 :
504 :
505 : /** @brief Set a new value for this type's speed deviation
506 : *
507 : * If the given value<0 then the one from the original type will
508 : * be used.
509 : *
510 : * @param[in] dev The new speed deviation of this type
511 : */
512 : void setSpeedDeviation(const double& dev);
513 :
514 :
515 : /** @brief Set a new value for this type's action step length
516 : *
517 : * @param[in] actionStepLength The new action step length of this type (in ms.)
518 : * @param[in] resetActionOffset If True (default), the next action point is
519 : * scheduled immediately. if If resetActionOffset == False, the interval
520 : * between the last and the next action point is updated to match the given
521 : * value for all vehicles of this type, or if the latter is smaller than the
522 : * time since the last action point, the next action follows immediately.
523 : *
524 : * @note: Singular vtypes do not update the state of the corresponding vehicle, because
525 : * the global lookup would be too expensive. The caller is responsible to
526 : * perform the actionOffsetReset operation at caller context, where the vehicle is known.
527 : */
528 : void setActionStepLength(const SUMOTime actionStepLength, bool resetActionOffset);
529 :
530 :
531 : /** @brief Set a new value for this type's emission class
532 : * @param[in] eclass The new emission class of this type
533 : */
534 : void setEmissionClass(SUMOEmissionClass eclass);
535 :
536 :
537 : /** @brief Set a new value for this type's mass
538 : * @param[in] mass The new mass of this type
539 : */
540 : void setMass(double mass);
541 :
542 :
543 : /** @brief Set a new value for this type's color
544 : * @param[in] color The new color of this type
545 : */
546 : void setColor(const RGBColor& color);
547 :
548 :
549 : /** @brief Set a new value for parking access rights of this type
550 : * @param[in] badges The new parking access rights of this type
551 : */
552 : void setParkingBadges(const std::vector<std::string>& badges);
553 :
554 :
555 : /** @brief Set a new value for this type's width
556 : *
557 : * If the given value<0 then the one from the original type will
558 : * be used.
559 : *
560 : * @param[in] width The new width of this type
561 : */
562 : void setWidth(const double& width);
563 :
564 :
565 : /** @brief Set a new value for this type's shape
566 : * @param[in] shape The new shape of this type
567 : */
568 : void setShape(SUMOVehicleShape shape);
569 :
570 : /** @brief Set a new value for this type's boardingDuration
571 : * @param[in] boardingDuration The new boardingDuration of this type
572 : * @param[in] isPerson Whether to set boardingDuration or loadingDuration
573 : */
574 : void setBoardingDuration(SUMOTime duration, bool isPerson = true);
575 :
576 : /** @brief Set a new value for this type's impatience
577 : * @param[in] impatience The new impatience of this type
578 : */
579 : void setImpatience(const double impatience);
580 :
581 : /** @brief Set vehicle's preferred lateral alignment
582 : */
583 : void setPreferredLateralAlignment(const LatAlignmentDefinition& latAlignment, double latAlignmentOffset = 0.0);
584 :
585 : /** @brief Set traffic scaling factor
586 : */
587 : void setScale(double value);
588 :
589 : /** @brief Set lcContRight (which is the only lc-attribute not used within the laneChange model)
590 : */
591 : void setLcContRight(const std::string& value);
592 : /// @}
593 :
594 :
595 :
596 : /// @name methods for building vehicle types
597 : /// @{
598 :
599 : /** @brief Builds the microsim vehicle type described by the given parameter
600 : * @param[in] from The vehicle type description
601 : * @return The built vehicle type
602 : * @exception ProcessError on false values (not et used)
603 : */
604 : static MSVehicleType* build(SUMOVTypeParameter& from, const std::string& fileName = "");
605 :
606 : /// @brief Accessor function for parameter equivalent returning entry time for a specific manoeuver angle
607 : SUMOTime getEntryManoeuvreTime(const int angle) const;
608 : /// @brief Accessor function for parameter equivalent returning exit time for a specific manoeuver angle
609 : SUMOTime getExitManoeuvreTime(const int angle) const;
610 :
611 :
612 : /** @brief Duplicates the microsim vehicle type giving the newly created type the given id,
613 : * marking it as vehicle specific
614 : * @param[in] id The new id of the type
615 : * @return The built vehicle type
616 : * @note This method is used in case that a vType is meant to be used only for a specific vehicle
617 : * The created vType will be removed with the vehicle or if it is assigned a new type.
618 : */
619 : MSVehicleType* buildSingularType(const std::string& id) const;
620 :
621 :
622 : /** @brief Duplicates the microsim vehicle type giving the newly created type the given id.
623 : *
624 : * @param[in] id The new id of the type
625 : * @param[in] persistent If true the created vType will be persistent and can be used by several vehicles,
626 : * otherwise it may be removed before simulation end, @see buildSingularType()
627 : * @return The built vehicle type
628 : */
629 : MSVehicleType* duplicateType(const std::string& id, bool persistent) const;
630 : /// @}
631 :
632 :
633 : /** @brief Returns whether this type belongs to a single vehicle only (was modified)
634 : * @return Whether this vehicle type is based on a different one, and belongs to one vehicle only
635 : */
636 : bool isVehicleSpecific() const {
637 5301727 : return myOriginalType != nullptr;
638 : }
639 :
640 :
641 : /** @brief Returns the id of the original vehicle type if this is a vehicle specific type, the id otherwise
642 : * @return the original vehicle type id
643 : */
644 : const std::string& getOriginalID() const {
645 2218913 : return myOriginalType != nullptr ? myOriginalType->getID() : getID();
646 : }
647 :
648 :
649 : const SUMOVTypeParameter& getParameter() const {
650 3232664081 : return myParameter;
651 : }
652 :
653 : /** @brief Checks whether vehicle type parameters may be problematic
654 : * (Currently, only the value for the action step length is
655 : * compared with the value for the desired headway time.)
656 : */
657 : void check();
658 :
659 : /// @brief retrieve parameters for the energy consumption model
660 : inline const EnergyParams* getEmissionParameters() const {
661 922397 : return &myEnergyParams;
662 : }
663 :
664 : private:
665 : /// @brief the parameter container
666 : SUMOVTypeParameter myParameter;
667 :
668 : const EnergyParams myEnergyParams;
669 :
670 : /// @brief the vtypes actionsStepLength in seconds (cached because needed very often)
671 : double myCachedActionStepLengthSecs;
672 :
673 : /// @brief Indicator whether the user was already warned once about an action step length
674 : /// larger than the desired time headway.
675 : bool myWarnedActionStepLengthTauOnce;
676 : bool myWarnedActionStepLengthBallisticOnce;
677 : bool myWarnedStepLengthTauOnce;
678 :
679 : /// @brief the running index
680 : const int myIndex;
681 :
682 : /// @brief instance of the car following model.
683 : MSCFModel* myCarFollowModel;
684 :
685 : /// @brief The original type
686 : const MSVehicleType* myOriginalType;
687 :
688 : /// @brief next value for the running index
689 : static int myNextIndex;
690 :
691 :
692 : private:
693 : /// @brief Invalidated copy constructor
694 : MSVehicleType(const MSVehicleType&) = delete;
695 :
696 : /// @brief Invalidated assignment operator
697 : MSVehicleType& operator=(const MSVehicleType&) = delete;
698 : };
|