SUMO - Simulation of Urban MObility
SUMOVehicleClass.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // Definitions of SUMO vehicle classes and helper functions
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
13 // Copyright (C) 2001-2015 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <string>
35 #include <map>
36 #include "SUMOVehicleClass.h"
38 #include <utils/common/ToString.h>
41 
42 
43 #ifdef CHECK_MEMORY_LEAKS
44 #include <foreign/nvwa/debug_new.h>
45 #endif // CHECK_MEMORY_LEAKS
46 
47 
48 // ===========================================================================
49 // static members
50 // ===========================================================================
52  {"ignoring", SVC_IGNORING},
53  {"private", SVC_PRIVATE},
54  {"public_emergency", SVC_EMERGENCY}, // !!! deprecated
55  {"emergency", SVC_EMERGENCY},
56  {"public_authority", SVC_AUTHORITY}, // !!! deprecated
57  {"authority", SVC_AUTHORITY},
58  {"public_army", SVC_ARMY}, // !!! deprecated
59  {"army", SVC_ARMY},
60  {"vip", SVC_VIP},
61  {"passenger", SVC_PASSENGER},
62  {"hov", SVC_HOV},
63  {"taxi", SVC_TAXI},
64  {"public_transport", SVC_BUS}, // !!! deprecated
65  {"bus", SVC_BUS},
66  {"coach", SVC_COACH},
67  {"delivery", SVC_DELIVERY},
68  {"transport", SVC_TRUCK},
69  {"truck", SVC_TRUCK},
70  {"trailer", SVC_TRAILER},
71  {"lightrail", SVC_TRAM}, // !!! deprecated
72  {"tram", SVC_TRAM},
73  {"cityrail", SVC_RAIL_URBAN}, // !!! deprecated
74  {"rail_urban", SVC_RAIL_URBAN},
75  {"rail_slow", SVC_RAIL}, // !!! deprecated
76  {"rail", SVC_RAIL},
77  {"rail_fast", SVC_RAIL_ELECTRIC}, // !!! deprecated
78  {"rail_electric", SVC_RAIL_ELECTRIC},
79  {"motorcycle", SVC_MOTORCYCLE},
80  {"moped", SVC_MOPED},
81  {"bicycle", SVC_BICYCLE},
82  {"pedestrian", SVC_PEDESTRIAN},
83  {"evehicle", SVC_E_VEHICLE},
84  {"ship", SVC_SHIP},
85  {"custom1", SVC_CUSTOM1},
86  {"custom2", SVC_CUSTOM2}
87 };
88 
90  sumoVehicleClassStringInitializer, SVC_CUSTOM2, false);
91 
92 std::set<std::string> deprecatedVehicleClassesSeen;
93 
94 
96  {"pedestrian", SVS_PEDESTRIAN},
97  {"bicycle", SVS_BICYCLE},
98  {"moped", SVS_MOPED},
99  {"motorcycle", SVS_MOTORCYCLE},
100  {"passenger", SVS_PASSENGER},
101  {"passenger/sedan", SVS_PASSENGER_SEDAN},
102  {"passenger/hatchback", SVS_PASSENGER_HATCHBACK},
103  {"passenger/wagon", SVS_PASSENGER_WAGON},
104  {"passenger/van", SVS_PASSENGER_VAN},
105  {"delivery", SVS_DELIVERY},
106  {"transport", SVS_TRUCK}, // !!! deprecated
107  {"truck", SVS_TRUCK},
108  {"transport/semitrailer", SVS_TRUCK_SEMITRAILER}, // !!! deprecated
109  {"truck/semitrailer", SVS_TRUCK_SEMITRAILER},
110  {"transport/trailer", SVS_TRUCK_1TRAILER}, // !!! deprecated
111  {"truck/trailer", SVS_TRUCK_1TRAILER},
112  {"bus/city", SVS_BUS}, // !!! deprecated
113  {"bus", SVS_BUS},
114  {"bus/overland", SVS_BUS_COACH}, // !!! deprecated
115  {"bus/coach", SVS_BUS_COACH},
116  {"bus/flexible", SVS_BUS_FLEXIBLE},
117  {"bus/trolley", SVS_BUS_TROLLEY},
118  {"rail/slow", SVS_RAIL}, // !!! deprecated
119  {"rail/fast", SVS_RAIL}, // !!! deprecated
120  {"rail", SVS_RAIL},
121  {"rail/light", SVS_RAIL_CAR}, // !!! deprecated
122  {"rail/city", SVS_RAIL_CAR}, // !!! deprecated
123  {"rail/railcar", SVS_RAIL_CAR},
124  {"rail/cargo", SVS_RAIL_CARGO},
125  {"evehicle", SVS_E_VEHICLE},
126  {"ant", SVS_ANT},
127  {"ship", SVS_SHIP},
128  {"", SVS_UNKNOWN}
129 };
130 
131 
133  sumoVehicleShapeStringInitializer, SVS_UNKNOWN, false);
134 
135 
136 // ===========================================================================
137 // additional constants
138 // ===========================================================================
139 
141 const SVCPermissions SVCAll = 2 * SUMOVehicleClass_MAX - 1; // all relevant bits set to 1
143 
144 
145 // ===========================================================================
146 // method definitions
147 // ===========================================================================
148 // ------------ Conversion of SUMOVehicleClass
149 
150 std::string
152  std::string ret;
153  const std::vector<std::string> names = SumoVehicleClassStrings.getStrings();
154  for (std::vector<std::string>::const_iterator it = names.begin(); it != names.end(); it++) {
155  if ((id & SumoVehicleClassStrings.get(*it))) {
156  ret += ("|" + *it);
157  }
158  }
159  if (ret.length() > 0) {
160  return ret.substr(1);
161  } else {
162  return ret;
163  }
164 }
165 
166 
167 std::string
169  if (permissions == SVCAll) {
170  return "all";
171  }
172  return joinToString(getVehicleClassNamesList(permissions), ' ');
173 }
174 
175 
176 std::vector<std::string>
179  const std::vector<std::string> classNames = SumoVehicleClassStrings.getStrings();
180  std::vector<std::string> result;
181  for (std::vector<std::string>::const_iterator it = classNames.begin(); it != classNames.end(); it++) {
182  const int svc = (int)SumoVehicleClassStrings.get(*it);
183  if ((svc & permissions) == svc && svc != SVC_IGNORING) {
184  result.push_back(*it);
185  }
186  }
187  return result;
188 }
189 
190 
192 getVehicleClassID(const std::string& name) {
193  if (SumoVehicleClassStrings.hasString(name)) {
194  return SumoVehicleClassStrings.get(name);
195  }
196  throw InvalidArgument("Unknown vehicle class '" + name + "'.");
197 }
198 
199 
200 int
201 getVehicleClassCompoundID(const std::string& name) {
202  int ret = SVC_IGNORING;
203  const std::vector<std::string> names = SumoVehicleClassStrings.getStrings();
204  for (std::vector<std::string>::const_iterator it = names.begin(); it != names.end(); it++) {
205  if (name.find(*it) != std::string::npos) {
206  ret = ret | (int) SumoVehicleClassStrings.get(*it);
207  }
208  }
209  return ret;
210 }
211 
212 
214 parseVehicleClasses(const std::string& allowedS) {
215  if (allowedS == "all") {
216  return SVCAll;
217  }
218  SVCPermissions result = 0;
219  StringTokenizer sta(allowedS, " ");
220  while (sta.hasNext()) {
221  const std::string s = sta.next();
222  const SUMOVehicleClass vc = getVehicleClassID(s);
223  const std::string& realName = SumoVehicleClassStrings.getString(vc);
224  if (realName != s) {
226  }
227  result |= vc;
228  }
229  return result;
230 }
231 
232 
233 bool
234 canParseVehicleClasses(const std::string& classes) {
235  if (classes == "all") {
236  return true;
237  }
238  StringTokenizer sta(classes, " ");
239  while (sta.hasNext()) {
240  if (!SumoVehicleClassStrings.hasString(sta.next())) {
241  return false;
242  }
243  }
244  return true;
245 }
246 
247 
248 extern SVCPermissions parseVehicleClasses(const std::string& allowedS, const std::string& disallowedS) {
249  if (allowedS.size() == 0 && disallowedS.size() == 0) {
250  return SVCAll;
251  } else if (allowedS.size() > 0 && disallowedS.size() > 0) {
252  WRITE_WARNING("SVCPermissions must be specified either via 'allow' or 'disallow'. Ignoring 'disallow'");
253  return parseVehicleClasses(allowedS);
254  } else if (allowedS.size() > 0) {
255  return parseVehicleClasses(allowedS);
256  } else {
257  return SVCAll & ~parseVehicleClasses(disallowedS);
258  }
259 }
260 
261 
263 parseVehicleClasses(const std::vector<std::string>& allowedS) {
264  SVCPermissions result = 0;
265  for (std::vector<std::string>::const_iterator i = allowedS.begin(); i != allowedS.end(); ++i) {
266  const SUMOVehicleClass vc = getVehicleClassID(*i);
267  const std::string& realName = SumoVehicleClassStrings.getString(vc);
268  if (realName != *i) {
269  WRITE_WARNING("The vehicle class '" + (*i) + "' is deprecated, use '" + realName + "' instead.");
270  }
271  result |= getVehicleClassID(*i);
272  }
273  return result;
274 }
275 
276 
278 getVehicleShapeID(const std::string& name) {
279  if (SumoVehicleShapeStrings.hasString(name)) {
280  return SumoVehicleShapeStrings.get(name);
281  } else {
282  throw InvalidArgument("Unknown vehicle shape '" + name + "'.");
283  }
284 }
285 
286 
287 std::string
289  return SumoVehicleShapeStrings.getString(id);
290 }
291 
292 
293 bool isRailway(SVCPermissions permissions) {
294  return (permissions & (SVC_RAIL_ELECTRIC | SVC_RAIL | SVC_RAIL_URBAN | SVC_TRAM)) > 0 && (permissions & SVC_PASSENGER) == 0;
295 }
296 
297 
298 bool isWaterway(SVCPermissions permissions) {
299  return permissions == SVC_SHIP;
300 }
301 
302 
303 bool isForbidden(SVCPermissions permissions) {
304  return (permissions & SVCAll) == 0;
305 }
306 
307 
308 const std::string DEFAULT_VTYPE_ID("DEFAULT_VEHTYPE");
309 const std::string DEFAULT_PEDTYPE_ID("DEFAULT_PEDTYPE");
310 
311 const SUMOReal DEFAULT_VEH_PROB(1.);
312 
313 const SUMOReal DEFAULT_PEDESTRIAN_SPEED(5. / 3.6);
314 
316 
317 /****************************************************************************/
318 
SUMOVehicleClass getVehicleClassID(const std::string &name)
Returns the class id of the abstract class given by its name.
std::string getVehicleClassCompoundName(int id)
vehicle is a motorcycle
vehicle is a coach
render as a rail
std::set< std::string > deprecatedVehicleClassesSeen
is a pedestrian
std::string next()
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types...
StringBijection< SUMOVehicleShape > SumoVehicleShapeStrings(sumoVehicleShapeStringInitializer, SVS_UNKNOWN, false)
render as a motorcycle
vehicle is a not electrified rail
render as a transport vehicle
vehicle is a bicycle
render as a flexible city bus
int SVCPermissions
vehicle is a small delivery vehicle
std::vector< std::string > getVehicleClassNamesList(SVCPermissions permissions)
Returns the ids of the given classes, divided using a ' '.
vehicle is a light rail
render as a delivery vehicle
StringBijection< SUMOVehicleClass >::Entry sumoVehicleClassStringInitializer[]
StringBijection< SUMOVehicleShape >::Entry sumoVehicleShapeStringInitializer[]
render as a sedan passenger vehicle ("Stufenheck")
bool isForbidden(SVCPermissions permissions)
Returns whether an edge with the given permission is a forbidden edge.
bool isRailway(SVCPermissions permissions)
Returns whether an edge with the given permission is a railway edge.
const SVCPermissions SVCAll
vehicle is a HOV
vehicle is a (possibly fast moving) electric rail
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
authorities vehicles
vehicle is a city rail
std::string getVehicleShapeName(SUMOVehicleShape id)
Returns the class name of the shape class given by its id.
vehicle is a large transport vehicle
is a user-defined type
const int SUMOVehicleClass_MAX
const SUMOReal DEFAULT_VEH_PROB(1.)
render as a hatchback passenger vehicle ("Fliessheck")
render as a bus
army vehicles
private vehicles
not defined
bool isWaterway(SVCPermissions permissions)
Returns whether an edge with the given permission is a waterway edge.
render as a bicycle
render as a (city) rail without locomotive
int getVehicleClassCompoundID(const std::string &name)
Returns the OR'ed id of the compound class given by its name.
const SUMOReal DEFAULT_CONTAINER_TRANSHIP_SPEED(5./3.6)
SVCPermissions parseVehicleClasses(const std::string &allowedS)
Parses the given definition of allowed vehicle classes into the given containers Deprecated classes g...
render as a van
StringBijection< SUMOVehicleClass > SumoVehicleClassStrings(sumoVehicleClassStringInitializer, SVC_CUSTOM2, false)
render as a passenger vehicle
const SUMOReal DEFAULT_PEDESTRIAN_SPEED(5./3.6)
std::string getVehicleClassNames(SVCPermissions permissions)
Returns the ids of the given classes, divided using a ' '.
vehicle is a passenger car (a "normal" car)
is an arbitrary ship
vehicle is a moped
bool canParseVehicleClasses(const std::string &classes)
Checks whether the given string contains only known vehicle classes.
render as a cargo train
vehicle is a taxi
vehicle is a bus
render as a giant ant
render as a pedestrian
render as a moped
SUMOVehicleShape
Definition of vehicle classes to differ between different appearences.
render as a arbitrary ship
vip vehicles
vehicle is a large transport vehicle
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:159
render as a (futuristic) e-vehicle
SUMOVehicleShape getVehicleShapeID(const std::string &name)
Returns the class id of the shape class given by its name.
#define SUMOReal
Definition: config.h:218
public emergency vehicles
render as a transport vehicle with one trailer
render as a wagon passenger vehicle ("Combi")
const std::string DEFAULT_PEDTYPE_ID("DEFAULT_PEDTYPE")
const std::string DEFAULT_VTYPE_ID("DEFAULT_VEHTYPE")
render as a coach
render as a semi-trailer transport vehicle ("Sattelschlepper")
vehicles ignoring classes
const SVCPermissions SVC_UNSPECIFIED
render as a trolley bus
is a user-defined type
is an electric vehicle