Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2001-2024 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 10362053 : 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 3919684 : 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 33297637760 : 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 7887864367 : 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 10186980516 : 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 33333262 : 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 930061395 : 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 12882204755 : return *myCarFollowModel;
148 : }
149 :
150 :
151 : inline LaneChangeModel getLaneChangeModel() const {
152 4379789 : 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 5977647134 : 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 6554654566 : 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 1042 : 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 5290122628 : 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 100951222 : 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 90 : return myParameter.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 14 : 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 14 : 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 66605 : 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 4863576437 : 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 3828362006 : 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 587649681 : 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 4479759458 : 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 13353 : 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 145548 : 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 48338467 : 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 29452 : 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 21787 : 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 11889951 : 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 9122871 : 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 71929 : 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 20 : 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 14648 : 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 144462043 : 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 92 : 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 13353 : 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 imperfection.
398 : * @param[in] imperfection The new imperfection of this type
399 : */
400 : void setImperfection(double imperfection);
401 :
402 : /** @brief Set a new value for this type's headway.
403 : * @param[in] tau The new headway of this type
404 : */
405 : void setTau(double tau);
406 :
407 : /** @brief Set a new value for this type's length
408 : *
409 : * If the given value<0 then the one from the original type will
410 : * be used.
411 : *
412 : * @param[in] length The new length of this type
413 : */
414 : void setLength(const double& length);
415 :
416 :
417 : /** @brief Set a new value for this type's height
418 : *
419 : * If the given value<0 then the one from the original type will
420 : * be used.
421 : *
422 : * @param[in] height The new height of this type
423 : */
424 : void setHeight(const double& height);
425 :
426 :
427 : /** @brief Set a new value for this type's minimum gap
428 : *
429 : * If the given value<0 then the one from the original type will
430 : * be used.
431 : *
432 : * @param[in] minGap The new minimum gap of this type
433 : */
434 : void setMinGap(const double& minGap);
435 :
436 :
437 : /** @brief Set a new value for this type's minimum lataral gap
438 : *
439 : * If the given value<0 then the one from the original type will
440 : * be used.
441 : *
442 : * @param[in] minGapLat The new minimum lateral gap of this type
443 : */
444 : void setMinGapLat(const double& minGapLat);
445 :
446 : /** @brief Set a new value for this type's maximum speed
447 : *
448 : * If the given value<0 then the one from the original type will
449 : * be used.
450 : *
451 : * @param[in] maxSpeed The new maximum speed of this type
452 : */
453 : void setMaxSpeed(const double& maxSpeed);
454 :
455 : /** @brief Set a new value for this type's maximum lateral speed
456 : *
457 : * If the given value<0 then the one from the original type will
458 : * be used.
459 : *
460 : * @param[in] maxSpeedLat The new maximum lateral speed of this type
461 : */
462 : void setMaxSpeedLat(const double& maxSpeedLat);
463 :
464 : /** @brief Set a new value for this type's vehicle class
465 : * @param[in] vclass The new vehicle class of this type
466 : */
467 : void setVClass(SUMOVehicleClass vclass);
468 :
469 :
470 : /** @brief Set a new value for this type's default probability
471 : *
472 : * If the given value<0 then the one from the original type will
473 : * be used.
474 : *
475 : * @param[in] prob The new default probability of this type
476 : */
477 : void setDefaultProbability(const double& prob);
478 :
479 :
480 : /** @brief Set a new value for this type's speed factor
481 : *
482 : * If the given value<0 then the one from the original type will
483 : * be used.
484 : *
485 : * @param[in] factor The new speed factor of this type
486 : */
487 : void setSpeedFactor(const double& factor);
488 :
489 :
490 : /** @brief Set a new value for this type's speed deviation
491 : *
492 : * If the given value<0 then the one from the original type will
493 : * be used.
494 : *
495 : * @param[in] dev The new speed deviation of this type
496 : */
497 : void setSpeedDeviation(const double& dev);
498 :
499 :
500 : /** @brief Set a new value for this type's action step length
501 : *
502 : * @param[in] actionStepLength The new action step length of this type (in ms.)
503 : * @param[in] resetActionOffset If True (default), the next action point is
504 : * scheduled immediately. if If resetActionOffset == False, the interval
505 : * between the last and the next action point is updated to match the given
506 : * value for all vehicles of this type, or if the latter is smaller than the
507 : * time since the last action point, the next action follows immediately.
508 : *
509 : * @note: Singular vtypes do not update the state of the corresponding vehicle, because
510 : * the global lookup would be too expensive. The caller is responsible to
511 : * perform the actionOffsetReset operation at caller context, where the vehicle is known.
512 : */
513 : void setActionStepLength(const SUMOTime actionStepLength, bool resetActionOffset);
514 :
515 :
516 : /** @brief Set a new value for this type's emission class
517 : * @param[in] eclass The new emission class of this type
518 : */
519 : void setEmissionClass(SUMOEmissionClass eclass);
520 :
521 :
522 : /** @brief Set a new value for this type's mass
523 : * @param[in] mass The new mass of this type
524 : */
525 : void setMass(double mass);
526 :
527 :
528 : /** @brief Set a new value for this type's color
529 : * @param[in] color The new color of this type
530 : */
531 : void setColor(const RGBColor& color);
532 :
533 :
534 : /** @brief Set a new value for parking access rights of this type
535 : * @param[in] badges The new parking access rights of this type
536 : */
537 : void setParkingBadges(const std::vector<std::string>& badges);
538 :
539 :
540 : /** @brief Set a new value for this type's width
541 : *
542 : * If the given value<0 then the one from the original type will
543 : * be used.
544 : *
545 : * @param[in] width The new width of this type
546 : */
547 : void setWidth(const double& width);
548 :
549 :
550 : /** @brief Set a new value for this type's shape
551 : * @param[in] shape The new shape of this type
552 : */
553 : void setShape(SUMOVehicleShape shape);
554 :
555 : /** @brief Set a new value for this type's boardingDuration
556 : * @param[in] boardingDuration The new boardingDuration of this type
557 : * @param[in] isPerson Whether to set boardingDuration or loadingDuration
558 : */
559 : void setBoardingDuration(SUMOTime duration, bool isPerson = true);
560 :
561 : /** @brief Set a new value for this type's impatience
562 : * @param[in] impatience The new impatience of this type
563 : */
564 : void setImpatience(const double impatience);
565 :
566 : /** @brief Set vehicle's preferred lateral alignment
567 : */
568 : void setPreferredLateralAlignment(const LatAlignmentDefinition& latAlignment, double latAlignmentOffset = 0.0);
569 :
570 : /** @brief Set traffic scaling factor
571 : */
572 : void setScale(double value);
573 : /// @}
574 :
575 :
576 :
577 : /// @name methods for building vehicle types
578 : /// @{
579 :
580 : /** @brief Builds the microsim vehicle type described by the given parameter
581 : * @param[in] from The vehicle type description
582 : * @return The built vehicle type
583 : * @exception ProcessError on false values (not et used)
584 : */
585 : static MSVehicleType* build(SUMOVTypeParameter& from);
586 :
587 : /// @brief Accessor function for parameter equivalent returning entry time for a specific manoeuver angle
588 : SUMOTime getEntryManoeuvreTime(const int angle) const;
589 : /// @brief Accessor function for parameter equivalent returning exit time for a specific manoeuver angle
590 : SUMOTime getExitManoeuvreTime(const int angle) const;
591 :
592 :
593 : /** @brief Duplicates the microsim vehicle type giving the newly created type the given id,
594 : * marking it as vehicle specific
595 : * @param[in] id The new id of the type
596 : * @return The built vehicle type
597 : * @note This method is used in case that a vType is meant to be used only for a specific vehicle
598 : * The created vType will be removed with the vehicle or if it is assigned a new type.
599 : */
600 : MSVehicleType* buildSingularType(const std::string& id) const;
601 :
602 :
603 : /** @brief Duplicates the microsim vehicle type giving the newly created type the given id.
604 : *
605 : * @param[in] id The new id of the type
606 : * @param[in] persistent If true the created vType will be persistent and can be used by several vehicles,
607 : * otherwise it may be removed before simulation end, @see buildSingularType()
608 : * @return The built vehicle type
609 : */
610 : MSVehicleType* duplicateType(const std::string& id, bool persistent) const;
611 : /// @}
612 :
613 :
614 : /** @brief Returns whether this type belongs to a single vehicle only (was modified)
615 : * @return Whether this vehicle type is based on a different one, and belongs to one vehicle only
616 : */
617 : bool isVehicleSpecific() const {
618 5008011 : return myOriginalType != nullptr;
619 : }
620 :
621 :
622 : /** @brief Returns the id of the original vehicle type if this is a vehicle specific type, the id otherwise
623 : * @return the original vehicle type id
624 : */
625 : const std::string& getOriginalID() const {
626 2089460 : return myOriginalType != nullptr ? myOriginalType->getID() : getID();
627 : }
628 :
629 :
630 : const SUMOVTypeParameter& getParameter() const {
631 3060506044 : return myParameter;
632 : }
633 :
634 : /** @brief Checks whether vehicle type parameters may be problematic
635 : * (Currently, only the value for the action step length is
636 : * compared with the value for the desired headway time.)
637 : */
638 : void check();
639 :
640 : /// @brief retrieve parameters for the energy consumption model
641 : inline const EnergyParams* getEmissionParameters() const {
642 868631 : return &myEnergyParams;
643 : }
644 :
645 : private:
646 : /// @brief the parameter container
647 : SUMOVTypeParameter myParameter;
648 :
649 : const EnergyParams myEnergyParams;
650 :
651 : /// @brief the vtypes actionsStepLength in seconds (cached because needed very often)
652 : double myCachedActionStepLengthSecs;
653 :
654 : /// @brief Indicator whether the user was already warned once about an action step length
655 : /// larger than the desired time headway.
656 : bool myWarnedActionStepLengthTauOnce;
657 : bool myWarnedActionStepLengthBallisticOnce;
658 : bool myWarnedStepLengthTauOnce;
659 :
660 : /// @brief the running index
661 : const int myIndex;
662 :
663 : /// @brief instance of the car following model.
664 : MSCFModel* myCarFollowModel;
665 :
666 : /// @brief The original type
667 : const MSVehicleType* myOriginalType;
668 :
669 : /// @brief next value for the running index
670 : static int myNextIndex;
671 :
672 :
673 : private:
674 : /// @brief Invalidated copy constructor
675 : MSVehicleType(const MSVehicleType&) = delete;
676 :
677 : /// @brief Invalidated assignment operator
678 : MSVehicleType& operator=(const MSVehicleType&) = delete;
679 : };
|