1 /****************************************************************************/ 2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo 3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others. 4 // This program and the accompanying materials 5 // are made available under the terms of the Eclipse Public License v2.0 6 // which accompanies this distribution, and is available at 7 // http://www.eclipse.org/legal/epl-v20.html 8 // SPDX-License-Identifier: EPL-2.0 9 /****************************************************************************/ 10 /// @file MSVehicleType.h 11 /// @author Christian Roessel 12 /// @author Daniel Krajzewicz 13 /// @author Jakob Erdmann 14 /// @author Michael Behrisch 15 /// @date Mon, 12 Mar 2001 16 /// @version $Id$ 17 /// 18 // The car-following model and parameter 19 /****************************************************************************/ 20 #ifndef MSVehicleType_h 21 #define MSVehicleType_h 22 23 24 // =========================================================================== 25 // included modules 26 // =========================================================================== 27 #include <config.h> 28 29 #include <cassert> 30 #include <map> 31 #include <string> 32 #include <microsim/cfmodels/MSCFModel.h> 33 #include <utils/common/SUMOTime.h> 34 #include <utils/common/StdDefs.h> 35 #include <utils/common/SUMOVehicleClass.h> 36 #include <utils/common/RandHelper.h> 37 #include <utils/vehicle/SUMOVTypeParameter.h> 38 #include <utils/common/RGBColor.h> 39 40 41 // =========================================================================== 42 // class declarations 43 // =========================================================================== 44 class MSLane; 45 class BinaryInputDevice; 46 class MSCFModel; 47 class SUMOVTypeParameter; 48 49 50 // =========================================================================== 51 // class definitions 52 // =========================================================================== 53 /** 54 * @class MSVehicleType 55 * @brief The car-following model and parameter 56 * 57 * MSVehicleType stores the parameter of a single vehicle type and methods 58 * that use these for computing the vehicle's car-following behavior 59 * 60 * It is assumed that within the simulation many vehicles are using the same 61 * vehicle type, quite common is using only one vehicle type for all vehicles. 62 * 63 * You can think of it like of having a vehicle type for each VW Golf or 64 * Ford Mustang in your simulation while the car instances just refer to it. 65 */ 66 class MSVehicleType { 67 public: 68 /** @brief Constructor. 69 * 70 * @param[in] parameter The vehicle type's parameter 71 */ 72 MSVehicleType(const SUMOVTypeParameter& parameter); 73 74 75 /// @brief Destructor 76 virtual ~MSVehicleType(); 77 78 79 /** @brief Returns whether the given parameter was set 80 * @param[in] what The parameter which one asks for 81 * @return Whether the given parameter was set 82 */ wasSet(int what)83 bool wasSet(int what) const { 84 return (myParameter.parametersSet & what) != 0; 85 } 86 87 88 /// @name Atomar getter for simulation 89 /// @{ 90 91 /** @brief Returns the name of the vehicle type 92 * @return This type's id 93 */ getID()94 const std::string& getID() const { 95 return myParameter.id; 96 } 97 98 99 /** @brief Returns the running index of the vehicle type 100 * @return This type's numerical id 101 */ getNumericalID()102 int getNumericalID() const { 103 return myIndex; 104 } 105 106 107 /** @brief Get vehicle's length [m] 108 * @return The length vehicles of this type have in m 109 */ getLength()110 double getLength() const { 111 return myParameter.length; 112 } 113 114 115 /** @brief Get vehicle's length including the minimum gap [m] 116 * @return The length vehicles of this type have (including the minimum gap in m 117 */ getLengthWithGap()118 double getLengthWithGap() const { 119 return myParameter.length + myParameter.minGap; 120 } 121 122 123 /** @brief Get the free space in front of vehicles of this class 124 * @return The place before the vehicle 125 */ getMinGap()126 double getMinGap() const { 127 return myParameter.minGap; 128 } 129 130 /** @brief Get the minimum lateral gap that vehicles of this type maintain 131 * @return The place before the vehicle 132 */ getMinGapLat()133 double getMinGapLat() const { 134 return myParameter.minGapLat; 135 } 136 137 138 /** @brief Returns the vehicle type's car following model definition (const version) 139 * @return The vehicle type's car following model definition 140 */ getCarFollowModel()141 inline const MSCFModel& getCarFollowModel() const { 142 return *myCarFollowModel; 143 } 144 145 146 /** @brief Returns the vehicle type's car following model definition (non-const version) 147 * @return The vehicle type's car following model definition 148 */ getCarFollowModel()149 inline MSCFModel& getCarFollowModel() { 150 return *myCarFollowModel; 151 } 152 153 getLaneChangeModel()154 inline LaneChangeModel getLaneChangeModel() const { 155 return myParameter.lcModel; 156 } 157 158 159 /** @brief Get vehicle's maximum speed [m/s]. 160 * @return The maximum speed (in m/s) of vehicles of this class 161 */ getMaxSpeed()162 double getMaxSpeed() const { 163 return myParameter.maxSpeed; 164 } 165 166 167 /** @brief Computes and returns the speed deviation 168 * @return A new, random speed deviation 169 */ 170 double computeChosenSpeedDeviation(std::mt19937* rng, const double minDev = -1.) const; 171 172 173 /** @brief Get the default probability of this vehicle type 174 * @return The probability to use this type 175 */ getDefaultProbability()176 double getDefaultProbability() const { 177 return myParameter.defaultProbability; 178 } 179 180 181 /** @brief Get this vehicle type's vehicle class 182 * @return The class of this vehicle type 183 * @see SUMOVehicleClass 184 */ getVehicleClass()185 SUMOVehicleClass getVehicleClass() const { 186 return myParameter.vehicleClass; 187 } 188 189 190 /** @brief Get this vehicle type's emission class 191 * @return The emission class of this vehicle type 192 * @see SUMOEmissionClass 193 */ getEmissionClass()194 SUMOEmissionClass getEmissionClass() const { 195 return myParameter.emissionClass; 196 } 197 198 199 /** @brief Returns this type's color 200 * @return The color of this type 201 */ getColor()202 const RGBColor& getColor() const { 203 return myParameter.color; 204 } 205 206 207 /** @brief Returns this type's speed factor 208 * @return The speed factor of this type 209 */ getSpeedFactor()210 const Distribution_Parameterized& getSpeedFactor() const { 211 return myParameter.speedFactor; 212 } 213 214 215 /** @brief Returns this type's default action step length 216 * @return The default action step length of this type (in ms.) 217 */ getActionStepLength()218 SUMOTime getActionStepLength() const { 219 return myParameter.actionStepLength; 220 } 221 222 223 /** @brief Returns this type's default action step length in seconds 224 * @return The default action step length of this type (in s.) 225 */ getActionStepLengthSecs()226 double getActionStepLengthSecs() const { 227 return myCachedActionStepLengthSecs; 228 } 229 230 231 /** @brief Returns this type's impatience 232 * @return The impatience of this type 233 */ getImpatience()234 double getImpatience() const { 235 return myParameter.impatience; 236 } 237 /// @} 238 239 240 241 /// @name Atomar getter for visualization 242 /// @{ 243 244 /** @brief Get the width which vehicles of this class shall have when being drawn 245 * @return The width of this type's vehicles 246 */ getWidth()247 double getWidth() const { 248 return myParameter.width; 249 } 250 251 /** @brief Get the height which vehicles of this class shall have when being drawn 252 * @return The height of this type's vehicles 253 */ getHeight()254 double getHeight() const { 255 return myParameter.height; 256 } 257 258 /** @brief Get this vehicle type's shape 259 * @return The shape of this vehicle type 260 * @see SUMOVehicleShape 261 */ getGuiShape()262 SUMOVehicleShape getGuiShape() const { 263 return myParameter.shape; 264 } 265 266 /** @brief Get this vehicle type's 3D model file name 267 * @return The model file name of this vehicle type 268 */ getOSGFile()269 std::string getOSGFile() const { 270 return myParameter.osgFile; 271 } 272 273 274 /** @brief Get this vehicle type's raster model file name 275 * @return The raster file name of this vehicle type 276 */ getImgFile()277 std::string getImgFile() const { 278 return myParameter.imgFile; 279 } 280 281 282 /** @brief Get this vehicle type's person capacity 283 * @return The person capacity of this vehicle type 284 */ getPersonCapacity()285 int getPersonCapacity() const { 286 return myParameter.personCapacity; 287 } 288 289 290 /** @brief Get this vehicle type's container capacity 291 * @return The container capacity of this vehicle type 292 */ getContainerCapacity()293 int getContainerCapacity() const { 294 return myParameter.containerCapacity; 295 } 296 297 /** @brief Get this vehicle type's boarding duration 298 * @return The time a person needs to board a vehicle of this type 299 */ getBoardingDuration()300 SUMOTime getBoardingDuration() const { 301 return myParameter.boardingDuration; 302 } 303 304 /** @brief Get this vehicle type's loading duration 305 * @return The time a container needs to get laoded on a vehicle of this type 306 */ getLoadingDuration()307 SUMOTime getLoadingDuration() const { 308 return myParameter.loadingDuration; 309 } 310 311 /** @brief Get vehicle's maximum lateral speed [m/s]. 312 * @return The maximum lateral speed (in m/s) of vehicles of this class 313 */ getMaxSpeedLat()314 double getMaxSpeedLat() const { 315 return myParameter.maxSpeedLat; 316 } 317 318 /** @brief Get vehicle's preferred lateral alignment 319 * @return The vehicle's preferred lateral alignment 320 */ getPreferredLateralAlignment()321 LateralAlignment getPreferredLateralAlignment() const { 322 return myParameter.latAlignment; 323 } 324 /// @} 325 326 327 /// @name Setter methods 328 /// @{ 329 330 /** @brief Set a new value for this type's acceleration. 331 * @param[in] accel The new acceleration of this type 332 */ 333 void setAccel(double accel); 334 335 /** @brief Set a new value for this type's deceleration. 336 * @param[in] decel The new deceleration of this type 337 */ 338 void setDecel(double decel); 339 340 /** @brief Set a new value for this type's emergency deceleration. 341 * @param[in] emergencyDecel The new emergency deceleration of this type 342 */ 343 void setEmergencyDecel(double emergencyDecel); 344 345 /** @brief Set a new value for this type's apparent deceleration. 346 * @param[in] apparentDecel The new apparent deceleration of this type 347 */ 348 void setApparentDecel(double apparentDecel); 349 350 /** @brief Set a new value for this type's imperfection. 351 * @param[in] imperfection The new imperfection of this type 352 */ 353 void setImperfection(double imperfection); 354 355 /** @brief Set a new value for this type's headway. 356 * @param[in] tau The new headway of this type 357 */ 358 void setTau(double tau); 359 360 /** @brief Set a new value for this type's length 361 * 362 * If the given value<0 then the one from the original type will 363 * be used. 364 * 365 * @param[in] length The new length of this type 366 */ 367 void setLength(const double& length); 368 369 370 /** @brief Set a new value for this type's height 371 * 372 * If the given value<0 then the one from the original type will 373 * be used. 374 * 375 * @param[in] height The new height of this type 376 */ 377 void setHeight(const double& height); 378 379 380 /** @brief Set a new value for this type's minimum gap 381 * 382 * If the given value<0 then the one from the original type will 383 * be used. 384 * 385 * @param[in] minGap The new minimum gap of this type 386 */ 387 void setMinGap(const double& minGap); 388 389 390 /** @brief Set a new value for this type's minimum lataral gap 391 * 392 * If the given value<0 then the one from the original type will 393 * be used. 394 * 395 * @param[in] minGapLat The new minimum lateral gap of this type 396 */ 397 void setMinGapLat(const double& minGapLat); 398 399 /** @brief Set a new value for this type's maximum speed 400 * 401 * If the given value<0 then the one from the original type will 402 * be used. 403 * 404 * @param[in] maxSpeed The new maximum speed of this type 405 */ 406 void setMaxSpeed(const double& maxSpeed); 407 408 /** @brief Set a new value for this type's maximum lateral speed 409 * 410 * If the given value<0 then the one from the original type will 411 * be used. 412 * 413 * @param[in] maxSpeedLat The new maximum lateral speed of this type 414 */ 415 void setMaxSpeedLat(const double& maxSpeedLat); 416 417 /** @brief Set a new value for this type's vehicle class 418 * @param[in] vclass The new vehicle class of this type 419 */ 420 void setVClass(SUMOVehicleClass vclass); 421 422 423 /** @brief Set a new value for this type's default probability 424 * 425 * If the given value<0 then the one from the original type will 426 * be used. 427 * 428 * @param[in] prob The new default probability of this type 429 */ 430 void setDefaultProbability(const double& prob); 431 432 433 /** @brief Set a new value for this type's speed factor 434 * 435 * If the given value<0 then the one from the original type will 436 * be used. 437 * 438 * @param[in] factor The new speed factor of this type 439 */ 440 void setSpeedFactor(const double& factor); 441 442 443 /** @brief Set a new value for this type's speed deviation 444 * 445 * If the given value<0 then the one from the original type will 446 * be used. 447 * 448 * @param[in] dev The new speed deviation of this type 449 */ 450 void setSpeedDeviation(const double& dev); 451 452 453 /** @brief Set a new value for this type's action step length 454 * 455 * @param[in] actionStepLength The new action step length of this type (in ms.) 456 * @param[in] resetActionOffset If True (default), the next action point is 457 * scheduled immediately. if If resetActionOffset == False, the interval 458 * between the last and the next action point is updated to match the given 459 * value for all vehicles of this type, or if the latter is smaller than the 460 * time since the last action point, the next action follows immediately. 461 * 462 * @note: Singular vtypes do not update the state of the corresponding vehicle, because 463 * the global lookup would be too expensive. The caller is responsible to 464 * perform the actionOffsetReset operation at caller context, where the vehicle is known. 465 */ 466 void setActionStepLength(const SUMOTime actionStepLength, bool resetActionOffset); 467 468 469 /** @brief Set a new value for this type's emission class 470 * @param[in] eclass The new emission class of this type 471 */ 472 void setEmissionClass(SUMOEmissionClass eclass); 473 474 475 /** @brief Set a new value for this type's color 476 * @param[in] color The new color of this type 477 */ 478 void setColor(const RGBColor& color); 479 480 481 /** @brief Set a new value for this type's width 482 * 483 * If the given value<0 then the one from the original type will 484 * be used. 485 * 486 * @param[in] width The new width of this type 487 */ 488 void setWidth(const double& width); 489 490 491 /** @brief Set a new value for this type's shape 492 * @param[in] shape The new shape of this type 493 */ 494 void setShape(SUMOVehicleShape shape); 495 496 /** @brief Set a new value for this type's impatience 497 * @param[in] impatience The new impatience of this type 498 */ 499 void setImpatience(const double impatience); 500 501 /** @brief Set vehicle's preferred lateral alignment 502 */ 503 void setPreferredLateralAlignment(LateralAlignment latAlignment); 504 /// @} 505 506 507 508 /// @name methods for building vehicle types 509 /// @{ 510 511 /** @brief Builds the microsim vehicle type described by the given parameter 512 * @param[in] from The vehicle type description 513 * @return The built vehicle type 514 * @exception ProcessError on false values (not et used) 515 */ 516 static MSVehicleType* build(SUMOVTypeParameter& from); 517 518 519 /** @brief Duplicates the microsim vehicle type giving the newly created type the given id, 520 * marking it as vehicle specific 521 * @param[in] id The new id of the type 522 * @return The built vehicle type 523 * @note This method is used in case that a vType is meant to be used only for a specific vehicle 524 * The created vType will be removed with the vehicle or if it is assigned a new type. 525 */ 526 MSVehicleType* buildSingularType(const std::string& id) const; 527 528 529 /** @brief Duplicates the microsim vehicle type giving the newly created type the given id. 530 * 531 * @param[in] id The new id of the type 532 * @param[in] persistent If true the created vType will be persistent and can be used by several vehicles, 533 * otherwise it may be removed before simulation end, @see buildSingularType() 534 * @return The built vehicle type 535 */ 536 MSVehicleType* duplicateType(const std::string& id, bool persistent) const; 537 /// @} 538 539 540 /** @brief Returns whether this type belongs to a single vehicle only (was modified) 541 * @return Whether this vehicle type is based on a different one, and belongs to one vehicle only 542 */ isVehicleSpecific()543 bool isVehicleSpecific() const { 544 return myOriginalType != 0; 545 } 546 547 getParameter()548 const SUMOVTypeParameter& getParameter() const { 549 return myParameter; 550 } 551 552 /** @brief Checks whether vehicle type parameters may be problematic 553 * (Currently, only the value for the action step length is 554 * compared with the value for the desired headway time.) 555 */ 556 void check(); 557 558 protected: 559 560 // init further param values 561 void initParameters(); 562 563 private: 564 /// @brief the parameter container 565 SUMOVTypeParameter myParameter; 566 567 /// @brief the vtypes actionsStepLength in seconds (cached because needed very often) 568 double myCachedActionStepLengthSecs; 569 570 /// @brief Indicator whether the user was already warned once about an action step length 571 /// larger than the desired time headway. 572 bool myWarnedActionStepLengthTauOnce; 573 574 /// @brief the running index 575 const int myIndex; 576 577 /// @brief instance of the car following model. 578 MSCFModel* myCarFollowModel; 579 580 /// @brief The original type 581 const MSVehicleType* myOriginalType; 582 583 /// @brief next value for the running index 584 static int myNextIndex; 585 586 587 private: 588 /// @brief Invalidated copy constructor 589 MSVehicleType(const MSVehicleType&); 590 591 /// @brief Invalidated assignment operator 592 MSVehicleType& operator=(const MSVehicleType&); 593 594 }; 595 596 597 #endif 598 599 /****************************************************************************/ 600 601