NINavTeqHelper.cpp

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // Some parser methods shared around several formats containing NavTeq-Nets
00008 /****************************************************************************/
00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00010 // Copyright 2001-2010 DLR (http://www.dlr.de/) and contributors
00011 /****************************************************************************/
00012 //
00013 //   This program is free software; you can redistribute it and/or modify
00014 //   it under the terms of the GNU General Public License as published by
00015 //   the Free Software Foundation; either version 2 of the License, or
00016 //   (at your option) any later version.
00017 //
00018 /****************************************************************************/
00019 
00020 
00021 // ===========================================================================
00022 // included modules
00023 // ===========================================================================
00024 #ifdef _MSC_VER
00025 #include <windows_config.h>
00026 #else
00027 #include <config.h>
00028 #endif
00029 
00030 #include "NINavTeqHelper.h"
00031 #include <utils/common/TplConvert.h>
00032 #include <utils/common/MsgHandler.h>
00033 #include <utils/common/UtilExceptions.h>
00034 #include <netbuild/NBEdge.h>
00035 
00036 #ifdef CHECK_MEMORY_LEAKS
00037 #include <foreign/nvwa/debug_new.h>
00038 #endif // CHECK_MEMORY_LEAKS
00039 
00040 
00041 // ===========================================================================
00042 // method definitions
00043 // ===========================================================================
00044 SUMOReal
00045 NINavTeqHelper::getSpeed(const std::string &id, const std::string &speedClassS) throw(ProcessError) {
00046     try {
00047         int speedClass = TplConvert<char>::_2int(speedClassS.c_str());
00048         switch (speedClass) {
00049         case -1:
00050             return (SUMOReal) 1.0 / (SUMOReal) 3.6;
00051         case 1:
00052             return (SUMOReal) 200 / (SUMOReal) 3.6; //> 130 KPH / > 80 MPH
00053         case 2:
00054             return (SUMOReal) 120 / (SUMOReal) 3.6; //101-130 KPH / 65-80 MPH
00055         case 3:
00056             return (SUMOReal) 100 / (SUMOReal) 3.6; // 91-100 KPH / 55-64 MPH
00057         case 4:
00058             return (SUMOReal) 80 / (SUMOReal) 3.6; // 71-90 KPH / 41-54 MPH
00059         case 5:
00060             return (SUMOReal) 70 / (SUMOReal) 3.6; // 51-70 KPH / 31-40 MPH
00061         case 6:
00062             return (SUMOReal) 50 / (SUMOReal) 3.6; // 31-50 KPH / 21-30 MPH
00063         case 7:
00064             return (SUMOReal) 30 / (SUMOReal) 3.6; // 11-30 KPH / 6-20 MPH
00065         case 8:
00066             return (SUMOReal) 5 / (SUMOReal) 3.6; //< 11 KPH / < 6 MPH
00067         default:
00068             throw ProcessError("Invalid speed code (edge '" + id + "').");
00069         }
00070     } catch (NumberFormatException &) {
00071         throw ProcessError("Non-numerical value for an edge's speed type occured (edge '" + id + "').");
00072     }
00073 }
00074 
00075 
00076 unsigned int
00077 NINavTeqHelper::getLaneNumber(const std::string &id, const std::string &laneNoS, SUMOReal speed) throw(ProcessError) {
00078     try {
00079         int nolanes = TplConvert<char>::_2int(laneNoS.c_str());
00080         if (nolanes<0) {
00081             return 1;
00082         } else if (nolanes/10 > 0) {
00083             return nolanes / 10;
00084         } else {
00085             switch (nolanes%10) {
00086             case 1:
00087                 return 1;
00088             case 2:
00089                 nolanes = 2;
00090                 if (speed>78.0/3.6) {
00091                     nolanes = 3;
00092                 }
00093                 return nolanes;
00094             case 3:
00095                 return 4;
00096             default:
00097                 throw ProcessError("Invalid lane number (edge '" + id + "').");
00098             }
00099         }
00100     } catch (NumberFormatException &) {
00101         throw ProcessError("Non-numerical value for an edge's lane number occured (edge '" + id + "'.");
00102     }
00103 }
00104 
00105 
00106 void
00107 NINavTeqHelper::addVehicleClasses(NBEdge &e, const std::string &oclassS) throw() {
00108     std::string classS = "0000000000" + oclassS;
00109     classS = classS.substr(classS.length() - 10);
00110     // 0: allow all vehicle types
00111     if (classS[0]=='1') {
00112         return;
00113     }
00114     // Passenger cars -- becomes SVC_PASSENGER
00115     if (classS[1]=='1') {
00116         addVehicleClass(e, SVC_PASSENGER);
00117     }
00118     // High Occupancy Vehicle -- becomes SVC_PASSENGER|SVC_HOV
00119     if (classS[2]=='1') {
00120         addVehicleClass(e, SVC_HOV);
00121         addVehicleClass(e, SVC_PASSENGER);
00122     }
00123     // Emergency Vehicle -- becomes SVC_PUBLIC_EMERGENCY
00124     if (classS[3]=='1') {
00125         addVehicleClass(e, SVC_PUBLIC_EMERGENCY);
00126     }
00127     // Taxi -- becomes SVC_PASSENGER|SVC_TAXI
00128     if (classS[4]=='1') {
00129         addVehicleClass(e, SVC_TAXI);
00130         addVehicleClass(e, SVC_PASSENGER);
00131     }
00132     // Public Bus -- becomes SVC_BUS|SVC_PUBLIC_TRANSPORT
00133     if (classS[5]=='1') {
00134         addVehicleClass(e, SVC_PUBLIC_TRANSPORT);
00135         addVehicleClass(e, SVC_BUS);
00136     }
00137     // Delivery Truck -- becomes SVC_DELIVERY
00138     if (classS[6]=='1') {
00139         addVehicleClass(e, SVC_DELIVERY);
00140     }
00141     // Transport Truck -- becomes SVC_TRANSPORT
00142     if (classS[7]=='1') {
00143         addVehicleClass(e, SVC_TRANSPORT);
00144     }
00145     // Bicycle -- becomes SVC_BICYCLE
00146     if (classS[8]=='1') {
00147         addVehicleClass(e, SVC_BICYCLE);
00148     }
00149     // Pedestrian -- becomes SVC_PEDESTRIAN
00150     if (classS[9]=='1') {
00151         addVehicleClass(e, SVC_PEDESTRIAN);
00152     }
00153 }
00154 
00155 
00156 void
00157 NINavTeqHelper::addVehicleClass(NBEdge &e, SUMOVehicleClass c) throw() {
00158     for (unsigned int i=0; i<e.getNoLanes(); i++) {
00159         e.allowVehicleClass(i, c);
00160     }
00161 }
00162 
00163 
00164 
00165 /****************************************************************************/
00166 

Generated on Wed May 5 00:06:34 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6