LCOV - code coverage report
Current view: top level - src/utils/vehicle - SUMOVTypeParameter.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 100.0 % 3 3
Test Date: 2024-12-21 15:45:41 Functions: 100.0 % 2 2

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

Generated by: LCOV version 2.0-1