Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
NINavTeqHelper.cpp
Go to the documentation of this file.
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/****************************************************************************/
21// Some parser methods shared around several formats containing NavTeq-Nets
22/****************************************************************************/
23#include <config.h>
24
29#include <netbuild/NBEdge.h>
30
31#include "NINavTeqHelper.h"
32
33
34// ===========================================================================
35// method definitions
36// ===========================================================================
37double
38NINavTeqHelper::getSpeed(const std::string& id, const std::string& speedClassS) {
39 try {
40 int speedClass = StringUtils::toInt(speedClassS);
41 switch (speedClass) {
42 case -1:
43 return (double) 1.0 / (double) 3.6;
44 case 1:
45 return (double) 200 / (double) 3.6; //> 130 KPH / > 80 MPH
46 case 2:
47 return (double) 120 / (double) 3.6; //101-130 KPH / 65-80 MPH
48 case 3:
49 return (double) 100 / (double) 3.6; // 91-100 KPH / 55-64 MPH
50 case 4:
51 return (double) 80 / (double) 3.6; // 71-90 KPH / 41-54 MPH
52 case 5:
53 return (double) 70 / (double) 3.6; // 51-70 KPH / 31-40 MPH
54 case 6:
55 return (double) 50 / (double) 3.6; // 31-50 KPH / 21-30 MPH
56 case 7:
57 return (double) 30 / (double) 3.6; // 11-30 KPH / 6-20 MPH
58 case 8:
59 return (double) 5 / (double) 3.6; //< 11 KPH / < 6 MPH
60 default:
61 throw ProcessError(TLF("Invalid speed code (edge '%').", id));
62 }
63 } catch (NumberFormatException&) {
64 throw ProcessError(TLF("Non-numerical value for an edge's speed type occurred (edge '%').", id));
65 }
66}
67
68
69int
70NINavTeqHelper::getLaneNumber(const std::string& id, const std::string& laneNoS, double speed) {
71 try {
72 int nolanes = StringUtils::toInt(laneNoS);
73 if (nolanes < 0) {
74 return 1;
75 } else if (nolanes / 10 > 0) {
76 return nolanes / 10;
77 } else {
78 switch (nolanes % 10) {
79 case 1:
80 return 1;
81 case 2:
82 nolanes = 2;
83 if (speed > 78.0 / 3.6) {
84 nolanes = 3;
85 }
86 return nolanes;
87 case 3:
88 return 4;
89 default:
90 throw ProcessError(TLF("Invalid lane number (edge '%').", id));
91 }
92 }
93 } catch (NumberFormatException&) {
94 throw ProcessError(TLF("Non-numerical value for an edge's lane number occurred (edge '%').", id));
95 }
96}
97
98
99bool
100NINavTeqHelper::addCommonVehicleClasses(NBEdge& e, const std::string& classS, const int offset) {
101 bool haveCar = false;
102 // High Occupancy Vehicle -- becomes SVC_PASSENGER|SVC_HOV
103 if (classS[offset] == '1') {
106 haveCar = true;
107 } else {
109 }
110 // Emergency Vehicle -- becomes SVC_EMERGENCY
111 if (classS[offset + 1] == '1') {
113 } else {
115 }
116 // Taxi -- becomes SVC_TAXI
117 if (classS[offset + 2] == '1') {
119 haveCar = true;
120 } else {
122 }
123 // Public Bus -- becomes SVC_BUS|SVC_COACH
124 if (classS[offset + 3] == '1') {
127 haveCar = true;
128 } else {
131 }
132 // Delivery Truck -- becomes SVC_DELIVERY
133 if (classS[offset + 4] == '1') {
135 haveCar = true;
136 } else {
138 }
139 // Transport Truck -- becomes SVC_TRUCK|SVC_TRAILER
140 if (classS[offset + 5] == '1') {
143 haveCar = true;
144 } else {
147 }
148 return haveCar;
149}
150
151
152void
153NINavTeqHelper::addVehicleClasses(NBEdge& e, const std::string& oclassS, const SVCPermissions allPermissions, const SVCPermissions defaultPermissions) {
154 std::string classS = "0000000000" + oclassS;
155 classS = classS.substr(classS.length() - 10);
156 // 0: allow all vehicle types
157 if (classS[0] == '1') {
158 e.setPermissions(allPermissions);
159 return;
160 }
161 bool haveCar = false;
162 e.setPermissions(defaultPermissions);
163 // Passenger cars -- becomes SVC_PASSENGER
164 if (classS[1] == '1') {
166 haveCar = true;
167 } else {
169 }
170 haveCar |= addCommonVehicleClasses(e, classS, 2);
171 if (!haveCar) {
172 e.setPermissions(0);
173 }
174 // Bicycle -- becomes SVC_BICYCLE
175 if (classS[8] == '1') {
177 } else {
179 }
180 // Pedestrian -- becomes SVC_PEDESTRIAN
181 if (classS[9] == '1') {
183 } else {
185 }
186}
187
188
189void
190NINavTeqHelper::addVehicleClassesV6(NBEdge& e, const std::string& oclassS, const SVCPermissions allPermissions, const SVCPermissions defaultPermissions) {
191 std::string classS = "0000000000" + oclassS;
192 classS = classS.substr(classS.length() - 12);
193 // 0: allow all vehicle types
194 if (classS[0] == '1') {
195 e.setPermissions(allPermissions);
196 return;
197 }
198 bool haveCar = false;
199 e.setPermissions(defaultPermissions);
200 // Passenger cars -- becomes SVC_PASSENGER
201 if (classS[1] == '1') {
203 haveCar = true;
204 } else {
206 }
207 // Residential Vehicle -- becomes SVC_PASSENGER
208 if (classS[2] == '1') {
210 haveCar = true;
211 }
212 haveCar |= addCommonVehicleClasses(e, classS, 3);
213 if (!haveCar) {
214 e.setPermissions(0);
215 }
216 // Motorcycle -- becomes SVC_MOTORCYCLE
217 if (classS[9] == '1') {
219 } else {
221 }
222 // Bicycle -- becomes SVC_BICYCLE
223 if (classS[10] == '1') {
225 } else {
227 }
228 // Pedestrian -- becomes SVC_PEDESTRIAN
229 if (classS[11] == '1') {
231 } else {
233 }
234}
235
236
237/****************************************************************************/
#define TLF(string,...)
Definition MsgHandler.h:317
long long int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
@ 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
The representation of a single edge during network building.
Definition NBEdge.h:92
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:4341
void disallowVehicleClass(int lane, SUMOVehicleClass vclass)
set disallowed class for the given lane or for all lanes if -1 is given
Definition NBEdge.cpp:4137
void allowVehicleClass(int lane, SUMOVehicleClass vclass)
set allowed class for the given lane or for all lanes if -1 is given
Definition NBEdge.cpp:4124
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,...