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-2016 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>
42 
43 
44 #ifdef CHECK_MEMORY_LEAKS
45 #include <foreign/nvwa/debug_new.h>
46 #endif // CHECK_MEMORY_LEAKS
47 
48 
49 // ===========================================================================
50 // static members
51 // ===========================================================================
53  {"ignoring", SVC_IGNORING},
54  {"private", SVC_PRIVATE},
55  {"public_emergency", SVC_EMERGENCY}, // !!! deprecated
56  {"emergency", SVC_EMERGENCY},
57  {"public_authority", SVC_AUTHORITY}, // !!! deprecated
58  {"authority", SVC_AUTHORITY},
59  {"public_army", SVC_ARMY}, // !!! deprecated
60  {"army", SVC_ARMY},
61  {"vip", SVC_VIP},
62  {"passenger", SVC_PASSENGER},
63  {"hov", SVC_HOV},
64  {"taxi", SVC_TAXI},
65  {"public_transport", SVC_BUS}, // !!! deprecated
66  {"bus", SVC_BUS},
67  {"coach", SVC_COACH},
68  {"delivery", SVC_DELIVERY},
69  {"transport", SVC_TRUCK},
70  {"truck", SVC_TRUCK},
71  {"trailer", SVC_TRAILER},
72  {"lightrail", SVC_TRAM}, // !!! deprecated
73  {"tram", SVC_TRAM},
74  {"cityrail", SVC_RAIL_URBAN}, // !!! deprecated
75  {"rail_urban", SVC_RAIL_URBAN},
76  {"rail_slow", SVC_RAIL}, // !!! deprecated
77  {"rail", SVC_RAIL},
78  {"rail_fast", SVC_RAIL_ELECTRIC}, // !!! deprecated
79  {"rail_electric", SVC_RAIL_ELECTRIC},
80  {"motorcycle", SVC_MOTORCYCLE},
81  {"moped", SVC_MOPED},
82  {"bicycle", SVC_BICYCLE},
83  {"pedestrian", SVC_PEDESTRIAN},
84  {"evehicle", SVC_E_VEHICLE},
85  {"ship", SVC_SHIP},
86  {"custom1", SVC_CUSTOM1},
87  {"custom2", SVC_CUSTOM2}
88 };
89 
91  sumoVehicleClassStringInitializer, SVC_CUSTOM2, false);
92 
93 std::set<std::string> deprecatedVehicleClassesSeen;
94 
95 
97  {"pedestrian", SVS_PEDESTRIAN},
98  {"bicycle", SVS_BICYCLE},
99  {"moped", SVS_MOPED},
100  {"motorcycle", SVS_MOTORCYCLE},
101  {"passenger", SVS_PASSENGER},
102  {"passenger/sedan", SVS_PASSENGER_SEDAN},
103  {"passenger/hatchback", SVS_PASSENGER_HATCHBACK},
104  {"passenger/wagon", SVS_PASSENGER_WAGON},
105  {"passenger/van", SVS_PASSENGER_VAN},
106  {"delivery", SVS_DELIVERY},
107  {"transport", SVS_TRUCK}, // !!! deprecated
108  {"truck", SVS_TRUCK},
109  {"transport/semitrailer", SVS_TRUCK_SEMITRAILER}, // !!! deprecated
110  {"truck/semitrailer", SVS_TRUCK_SEMITRAILER},
111  {"transport/trailer", SVS_TRUCK_1TRAILER}, // !!! deprecated
112  {"truck/trailer", SVS_TRUCK_1TRAILER},
113  {"bus/city", SVS_BUS}, // !!! deprecated
114  {"bus", SVS_BUS},
115  {"bus/overland", SVS_BUS_COACH}, // !!! deprecated
116  {"bus/coach", SVS_BUS_COACH},
117  {"bus/flexible", SVS_BUS_FLEXIBLE},
118  {"bus/trolley", SVS_BUS_TROLLEY},
119  {"rail/slow", SVS_RAIL}, // !!! deprecated
120  {"rail/fast", SVS_RAIL}, // !!! deprecated
121  {"rail", SVS_RAIL},
122  {"rail/light", SVS_RAIL_CAR}, // !!! deprecated
123  {"rail/city", SVS_RAIL_CAR}, // !!! deprecated
124  {"rail/railcar", SVS_RAIL_CAR},
125  {"rail/cargo", SVS_RAIL_CARGO},
126  {"evehicle", SVS_E_VEHICLE},
127  {"ant", SVS_ANT},
128  {"ship", SVS_SHIP},
129  {"emergency", SVS_EMERGENCY},
130  {"", SVS_UNKNOWN}
131 };
132 
133 
135  sumoVehicleShapeStringInitializer, SVS_UNKNOWN, false);
136 
137 
138 // ===========================================================================
139 // additional constants
140 // ===========================================================================
141 
143 const SVCPermissions SVCAll = 2 * SUMOVehicleClass_MAX - 1; // all relevant bits set to 1
145 
146 
147 // ===========================================================================
148 // method definitions
149 // ===========================================================================
150 // ------------ Conversion of SUMOVehicleClass
151 
152 std::string
154  if (permissions == SVCAll) {
155  return "all";
156  }
157  return joinToString(getVehicleClassNamesList(permissions), ' ');
158 }
159 
160 
161 std::vector<std::string>
164  const std::vector<std::string> classNames = SumoVehicleClassStrings.getStrings();
165  std::vector<std::string> result;
166  for (std::vector<std::string>::const_iterator it = classNames.begin(); it != classNames.end(); it++) {
167  const int svc = (int)SumoVehicleClassStrings.get(*it);
168  if ((svc & permissions) == svc && svc != SVC_IGNORING) {
169  result.push_back(*it);
170  }
171  }
172  return result;
173 }
174 
175 
177 getVehicleClassID(const std::string& name) {
178  if (SumoVehicleClassStrings.hasString(name)) {
179  return SumoVehicleClassStrings.get(name);
180  }
181  throw InvalidArgument("Unknown vehicle class '" + name + "'.");
182 }
183 
184 
185 int
186 getVehicleClassCompoundID(const std::string& name) {
187  int ret = SVC_IGNORING;
188  const std::vector<std::string> names = SumoVehicleClassStrings.getStrings();
189  for (std::vector<std::string>::const_iterator it = names.begin(); it != names.end(); it++) {
190  if (name.find(*it) != std::string::npos) {
191  ret = ret | (int) SumoVehicleClassStrings.get(*it);
192  }
193  }
194  return ret;
195 }
196 
197 
199 parseVehicleClasses(const std::string& allowedS) {
200  if (allowedS == "all") {
201  return SVCAll;
202  }
203  SVCPermissions result = 0;
204  StringTokenizer sta(allowedS, " ");
205  while (sta.hasNext()) {
206  const std::string s = sta.next();
207  const SUMOVehicleClass vc = getVehicleClassID(s);
208  const std::string& realName = SumoVehicleClassStrings.getString(vc);
209  if (realName != s) {
211  }
212  result |= vc;
213  }
214  return result;
215 }
216 
217 
218 bool
219 canParseVehicleClasses(const std::string& classes) {
220  if (classes == "all") {
221  return true;
222  }
223  StringTokenizer sta(classes, " ");
224  while (sta.hasNext()) {
225  if (!SumoVehicleClassStrings.hasString(sta.next())) {
226  return false;
227  }
228  }
229  return true;
230 }
231 
232 
233 extern SVCPermissions parseVehicleClasses(const std::string& allowedS, const std::string& disallowedS) {
234  if (allowedS.size() == 0 && disallowedS.size() == 0) {
235  return SVCAll;
236  } else if (allowedS.size() > 0 && disallowedS.size() > 0) {
237  WRITE_WARNING("SVCPermissions must be specified either via 'allow' or 'disallow'. Ignoring 'disallow'");
238  return parseVehicleClasses(allowedS);
239  } else if (allowedS.size() > 0) {
240  return parseVehicleClasses(allowedS);
241  } else {
242  return SVCAll & ~parseVehicleClasses(disallowedS);
243  }
244 }
245 
246 
248 parseVehicleClasses(const std::vector<std::string>& allowedS) {
249  SVCPermissions result = 0;
250  for (std::vector<std::string>::const_iterator i = allowedS.begin(); i != allowedS.end(); ++i) {
251  const SUMOVehicleClass vc = getVehicleClassID(*i);
252  const std::string& realName = SumoVehicleClassStrings.getString(vc);
253  if (realName != *i) {
254  WRITE_WARNING("The vehicle class '" + (*i) + "' is deprecated, use '" + realName + "' instead.");
255  }
256  result |= getVehicleClassID(*i);
257  }
258  return result;
259 }
260 
261 
262 void
264  if (permissions == SVCAll) {
265  return;
266  } else if (permissions == 0) {
267  into.writeAttr(SUMO_ATTR_DISALLOW, "all");
268  return;
269  } else {
270  int num_allowed = 0;
271  for (int mask = 1; mask <= SUMOVehicleClass_MAX; mask = mask << 1) {
272  if ((mask & permissions) == mask) {
273  ++num_allowed;
274  }
275  }
276  if (num_allowed <= (SumoVehicleClassStrings.size() - num_allowed) && num_allowed > 0) {
277  into.writeAttr(SUMO_ATTR_ALLOW, getVehicleClassNames(permissions));
278  } else {
280  }
281  }
282 }
283 
284 
285 void
287  if (preferred == SVCAll || preferred == 0) {
288  return;
289  } else {
291  }
292 }
293 
294 
296 getVehicleShapeID(const std::string& name) {
297  if (SumoVehicleShapeStrings.hasString(name)) {
298  return SumoVehicleShapeStrings.get(name);
299  } else {
300  throw InvalidArgument("Unknown vehicle shape '" + name + "'.");
301  }
302 }
303 
304 
305 std::string
307  return SumoVehicleShapeStrings.getString(id);
308 }
309 
310 
311 bool isRailway(SVCPermissions permissions) {
312  return (permissions & (SVC_RAIL_ELECTRIC | SVC_RAIL | SVC_RAIL_URBAN | SVC_TRAM)) > 0 && (permissions & SVC_PASSENGER) == 0;
313 }
314 
315 
316 bool isWaterway(SVCPermissions permissions) {
317  return permissions == SVC_SHIP;
318 }
319 
320 
321 bool isForbidden(SVCPermissions permissions) {
322  return (permissions & SVCAll) == 0;
323 }
324 
325 
326 const std::string DEFAULT_VTYPE_ID("DEFAULT_VEHTYPE");
327 const std::string DEFAULT_PEDTYPE_ID("DEFAULT_PEDTYPE");
328 
329 const SUMOReal DEFAULT_VEH_PROB(1.);
330 
331 const SUMOReal DEFAULT_PEDESTRIAN_SPEED(5. / 3.6);
332 
334 
335 /****************************************************************************/
336 
SUMOVehicleClass getVehicleClassID(const std::string &name)
Returns the class id of the abstract class given by its name.
void writePermissions(OutputDevice &into, SVCPermissions permissions)
writes allowed disallowed attributes if needed;
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:257
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)
bool hasString(const std::string &str) const
render as a motorcycle
vehicle is a not electrified rail
void writePreferences(OutputDevice &into, SVCPermissions preferred)
writes allowed disallowed attributes if needed;
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 &#39; &#39;.
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
std::vector< std::string > getStrings() const
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
const std::string & getString(const T key) const
render as a (city) rail without locomotive
int getVehicleClassCompoundID(const std::string &name)
Returns the OR&#39;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 &#39; &#39;.
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
render as an emergency vehicle
T get(const std::string &str) const
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:188
render as a (futuristic) e-vehicle
SUMOVehicleShape getVehicleShapeID(const std::string &name)
Returns the class id of the shape class given by its name.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
#define SUMOReal
Definition: config.h:213
int size() const
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