SUMO - Simulation of Urban MObility

SUMOVehicleClass.cpp

Go to the documentation of this file.
00001 /****************************************************************************/
00010 // Definitions of SUMO vehicle classes and helper functions
00011 /****************************************************************************/
00012 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00013 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
00014 /****************************************************************************/
00015 //
00016 //   This file is part of SUMO.
00017 //   SUMO is free software: you can redistribute it and/or modify
00018 //   it under the terms of the GNU General Public License as published by
00019 //   the Free Software Foundation, either version 3 of the License, or
00020 //   (at your option) any later version.
00021 //
00022 /****************************************************************************/
00023 
00024 
00025 // ===========================================================================
00026 // included modules
00027 // ===========================================================================
00028 #ifdef _MSC_VER
00029 #include <windows_config.h>
00030 #else
00031 #include <config.h>
00032 #endif
00033 
00034 #include <string>
00035 #include <map>
00036 #include "SUMOVehicleClass.h"
00037 #include <utils/common/TplConvert.h>
00038 #include <utils/common/ToString.h>
00039 #include <utils/common/MsgHandler.h>
00040 #include <utils/common/StringTokenizer.h>
00041 
00042 
00043 #ifdef CHECK_MEMORY_LEAKS
00044 #include <foreign/nvwa/debug_new.h>
00045 #endif // CHECK_MEMORY_LEAKS
00046 
00047 
00048 // ===========================================================================
00049 // static members
00050 // ===========================================================================
00051 StringBijection<SUMOVehicleClass>::Entry sumoVehicleClassStringInitializer[] = {
00052     {"unknown",           SVC_UNKNOWN},
00053     {"private",           SVC_PRIVATE},
00054     {"public_transport",  SVC_PUBLIC_TRANSPORT},
00055     {"public_emergency",  SVC_PUBLIC_EMERGENCY},
00056     {"public_authority",  SVC_PUBLIC_AUTHORITY},
00057     {"public_army",       SVC_PUBLIC_ARMY},
00058     {"vip",               SVC_VIP},
00059     {"ignoring",          SVC_IGNORING},
00060     {"passenger",         SVC_PASSENGER},
00061     {"hov",               SVC_HOV},
00062     {"taxi",              SVC_TAXI},
00063     {"bus",               SVC_BUS},
00064     {"delivery",          SVC_DELIVERY},
00065     {"transport",         SVC_TRANSPORT},
00066     {"lightrail",         SVC_LIGHTRAIL},
00067     {"cityrail",          SVC_CITYRAIL},
00068     {"rail_slow",         SVC_RAIL_SLOW},
00069     {"rail_fast",         SVC_RAIL_FAST},
00070     {"motorcycle",        SVC_MOTORCYCLE},
00071     {"bicycle",           SVC_BICYCLE},
00072     {"pedestrian",        SVC_PEDESTRIAN}
00073 };
00074 
00075 StringBijection<SUMOVehicleClass> SumoVehicleClassStrings(
00076     sumoVehicleClassStringInitializer, SVC_PEDESTRIAN);
00077 
00078 
00079 StringBijection<SUMOVehicleShape>::Entry sumoVehicleShapeStringInitializer[] = {
00080     {"pedestrian",            SVS_PEDESTRIAN},
00081     {"bicycle",               SVS_BICYCLE},
00082     {"motorcycle",            SVS_MOTORCYCLE},
00083     {"passenger",             SVS_PASSENGER},
00084     {"passenger/sedan",       SVS_PASSENGER_SEDAN},
00085     {"passenger/hatchback",   SVS_PASSENGER_HATCHBACK},
00086     {"passenger/wagon",       SVS_PASSENGER_WAGON},
00087     {"passenger/van",         SVS_PASSENGER_VAN},
00088     {"delivery",              SVS_DELIVERY},
00089     {"transport",             SVS_TRANSPORT},
00090     {"transport/semitrailer", SVS_TRANSPORT_SEMITRAILER},
00091     {"transport/trailer",     SVS_TRANSPORT_1TRAILER},
00092     {"bus",                   SVS_BUS},
00093     {"bus/city",              SVS_BUS_CITY},
00094     {"bus/flexible",          SVS_BUS_CITY_FLEXIBLE},
00095     {"bus/overland",          SVS_BUS_OVERLAND},
00096     {"bus/trolley",           SVS_BUS_TROLLEY},
00097     {"rail",                  SVS_RAIL},
00098     {"rail/light",            SVS_RAIL_LIGHT},
00099     {"rail/city",             SVS_RAIL_CITY},
00100     {"rail/slow",             SVS_RAIL_SLOW},
00101     {"rail/fast",             SVS_RAIL_FAST},
00102     {"rail/cargo",            SVS_RAIL_CARGO},
00103     {"evehicle",              SVS_E_VEHICLE},
00104     {"ant",                   SVS_ANT},
00105     {"",                      SVS_UNKNOWN}
00106 };
00107 
00108 
00109 StringBijection<SUMOVehicleShape> SumoVehicleShapeStrings(
00110     sumoVehicleShapeStringInitializer, SVS_UNKNOWN);
00111 
00112 
00113 // ===========================================================================
00114 // method definitions
00115 // ===========================================================================
00116 // ------------ Conversion of SUMOVehicleClass
00117 
00118 std::string
00119 getVehicleClassCompoundName(int id) {
00120     std::string ret;
00121     const std::vector<std::string> names = SumoVehicleClassStrings.getStrings();
00122     for (std::vector<std::string>::const_iterator it = names.begin(); it != names.end(); it++) {
00123         if ((id & SumoVehicleClassStrings.get(*it))) {
00124             ret += ("|" + *it);
00125         }
00126     }
00127     if (ret.length() > 0) {
00128         return ret.substr(1);
00129     } else {
00130         return ret;
00131     }
00132 }
00133 
00134 
00135 std::string
00136 getVehicleClassNames(const SUMOVehicleClasses& ids) {
00137     std::ostringstream oss;
00138     bool hadOne = false;
00139     for (SUMOVehicleClasses::const_iterator i = ids.begin(); i != ids.end(); ++i) {
00140         if (hadOne) {
00141             oss << ' ';
00142         }
00143         oss << toString(*i);
00144         hadOne = true;
00145     }
00146     return oss.str();
00147 }
00148 
00149 
00150 SUMOVehicleClass
00151 getVehicleClassID(const std::string& name) {
00152     if (SumoVehicleClassStrings.hasString(name)) {
00153         return SumoVehicleClassStrings.get(name);
00154     }
00155     throw ProcessError("Unknown vehicle class '" + name + "'.");
00156 }
00157 
00158 
00159 int
00160 getVehicleClassCompoundID(const std::string& name) {
00161     int ret = SVC_UNKNOWN;
00162     const std::vector<std::string> names = SumoVehicleClassStrings.getStrings();
00163     for (std::vector<std::string>::const_iterator it = names.begin(); it != names.end(); it++) {
00164         if (name.find(*it) != std::string::npos) {
00165             ret = ret | (int) SumoVehicleClassStrings.get(*it);
00166         }
00167     }
00168     return ret;
00169 }
00170 
00171 
00172 void
00173 parseVehicleClasses(
00174     const std::string& classNames,
00175     SUMOVehicleClasses& container) {
00176     StringTokenizer sta(classNames, " ");
00177     while (sta.hasNext()) {
00178         container.insert(getVehicleClassID(sta.next()));
00179     }
00180 }
00181 
00182 
00183 void
00184 parseVehicleClasses(const std::string& allowedS,
00185                     const std::string& disallowedS,
00186                     SUMOVehicleClasses& allowed,
00187                     SUMOVehicleClasses& disallowed) {
00188     parseVehicleClasses(allowedS, allowed);
00189     parseVehicleClasses(disallowedS, disallowed);
00190 }
00191 
00192 
00193 void
00194 parseVehicleClasses(const std::vector<std::string> &classesS,
00195                     SUMOVehicleClasses& classes) {
00196     for (std::vector<std::string>::const_iterator i = classesS.begin(); i != classesS.end(); ++i) {
00197         classes.insert(getVehicleClassID(*i));
00198     }
00199 }
00200 
00201 
00202 SUMOVehicleShape
00203 getVehicleShapeID(const std::string& name) {
00204     if (SumoVehicleShapeStrings.hasString(name)) {
00205         return SumoVehicleShapeStrings.get(name);
00206     } else {
00207         throw ProcessError("Unknown vehicle shape '" + name + "'.");
00208     }
00209 }
00210 
00211 
00212 std::string
00213 getVehicleShapeName(SUMOVehicleShape id) {
00214     return SumoVehicleShapeStrings.getString(id);
00215 }
00216 
00217 
00218 // ------------ Conversion of SUMOEmissionClass
00219 SUMOEmissionClass
00220 getVehicleEmissionTypeID(const std::string& name) {
00221     try {
00222         if (name == "") {
00223             return SVE_UNKNOWN;
00224         } else if (name == "zero") {
00225             return SVE_ZERO_EMISSIONS;
00226         } else if (name.find("HDV_3_") == 0) {
00227             return (SUMOEmissionClass)(SVE_HDV_3_1 - 1 + TplConvert<char>::_2int(name.substr(name.rfind("_") + 1).c_str()));
00228         } else if (name.find("HDV_6_") == 0) {
00229             return (SUMOEmissionClass)(SVE_HDV_6_1 - 1 + TplConvert<char>::_2int(name.substr(name.rfind("_") + 1).c_str()));
00230         } else if (name.find("HDV_12_") == 0) {
00231             return (SUMOEmissionClass)(SVE_HDV_12_1 - 1 + TplConvert<char>::_2int(name.substr(name.rfind("_") + 1).c_str()));
00232         } else if (name.find("P_7_") == 0) {
00233             return (SUMOEmissionClass)(SVE_P_LDV_7_1 - 1 + TplConvert<char>::_2int(name.substr(name.rfind("_") + 1).c_str()));
00234         } else if (name.find("P_14_") == 0) {
00235             return (SUMOEmissionClass)(SVE_P_LDV_14_1 - 1 + TplConvert<char>::_2int(name.substr(name.rfind("_") + 1).c_str()));
00236         } else if (name.find("HDV_A0_3_") == 0) {
00237             return (SUMOEmissionClass)(SVE_HDV_A0_3_1 - 1 + TplConvert<char>::_2int(name.substr(name.rfind("_") + 1).c_str()));
00238         } else if (name.find("HDV_A0_6_") == 0) {
00239             return (SUMOEmissionClass)(SVE_HDV_A0_6_1 - 1 + TplConvert<char>::_2int(name.substr(name.rfind("_") + 1).c_str()));
00240         } else if (name.find("HDV_A0_12_") == 0) {
00241             return (SUMOEmissionClass)(SVE_HDV_A0_12_1 - 1 + TplConvert<char>::_2int(name.substr(name.rfind("_") + 1).c_str()));
00242         } else if (name.find("P_A0_7_") == 0) {
00243             return (SUMOEmissionClass)(SVE_P_LDV_A0_7_1 - 1 + TplConvert<char>::_2int(name.substr(name.rfind("_") + 1).c_str()));
00244         } else if (name.find("P_A0_14_") == 0) {
00245             return (SUMOEmissionClass)(SVE_P_LDV_A0_14_1 - 1 + TplConvert<char>::_2int(name.substr(name.rfind("_") + 1).c_str()));
00246         }
00247     } catch (NumberFormatException&) {
00248     }
00249     throw ProcessError("Unknown emission type '" + name + "'.");
00250 }
00251 
00252 
00253 std::string
00254 getVehicleEmissionTypeName(SUMOEmissionClass id) {
00255     if (id == SVE_ZERO_EMISSIONS) {
00256         return "zero";
00257     }
00258     if (id < 0) {
00259         return "";
00260     } else if (id < 3) {
00261         return "HDV_3_" + toString(int(id));
00262     } else if (id < 3 + 6) {
00263         return "HDV_6_" + toString(int(id - 3));
00264     } else if (id < 3 + 6 + 12) {
00265         return "HDV_12_" + toString(int(id - 3 - 6));
00266     } else if (id < 3 + 6 + 12 + 7) {
00267         return "P_7_" + toString(int(id - 3 - 6 - 12));
00268     } else if (id < 3 + 6 + 12 + 7 + 14) {
00269         return "P_14_" + toString(int(id - 3 - 6 - 12 - 7));
00270     }
00271     return "";
00272 }
00273 
00274 const std::string DEFAULT_VTYPE_ID("DEFAULT_VEHTYPE");
00275 const SUMOReal DEFAULT_VEH_MAXSPEED(70.0);
00276 const SUMOReal DEFAULT_VEH_ACCEL(2.6);
00277 const SUMOReal DEFAULT_VEH_DECEL(4.5);
00278 const SUMOReal DEFAULT_VEH_SIGMA(0.5);
00279 const SUMOReal DEFAULT_VEH_LENGTH(5.);
00280 const SUMOReal DEFAULT_VEH_MINGAP(2.5);
00281 const SUMOReal DEFAULT_VEH_TAU(1.);
00282 const SUMOVehicleClass DEFAULT_VEH_CLASS(SVC_UNKNOWN);
00283 const SUMOReal DEFAULT_VEH_PROB(1.);
00284 const SUMOReal DEFAULT_VEH_SPEEDFACTOR(1.);
00285 const SUMOReal DEFAULT_VEH_SPEEDDEV(0.);
00286 const SUMOReal DEFAULT_VEH_GUIWIDTH(2.);
00287 const SumoXMLTag DEFAULT_VEH_FOLLOW_MODEL(SUMO_TAG_CF_KRAUSS);
00288 const std::string DEFAULT_VEH_LANE_CHANGE_MODEL("dkrajzew2008");
00289 const SUMOVehicleShape DEFAULT_VEH_SHAPE(SVS_UNKNOWN);
00290 
00291 /****************************************************************************/
00292 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines