LCOV - code coverage report
Current view: top level - src/netimport - NINavTeqHelper.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 83 106 78.3 %
Date: 2024-05-02 15:31:40 Functions: 5 5 100.0 %

          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    NINavTeqHelper.cpp
      15             : /// @author  Daniel Krajzewicz
      16             : /// @author  Jakob Erdmann
      17             : /// @author  Sascha Krieg
      18             : /// @author  Michael Behrisch
      19             : /// @date    Jul 2006
      20             : ///
      21             : // Some parser methods shared around several formats containing NavTeq-Nets
      22             : /****************************************************************************/
      23             : #include <config.h>
      24             : 
      25             : #include <utils/common/StringUtils.h>
      26             : #include <utils/common/StringUtils.h>
      27             : #include <utils/common/MsgHandler.h>
      28             : #include <utils/common/UtilExceptions.h>
      29             : #include <netbuild/NBEdge.h>
      30             : 
      31             : #include "NINavTeqHelper.h"
      32             : 
      33             : 
      34             : // ===========================================================================
      35             : // method definitions
      36             : // ===========================================================================
      37             : double
      38         343 : NINavTeqHelper::getSpeed(const std::string& id, const std::string& speedClassS) {
      39             :     try {
      40         343 :         int speedClass = StringUtils::toInt(speedClassS);
      41         343 :         switch (speedClass) {
      42             :             case -1:
      43             :                 return (double) 1.0 / (double) 3.6;
      44         214 :             case 1:
      45         214 :                 return (double) 200 / (double) 3.6; //> 130 KPH / > 80 MPH
      46          74 :             case 2:
      47          74 :                 return (double) 120 / (double) 3.6; //101-130 KPH / 65-80 MPH
      48           0 :             case 3:
      49           0 :                 return (double) 100 / (double) 3.6; // 91-100 KPH / 55-64 MPH
      50           0 :             case 4:
      51           0 :                 return (double) 80 / (double) 3.6; // 71-90 KPH / 41-54 MPH
      52           0 :             case 5:
      53           0 :                 return (double) 70 / (double) 3.6; // 51-70 KPH / 31-40 MPH
      54          44 :             case 6:
      55          44 :                 return (double) 50 / (double) 3.6; // 31-50 KPH / 21-30 MPH
      56          11 :             case 7:
      57          11 :                 return (double) 30 / (double) 3.6; // 11-30 KPH / 6-20 MPH
      58           0 :             case 8:
      59           0 :                 return (double) 5 / (double) 3.6; //< 11 KPH / < 6 MPH
      60           0 :             default:
      61           0 :                 throw ProcessError(TLF("Invalid speed code (edge '%').", id));
      62             :         }
      63           0 :     } catch (NumberFormatException&) {
      64           0 :         throw ProcessError(TLF("Non-numerical value for an edge's speed type occurred (edge '%').", id));
      65           0 :     }
      66             : }
      67             : 
      68             : 
      69             : int
      70         854 : NINavTeqHelper::getLaneNumber(const std::string& id, const std::string& laneNoS, double speed) {
      71             :     try {
      72         854 :         int nolanes = StringUtils::toInt(laneNoS);
      73         854 :         if (nolanes < 0) {
      74             :             return 1;
      75         854 :         } else if (nolanes / 10 > 0) {
      76         827 :             return nolanes / 10;
      77             :         } else {
      78          27 :             switch (nolanes % 10) {
      79             :                 case 1:
      80             :                     return 1;
      81           0 :                 case 2:
      82             :                     nolanes = 2;
      83           0 :                     if (speed > 78.0 / 3.6) {
      84             :                         nolanes = 3;
      85             :                     }
      86           0 :                     return nolanes;
      87           0 :                 case 3:
      88           0 :                     return 4;
      89           0 :                 default:
      90           0 :                     throw ProcessError(TLF("Invalid lane number (edge '%').", id));
      91             :             }
      92             :         }
      93           0 :     } catch (NumberFormatException&) {
      94           0 :         throw ProcessError(TLF("Non-numerical value for an edge's lane number occurred (edge '%'.", id));
      95           0 :     }
      96             : }
      97             : 
      98             : 
      99             : bool
     100         384 : NINavTeqHelper::addCommonVehicleClasses(NBEdge& e, const std::string& classS, const int offset) {
     101             :     bool haveCar = false;
     102             :     // High Occupancy Vehicle -- becomes SVC_PASSENGER|SVC_HOV
     103         384 :     if (classS[offset] == '1') {
     104         200 :         e.allowVehicleClass(-1, SVC_HOV);
     105         200 :         e.allowVehicleClass(-1, SVC_PASSENGER);
     106             :         haveCar = true;
     107             :     } else {
     108         184 :         e.disallowVehicleClass(-1, SVC_HOV);
     109             :     }
     110             :     // Emergency Vehicle -- becomes SVC_EMERGENCY
     111         384 :     if (classS[offset + 1] == '1') {
     112         200 :         e.allowVehicleClass(-1, SVC_EMERGENCY);
     113             :     } else {
     114         184 :         e.disallowVehicleClass(-1, SVC_EMERGENCY);
     115             :     }
     116             :     // Taxi -- becomes SVC_TAXI
     117         384 :     if (classS[offset + 2] == '1') {
     118         216 :         e.allowVehicleClass(-1, SVC_TAXI);
     119             :         haveCar = true;
     120             :     } else {
     121         168 :         e.disallowVehicleClass(-1, SVC_TAXI);
     122             :     }
     123             :     // Public Bus -- becomes SVC_BUS|SVC_COACH
     124         384 :     if (classS[offset + 3] == '1') {
     125         200 :         e.allowVehicleClass(-1, SVC_BUS);
     126         200 :         e.allowVehicleClass(-1, SVC_COACH);
     127             :         haveCar = true;
     128             :     } else {
     129         184 :         e.disallowVehicleClass(-1, SVC_BUS);
     130         184 :         e.disallowVehicleClass(-1, SVC_COACH);
     131             :     }
     132             :     // Delivery Truck -- becomes SVC_DELIVERY
     133         384 :     if (classS[offset + 4] == '1') {
     134         258 :         e.allowVehicleClass(-1, SVC_DELIVERY);
     135             :         haveCar = true;
     136             :     } else {
     137         126 :         e.disallowVehicleClass(-1, SVC_DELIVERY);
     138             :     }
     139             :     // Transport Truck -- becomes SVC_TRUCK|SVC_TRAILER
     140         384 :     if (classS[offset + 5] == '1') {
     141         200 :         e.allowVehicleClass(-1, SVC_TRUCK);
     142         200 :         e.allowVehicleClass(-1, SVC_TRAILER);
     143             :         haveCar = true;
     144             :     } else {
     145         184 :         e.disallowVehicleClass(-1, SVC_TRUCK);
     146         184 :         e.disallowVehicleClass(-1, SVC_TRAILER);
     147             :     }
     148         384 :     return haveCar;
     149             : }
     150             : 
     151             : 
     152             : void
     153         328 : NINavTeqHelper::addVehicleClasses(NBEdge& e, const std::string& oclassS, const SVCPermissions allPermissions, const SVCPermissions defaultPermissions) {
     154         328 :     std::string classS = "0000000000" + oclassS;
     155         656 :     classS = classS.substr(classS.length() - 10);
     156             :     // 0: allow all vehicle types
     157         328 :     if (classS[0] == '1') {
     158         144 :         e.setPermissions(allPermissions);
     159             :         return;
     160             :     }
     161             :     bool haveCar = false;
     162         184 :     e.setPermissions(defaultPermissions);
     163             :     // Passenger cars -- becomes SVC_PASSENGER
     164         184 :     if (classS[1] == '1') {
     165         150 :         e.allowVehicleClass(-1, SVC_PASSENGER);
     166             :         haveCar = true;
     167             :     } else {
     168          34 :         e.disallowVehicleClass(-1, SVC_PASSENGER);
     169             :     }
     170         184 :     haveCar |= addCommonVehicleClasses(e, classS, 2);
     171         184 :     if (!haveCar) {
     172          18 :         e.setPermissions(0);
     173             :     }
     174             :     // Bicycle -- becomes SVC_BICYCLE
     175         184 :     if (classS[8] == '1') {
     176          12 :         e.allowVehicleClass(-1, SVC_BICYCLE);
     177             :     } else {
     178         172 :         e.disallowVehicleClass(-1, SVC_BICYCLE);
     179             :     }
     180             :     // Pedestrian -- becomes SVC_PEDESTRIAN
     181         184 :     if (classS[9] == '1') {
     182          12 :         e.allowVehicleClass(-1, SVC_PEDESTRIAN);
     183             :     } else {
     184         172 :         e.disallowVehicleClass(-1, SVC_PEDESTRIAN);
     185             :     }
     186             : }
     187             : 
     188             : 
     189             : void
     190         518 : NINavTeqHelper::addVehicleClassesV6(NBEdge& e, const std::string& oclassS, const SVCPermissions allPermissions, const SVCPermissions defaultPermissions) {
     191         518 :     std::string classS = "0000000000" + oclassS;
     192        1036 :     classS = classS.substr(classS.length() - 12);
     193             :     // 0: allow all vehicle types
     194         518 :     if (classS[0] == '1') {
     195         318 :         e.setPermissions(allPermissions);
     196             :         return;
     197             :     }
     198             :     bool haveCar = false;
     199         200 :     e.setPermissions(defaultPermissions);
     200             :     // Passenger cars -- becomes SVC_PASSENGER
     201         200 :     if (classS[1] == '1') {
     202          50 :         e.allowVehicleClass(-1, SVC_PASSENGER);
     203             :         haveCar = true;
     204             :     } else {
     205         150 :         e.disallowVehicleClass(-1, SVC_PASSENGER);
     206             :     }
     207             :     // Residential Vehicle -- becomes SVC_PASSENGER
     208         200 :     if (classS[2] == '1') {
     209          49 :         e.allowVehicleClass(-1, SVC_PASSENGER);
     210             :         haveCar = true;
     211             :     }
     212         200 :     haveCar |= addCommonVehicleClasses(e, classS, 3);
     213         200 :     if (!haveCar) {
     214          92 :         e.setPermissions(0);
     215             :     }
     216             :     // Motorcycle -- becomes SVC_MOTORCYCLE
     217         200 :     if (classS[9] == '1') {
     218          48 :         e.allowVehicleClass(-1, SVC_MOTORCYCLE);
     219             :     } else {
     220         152 :         e.disallowVehicleClass(-1, SVC_MOTORCYCLE);
     221             :     }
     222             :     // Bicycle -- becomes SVC_BICYCLE
     223         200 :     if (classS[10] == '1') {
     224          52 :         e.allowVehicleClass(-1, SVC_BICYCLE);
     225             :     } else {
     226         148 :         e.disallowVehicleClass(-1, SVC_BICYCLE);
     227             :     }
     228             :     // Pedestrian -- becomes SVC_PEDESTRIAN
     229         200 :     if (classS[11] == '1') {
     230         136 :         e.allowVehicleClass(-1, SVC_PEDESTRIAN);
     231             :     } else {
     232          64 :         e.disallowVehicleClass(-1, SVC_PEDESTRIAN);
     233             :     }
     234             : }
     235             : 
     236             : 
     237             : /****************************************************************************/

Generated by: LCOV version 1.14