SUMO - Simulation of Urban MObility
NINavTeqHelper.cpp
Go to the documentation of this file.
00001 /****************************************************************************/
00010 // Some parser methods shared around several formats containing NavTeq-Nets
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 "NINavTeqHelper.h"
00035 #include <utils/common/TplConvert.h>
00036 #include <utils/common/MsgHandler.h>
00037 #include <utils/common/UtilExceptions.h>
00038 #include <netbuild/NBEdge.h>
00039 
00040 #ifdef CHECK_MEMORY_LEAKS
00041 #include <foreign/nvwa/debug_new.h>
00042 #endif // CHECK_MEMORY_LEAKS
00043 
00044 
00045 // ===========================================================================
00046 // method definitions
00047 // ===========================================================================
00048 SUMOReal
00049 NINavTeqHelper::getSpeed(const std::string& id, const std::string& speedClassS) {
00050     try {
00051         int speedClass = TplConvert<char>::_2int(speedClassS.c_str());
00052         switch (speedClass) {
00053             case -1:
00054                 return (SUMOReal) 1.0 / (SUMOReal) 3.6;
00055             case 1:
00056                 return (SUMOReal) 200 / (SUMOReal) 3.6; //> 130 KPH / > 80 MPH
00057             case 2:
00058                 return (SUMOReal) 120 / (SUMOReal) 3.6; //101-130 KPH / 65-80 MPH
00059             case 3:
00060                 return (SUMOReal) 100 / (SUMOReal) 3.6; // 91-100 KPH / 55-64 MPH
00061             case 4:
00062                 return (SUMOReal) 80 / (SUMOReal) 3.6; // 71-90 KPH / 41-54 MPH
00063             case 5:
00064                 return (SUMOReal) 70 / (SUMOReal) 3.6; // 51-70 KPH / 31-40 MPH
00065             case 6:
00066                 return (SUMOReal) 50 / (SUMOReal) 3.6; // 31-50 KPH / 21-30 MPH
00067             case 7:
00068                 return (SUMOReal) 30 / (SUMOReal) 3.6; // 11-30 KPH / 6-20 MPH
00069             case 8:
00070                 return (SUMOReal) 5 / (SUMOReal) 3.6; //< 11 KPH / < 6 MPH
00071             default:
00072                 throw ProcessError("Invalid speed code (edge '" + id + "').");
00073         }
00074     } catch (NumberFormatException&) {
00075         throw ProcessError("Non-numerical value for an edge's speed type occured (edge '" + id + "').");
00076     }
00077 }
00078 
00079 
00080 unsigned int
00081 NINavTeqHelper::getLaneNumber(const std::string& id, const std::string& laneNoS, SUMOReal speed) {
00082     try {
00083         int nolanes = TplConvert<char>::_2int(laneNoS.c_str());
00084         if (nolanes < 0) {
00085             return 1;
00086         } else if (nolanes / 10 > 0) {
00087             return nolanes / 10;
00088         } else {
00089             switch (nolanes % 10) {
00090                 case 1:
00091                     return 1;
00092                 case 2:
00093                     nolanes = 2;
00094                     if (speed > 78.0 / 3.6) {
00095                         nolanes = 3;
00096                     }
00097                     return nolanes;
00098                 case 3:
00099                     return 4;
00100                 default:
00101                     throw ProcessError("Invalid lane number (edge '" + id + "').");
00102             }
00103         }
00104     } catch (NumberFormatException&) {
00105         throw ProcessError("Non-numerical value for an edge's lane number occured (edge '" + id + "'.");
00106     }
00107 }
00108 
00109 
00110 void
00111 NINavTeqHelper::addVehicleClasses(NBEdge& e, const std::string& oclassS) {
00112     std::string classS = "0000000000" + oclassS;
00113     classS = classS.substr(classS.length() - 10);
00114     // 0: allow all vehicle types
00115     if (classS[0] == '1') {
00116         return;
00117     }
00118     // we have some restrictions. disallow all and then add classes indiviually
00119     e.setPermissions(0);
00120     // Passenger cars -- becomes SVC_PASSENGER
00121     if (classS[1] == '1') {
00122         e.allowVehicleClass(-1, SVC_PASSENGER);
00123     }
00124     // High Occupancy Vehicle -- becomes SVC_PASSENGER|SVC_HOV
00125     if (classS[2] == '1') {
00126         e.allowVehicleClass(-1, SVC_HOV);
00127         e.allowVehicleClass(-1, SVC_PASSENGER);
00128     }
00129     // Emergency Vehicle -- becomes SVC_PUBLIC_EMERGENCY
00130     if (classS[3] == '1') {
00131         e.allowVehicleClass(-1, SVC_PUBLIC_EMERGENCY);
00132     }
00133     // Taxi -- becomes SVC_PASSENGER|SVC_TAXI
00134     if (classS[4] == '1') {
00135         e.allowVehicleClass(-1, SVC_TAXI);
00136         e.allowVehicleClass(-1, SVC_PASSENGER);
00137     }
00138     // Public Bus -- becomes SVC_BUS|SVC_PUBLIC_TRANSPORT
00139     if (classS[5] == '1') {
00140         e.allowVehicleClass(-1, SVC_PUBLIC_TRANSPORT);
00141         e.allowVehicleClass(-1, SVC_BUS);
00142     }
00143     // Delivery Truck -- becomes SVC_DELIVERY
00144     if (classS[6] == '1') {
00145         e.allowVehicleClass(-1, SVC_DELIVERY);
00146     }
00147     // Transport Truck -- becomes SVC_TRANSPORT
00148     if (classS[7] == '1') {
00149         e.allowVehicleClass(-1, SVC_TRANSPORT);
00150     }
00151     // Bicycle -- becomes SVC_BICYCLE
00152     if (classS[8] == '1') {
00153         e.allowVehicleClass(-1, SVC_BICYCLE);
00154     }
00155     // Pedestrian -- becomes SVC_PEDESTRIAN
00156     if (classS[9] == '1') {
00157         e.allowVehicleClass(-1, SVC_PEDESTRIAN);
00158     }
00159 }
00160 
00161 /****************************************************************************/
00162 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines