Eclipse SUMO - Simulation of Urban MObility
NINavTeqHelper.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // Some parser methods shared around several formats containing NavTeq-Nets
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include "NINavTeqHelper.h"
30 #include <netbuild/NBEdge.h>
31 
32 
33 // ===========================================================================
34 // method definitions
35 // ===========================================================================
36 double
37 NINavTeqHelper::getSpeed(const std::string& id, const std::string& speedClassS) {
38  try {
39  int speedClass = StringUtils::toInt(speedClassS);
40  switch (speedClass) {
41  case -1:
42  return (double) 1.0 / (double) 3.6;
43  case 1:
44  return (double) 200 / (double) 3.6; //> 130 KPH / > 80 MPH
45  case 2:
46  return (double) 120 / (double) 3.6; //101-130 KPH / 65-80 MPH
47  case 3:
48  return (double) 100 / (double) 3.6; // 91-100 KPH / 55-64 MPH
49  case 4:
50  return (double) 80 / (double) 3.6; // 71-90 KPH / 41-54 MPH
51  case 5:
52  return (double) 70 / (double) 3.6; // 51-70 KPH / 31-40 MPH
53  case 6:
54  return (double) 50 / (double) 3.6; // 31-50 KPH / 21-30 MPH
55  case 7:
56  return (double) 30 / (double) 3.6; // 11-30 KPH / 6-20 MPH
57  case 8:
58  return (double) 5 / (double) 3.6; //< 11 KPH / < 6 MPH
59  default:
60  throw ProcessError("Invalid speed code (edge '" + id + "').");
61  }
62  } catch (NumberFormatException&) {
63  throw ProcessError("Non-numerical value for an edge's speed type occurred (edge '" + id + "').");
64  }
65 }
66 
67 
68 int
69 NINavTeqHelper::getLaneNumber(const std::string& id, const std::string& laneNoS, double speed) {
70  try {
71  int nolanes = StringUtils::toInt(laneNoS);
72  if (nolanes < 0) {
73  return 1;
74  } else if (nolanes / 10 > 0) {
75  return nolanes / 10;
76  } else {
77  switch (nolanes % 10) {
78  case 1:
79  return 1;
80  case 2:
81  nolanes = 2;
82  if (speed > 78.0 / 3.6) {
83  nolanes = 3;
84  }
85  return nolanes;
86  case 3:
87  return 4;
88  default:
89  throw ProcessError("Invalid lane number (edge '" + id + "').");
90  }
91  }
92  } catch (NumberFormatException&) {
93  throw ProcessError("Non-numerical value for an edge's lane number occurred (edge '" + id + "'.");
94  }
95 }
96 
97 
98 void
99 NINavTeqHelper::addVehicleClasses(NBEdge& e, const std::string& oclassS) {
100  std::string classS = "0000000000" + oclassS;
101  classS = classS.substr(classS.length() - 10);
102  // 0: allow all vehicle types
103  if (classS[0] == '1') {
105  return;
106  }
107  // we have some restrictions. disallow all and then add classes indiviually
108  e.setPermissions(0);
109  // Passenger cars -- becomes SVC_PASSENGER
110  if (classS[1] == '1') {
112  }
113  // High Occupancy Vehicle -- becomes SVC_PASSENGER|SVC_HOV
114  if (classS[2] == '1') {
115  e.allowVehicleClass(-1, SVC_HOV);
117  }
118  // Emergency Vehicle -- becomes SVC_PUBLIC_EMERGENCY
119  if (classS[3] == '1') {
121  }
122  // Taxi -- becomes SVC_TAXI
123  if (classS[4] == '1') {
125  }
126  // Public Bus -- becomes SVC_BUS|SVC_COACH
127  if (classS[5] == '1') {
128  e.allowVehicleClass(-1, SVC_BUS);
130  }
131  // Delivery Truck -- becomes SVC_DELIVERY
132  if (classS[6] == '1') {
134  }
135  // Transport Truck -- becomes SVC_TRUCK|SVC_TRAILER
136  if (classS[7] == '1') {
139  }
140  // Bicycle -- becomes SVC_BICYCLE
141  if (classS[8] == '1') {
143  }
144  // Pedestrian -- becomes SVC_PEDESTRIAN
145  if (classS[9] == '1') {
147  }
148 }
149 
150 
151 void
152 NINavTeqHelper::addVehicleClassesV6(NBEdge& e, const std::string& oclassS) {
153  std::string classS = "0000000000" + oclassS;
154  classS = classS.substr(classS.length() - 12);
155  // 0: allow all vehicle types
156  if (classS[0] == '1') {
158  return;
159  }
160  // we have some restrictions. disallow all and then add classes indiviually
161  e.setPermissions(0);
162  // Passenger cars -- becomes SVC_PASSENGER
163  if (classS[1] == '1') {
165  }
166  // Residential Vehicle -- becomes SVC_PASSENGER
167  if (classS[2] == '1') {
169  }
170  // High Occupancy Vehicle -- becomes SVC_PASSENGER|SVC_HOV
171  if (classS[3] == '1') {
172  e.allowVehicleClass(-1, SVC_HOV);
174  }
175  // Emergency Vehicle -- becomes SVC_PUBLIC_EMERGENCY
176  if (classS[4] == '1') {
178  }
179  // Taxi -- becomes SVC_TAXI
180  if (classS[5] == '1') {
182  }
183  // Public Bus -- becomes SVC_BUS|SVC_COACH
184  if (classS[6] == '1') {
185  e.allowVehicleClass(-1, SVC_BUS);
187  }
188  // Delivery Truck -- becomes SVC_DELIVERY
189  if (classS[7] == '1') {
191  }
192  // Transport Truck -- becomes SVC_TRUCK|SVC_TRAILER
193  if (classS[8] == '1') {
196  }
197  // Motorcycle -- becomes SVC_MOTORCYCLE
198  if (classS[9] == '1') {
200  }
201  // Bicycle -- becomes SVC_BICYCLE
202  if (classS[10] == '1') {
204  }
205  // Pedestrian -- becomes SVC_PEDESTRIAN
206  if (classS[11] == '1') {
208  }
209 }
210 /****************************************************************************/
211 
SVC_PEDESTRIAN
@ SVC_PEDESTRIAN
pedestrian
Definition: SUMOVehicleClass.h:156
SVC_EMERGENCY
@ SVC_EMERGENCY
public emergency vehicles
Definition: SUMOVehicleClass.h:143
SVC_COACH
@ SVC_COACH
vehicle is a coach
Definition: SUMOVehicleClass.h:167
MsgHandler.h
NINavTeqHelper::addVehicleClasses
static void addVehicleClasses(NBEdge &e, const std::string &classS)
Adds vehicle classes parsing the given list of allowed vehicles.
Definition: NINavTeqHelper.cpp:99
SVC_BICYCLE
@ SVC_BICYCLE
vehicle is a bicycle
Definition: SUMOVehicleClass.h:179
SVC_DELIVERY
@ SVC_DELIVERY
vehicle is a small delivery vehicle
Definition: SUMOVehicleClass.h:169
NBEdge::setPermissions
void setPermissions(SVCPermissions permissions, int lane=-1)
set allowed/disallowed classes for the given lane or for all lanes if -1 is given
Definition: NBEdge.cpp:3376
NBEdge
The representation of a single edge during network building.
Definition: NBEdge.h:91
NINavTeqHelper::addVehicleClassesV6
static void addVehicleClassesV6(NBEdge &e, const std::string &classS)
same as addVehicleClasses but for version 6+
Definition: NINavTeqHelper.cpp:152
NumberFormatException
Definition: UtilExceptions.h:95
SVC_TRUCK
@ SVC_TRUCK
vehicle is a large transport vehicle
Definition: SUMOVehicleClass.h:171
SVC_HOV
@ SVC_HOV
vehicle is a HOV
Definition: SUMOVehicleClass.h:161
SVC_PASSENGER
@ SVC_PASSENGER
vehicle is a passenger car (a "normal" car)
Definition: SUMOVehicleClass.h:159
NINavTeqHelper.h
NINavTeqHelper::getLaneNumber
static int getLaneNumber(const std::string &id, const std::string &laneNoS, double speed)
Returns the lane number evaluating the given Navteq-description.
Definition: NINavTeqHelper.cpp:69
ProcessError
Definition: UtilExceptions.h:39
UtilExceptions.h
StringUtils.h
StringUtils::toInt
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter,...
Definition: StringUtils.cpp:278
SVC_TAXI
@ SVC_TAXI
vehicle is a taxi
Definition: SUMOVehicleClass.h:163
SVCAll
const SVCPermissions SVCAll
all VClasses are allowed
Definition: SUMOVehicleClass.cpp:146
config.h
SVC_TRAILER
@ SVC_TRAILER
vehicle is a large transport vehicle
Definition: SUMOVehicleClass.h:173
SVC_BUS
@ SVC_BUS
vehicle is a bus
Definition: SUMOVehicleClass.h:165
SVC_MOTORCYCLE
@ SVC_MOTORCYCLE
vehicle is a motorcycle
Definition: SUMOVehicleClass.h:175
NBEdge::allowVehicleClass
void allowVehicleClass(int lane, SUMOVehicleClass vclass)
set allowed class for the given lane or for all lanes if -1 is given
Definition: NBEdge.cpp:3200
NBEdge.h
NINavTeqHelper::getSpeed
static double getSpeed(const std::string &id, const std::string &speedClassS)
Returns the speed evaluating the given Navteq-description.
Definition: NINavTeqHelper.cpp:37