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-2020 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 /****************************************************************************/
21 // Some parser methods shared around several formats containing NavTeq-Nets
22 /****************************************************************************/
23 #include <config.h>
24 
25 #include "NINavTeqHelper.h"
29 #include <netbuild/NBEdge.h>
30 
31 
32 // ===========================================================================
33 // method definitions
34 // ===========================================================================
35 double
36 NINavTeqHelper::getSpeed(const std::string& id, const std::string& speedClassS) {
37  try {
38  int speedClass = StringUtils::toInt(speedClassS);
39  switch (speedClass) {
40  case -1:
41  return (double) 1.0 / (double) 3.6;
42  case 1:
43  return (double) 200 / (double) 3.6; //> 130 KPH / > 80 MPH
44  case 2:
45  return (double) 120 / (double) 3.6; //101-130 KPH / 65-80 MPH
46  case 3:
47  return (double) 100 / (double) 3.6; // 91-100 KPH / 55-64 MPH
48  case 4:
49  return (double) 80 / (double) 3.6; // 71-90 KPH / 41-54 MPH
50  case 5:
51  return (double) 70 / (double) 3.6; // 51-70 KPH / 31-40 MPH
52  case 6:
53  return (double) 50 / (double) 3.6; // 31-50 KPH / 21-30 MPH
54  case 7:
55  return (double) 30 / (double) 3.6; // 11-30 KPH / 6-20 MPH
56  case 8:
57  return (double) 5 / (double) 3.6; //< 11 KPH / < 6 MPH
58  default:
59  throw ProcessError("Invalid speed code (edge '" + id + "').");
60  }
61  } catch (NumberFormatException&) {
62  throw ProcessError("Non-numerical value for an edge's speed type occurred (edge '" + id + "').");
63  }
64 }
65 
66 
67 int
68 NINavTeqHelper::getLaneNumber(const std::string& id, const std::string& laneNoS, double speed) {
69  try {
70  int nolanes = StringUtils::toInt(laneNoS);
71  if (nolanes < 0) {
72  return 1;
73  } else if (nolanes / 10 > 0) {
74  return nolanes / 10;
75  } else {
76  switch (nolanes % 10) {
77  case 1:
78  return 1;
79  case 2:
80  nolanes = 2;
81  if (speed > 78.0 / 3.6) {
82  nolanes = 3;
83  }
84  return nolanes;
85  case 3:
86  return 4;
87  default:
88  throw ProcessError("Invalid lane number (edge '" + id + "').");
89  }
90  }
91  } catch (NumberFormatException&) {
92  throw ProcessError("Non-numerical value for an edge's lane number occurred (edge '" + id + "'.");
93  }
94 }
95 
96 
97 bool
98 NINavTeqHelper::addCommonVehicleClasses(NBEdge& e, const std::string& classS, const int offset) {
99  bool haveCar = false;
100  // High Occupancy Vehicle -- becomes SVC_PASSENGER|SVC_HOV
101  if (classS[offset] == '1') {
102  e.allowVehicleClass(-1, SVC_HOV);
104  haveCar = true;
105  } else {
107  }
108  // Emergency Vehicle -- becomes SVC_EMERGENCY
109  if (classS[offset + 1] == '1') {
111  } else {
113  }
114  // Taxi -- becomes SVC_TAXI
115  if (classS[offset + 2] == '1') {
117  haveCar = true;
118  } else {
120  }
121  // Public Bus -- becomes SVC_BUS|SVC_COACH
122  if (classS[offset + 3] == '1') {
123  e.allowVehicleClass(-1, SVC_BUS);
125  haveCar = true;
126  } else {
129  }
130  // Delivery Truck -- becomes SVC_DELIVERY
131  if (classS[offset + 4] == '1') {
133  haveCar = true;
134  } else {
136  }
137  // Transport Truck -- becomes SVC_TRUCK|SVC_TRAILER
138  if (classS[offset + 5] == '1') {
141  haveCar = true;
142  } else {
145  }
146  return haveCar;
147 }
148 
149 
150 void
151 NINavTeqHelper::addVehicleClasses(NBEdge& e, const std::string& oclassS, const SVCPermissions allPermissions, const SVCPermissions defaultPermissions) {
152  std::string classS = "0000000000" + oclassS;
153  classS = classS.substr(classS.length() - 10);
154  // 0: allow all vehicle types
155  if (classS[0] == '1') {
156  e.setPermissions(allPermissions);
157  return;
158  }
159  bool haveCar = false;
160  e.setPermissions(defaultPermissions);
161  // Passenger cars -- becomes SVC_PASSENGER
162  if (classS[1] == '1') {
164  haveCar = true;
165  } else {
167  }
168  haveCar |= addCommonVehicleClasses(e, classS, 2);
169  if (!haveCar) {
170  e.setPermissions(0);
171  }
172  // Bicycle -- becomes SVC_BICYCLE
173  if (classS[8] == '1') {
175  } else {
177  }
178  // Pedestrian -- becomes SVC_PEDESTRIAN
179  if (classS[9] == '1') {
181  } else {
183  }
184 }
185 
186 
187 void
188 NINavTeqHelper::addVehicleClassesV6(NBEdge& e, const std::string& oclassS, const SVCPermissions allPermissions, const SVCPermissions defaultPermissions) {
189  std::string classS = "0000000000" + oclassS;
190  classS = classS.substr(classS.length() - 12);
191  // 0: allow all vehicle types
192  if (classS[0] == '1') {
193  e.setPermissions(allPermissions);
194  return;
195  }
196  bool haveCar = false;
197  e.setPermissions(defaultPermissions);
198  // Passenger cars -- becomes SVC_PASSENGER
199  if (classS[1] == '1') {
201  haveCar = true;
202  } else {
204  }
205  // Residential Vehicle -- becomes SVC_PASSENGER
206  if (classS[2] == '1') {
208  haveCar = true;
209  }
210  haveCar |= addCommonVehicleClasses(e, classS, 3);
211  if (!haveCar) {
212  e.setPermissions(0);
213  }
214  // Motorcycle -- becomes SVC_MOTORCYCLE
215  if (classS[9] == '1') {
217  } else {
219  }
220  // Bicycle -- becomes SVC_BICYCLE
221  if (classS[10] == '1') {
223  } else {
225  }
226  // Pedestrian -- becomes SVC_PEDESTRIAN
227  if (classS[11] == '1') {
229  } else {
231  }
232 }
233 
234 
235 /****************************************************************************/
@ SVC_HOV
vehicle is a HOV
@ SVC_TRUCK
vehicle is a large transport vehicle
@ SVC_COACH
vehicle is a coach
@ SVC_PASSENGER
vehicle is a passenger car (a "normal" car)
@ SVC_BICYCLE
vehicle is a bicycle
@ SVC_TRAILER
vehicle is a large transport vehicle
@ SVC_DELIVERY
vehicle is a small delivery vehicle
@ SVC_MOTORCYCLE
vehicle is a motorcycle
@ SVC_EMERGENCY
public emergency vehicles
@ SVC_TAXI
vehicle is a taxi
@ SVC_BUS
vehicle is a bus
@ SVC_PEDESTRIAN
pedestrian
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
The representation of a single edge during network building.
Definition: NBEdge.h:91
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:3627
void disallowVehicleClass(int lane, SUMOVehicleClass vclass)
set disallowed class for the given lane or for all lanes if -1 is given
Definition: NBEdge.cpp:3465
void allowVehicleClass(int lane, SUMOVehicleClass vclass)
set allowed class for the given lane or for all lanes if -1 is given
Definition: NBEdge.cpp:3452
static void addVehicleClasses(NBEdge &e, const std::string &classS, const SVCPermissions allPermissions, const SVCPermissions defaultPermissions)
Adds vehicle classes parsing the given list of allowed vehicles.
static void addVehicleClassesV6(NBEdge &e, const std::string &classS, const SVCPermissions allPermissions, const SVCPermissions defaultPermissions)
same as addVehicleClasses but for version 6+
static int getLaneNumber(const std::string &id, const std::string &laneNoS, double speed)
Returns the lane number evaluating the given Navteq-description.
static double getSpeed(const std::string &id, const std::string &speedClassS)
Returns the speed evaluating the given Navteq-description.
static bool addCommonVehicleClasses(NBEdge &e, const std::string &classS, const int offset)
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter,...