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-2017 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 // ===========================================================================
45 // static members
46 // ===========================================================================
47 
49  {"ignoring", SVC_IGNORING},
50  {"private", SVC_PRIVATE},
51  {"public_emergency", SVC_EMERGENCY}, // !!! deprecated
52  {"emergency", SVC_EMERGENCY},
53  {"public_authority", SVC_AUTHORITY}, // !!! deprecated
54  {"authority", SVC_AUTHORITY},
55  {"public_army", SVC_ARMY}, // !!! deprecated
56  {"army", SVC_ARMY},
57  {"vip", SVC_VIP},
58  {"passenger", SVC_PASSENGER},
59  {"hov", SVC_HOV},
60  {"taxi", SVC_TAXI},
61  {"public_transport", SVC_BUS}, // !!! deprecated
62  {"bus", SVC_BUS},
63  {"coach", SVC_COACH},
64  {"delivery", SVC_DELIVERY},
65  {"transport", SVC_TRUCK},
66  {"truck", SVC_TRUCK},
67  {"trailer", SVC_TRAILER},
68  {"lightrail", SVC_TRAM}, // !!! deprecated
69  {"tram", SVC_TRAM},
70  {"cityrail", SVC_RAIL_URBAN}, // !!! deprecated
71  {"rail_urban", SVC_RAIL_URBAN},
72  {"rail_slow", SVC_RAIL}, // !!! deprecated
73  {"rail", SVC_RAIL},
74  {"rail_fast", SVC_RAIL_ELECTRIC}, // !!! deprecated
75  {"rail_electric", SVC_RAIL_ELECTRIC},
76  {"motorcycle", SVC_MOTORCYCLE},
77  {"moped", SVC_MOPED},
78  {"bicycle", SVC_BICYCLE},
79  {"pedestrian", SVC_PEDESTRIAN},
80  {"evehicle", SVC_E_VEHICLE},
81  {"ship", SVC_SHIP},
82  {"custom1", SVC_CUSTOM1},
83  {"custom2", SVC_CUSTOM2}
84 };
85 
87  sumoVehicleClassStringInitializer, SVC_CUSTOM2, false);
88 
89 
90 std::set<std::string> deprecatedVehicleClassesSeen;
91 
92 
94  {"pedestrian", SVS_PEDESTRIAN},
95  {"bicycle", SVS_BICYCLE},
96  {"moped", SVS_MOPED},
97  {"motorcycle", SVS_MOTORCYCLE},
98  {"passenger", SVS_PASSENGER},
99  {"passenger/sedan", SVS_PASSENGER_SEDAN},
100  {"passenger/hatchback", SVS_PASSENGER_HATCHBACK},
101  {"passenger/wagon", SVS_PASSENGER_WAGON},
102  {"passenger/van", SVS_PASSENGER_VAN},
103  {"delivery", SVS_DELIVERY},
104  {"transport", SVS_TRUCK}, // !!! deprecated
105  {"truck", SVS_TRUCK},
106  {"transport/semitrailer", SVS_TRUCK_SEMITRAILER}, // !!! deprecated
107  {"truck/semitrailer", SVS_TRUCK_SEMITRAILER},
108  {"transport/trailer", SVS_TRUCK_1TRAILER}, // !!! deprecated
109  {"truck/trailer", SVS_TRUCK_1TRAILER},
110  {"bus/city", SVS_BUS}, // !!! deprecated
111  {"bus", SVS_BUS},
112  {"bus/overland", SVS_BUS_COACH}, // !!! deprecated
113  {"bus/coach", SVS_BUS_COACH},
114  {"bus/flexible", SVS_BUS_FLEXIBLE},
115  {"bus/trolley", SVS_BUS_TROLLEY},
116  {"rail/slow", SVS_RAIL}, // !!! deprecated
117  {"rail/fast", SVS_RAIL}, // !!! deprecated
118  {"rail", SVS_RAIL},
119  {"rail/light", SVS_RAIL_CAR}, // !!! deprecated
120  {"rail/city", SVS_RAIL_CAR}, // !!! deprecated
121  {"rail/railcar", SVS_RAIL_CAR},
122  {"rail/cargo", SVS_RAIL_CARGO},
123  {"evehicle", SVS_E_VEHICLE},
124  {"ant", SVS_ANT},
125  {"ship", SVS_SHIP},
126  {"emergency", SVS_EMERGENCY},
127  {"firebrigade", SVS_FIREBRIGADE},
128  {"police", SVS_POLICE},
129  {"", SVS_UNKNOWN}
130 };
131 
132 
134  sumoVehicleShapeStringInitializer, SVS_UNKNOWN, false);
135 
136 
137 // ===========================================================================
138 // additional constants
139 // ===========================================================================
140 
142 const SVCPermissions SVCAll = 2 * SUMOVehicleClass_MAX - 1; // all relevant bits set to 1
144 
145 
146 // ===========================================================================
147 // method definitions
148 // ===========================================================================
149 // ------------ Conversion of SUMOVehicleClass
150 
151 std::string
152 getVehicleClassNames(SVCPermissions permissions, bool expand) {
153  if (permissions == SVCAll && !expand) {
154  return "all";
155  }
156  return joinToString(getVehicleClassNamesList(permissions), ' ');
157 }
158 
159 
160 std::vector<std::string>
163  const std::vector<std::string> classNames = SumoVehicleClassStrings.getStrings();
164  std::vector<std::string> result;
165  for (std::vector<std::string>::const_iterator it = classNames.begin(); it != classNames.end(); it++) {
166  const int svc = (int)SumoVehicleClassStrings.get(*it);
167  if ((svc & permissions) == svc && svc != SVC_IGNORING) {
168  result.push_back(*it);
169  }
170  }
171  return result;
172 }
173 
174 
176 getVehicleClassID(const std::string& name) {
177  if (SumoVehicleClassStrings.hasString(name)) {
178  return SumoVehicleClassStrings.get(name);
179  }
180  throw InvalidArgument("Unknown vehicle class '" + name + "'.");
181 }
182 
183 
184 int
185 getVehicleClassCompoundID(const std::string& name) {
186  int ret = SVC_IGNORING;
187  const std::vector<std::string> names = SumoVehicleClassStrings.getStrings();
188  for (std::vector<std::string>::const_iterator it = names.begin(); it != names.end(); it++) {
189  if (name.find(*it) != std::string::npos) {
190  ret = ret | (int) SumoVehicleClassStrings.get(*it);
191  }
192  }
193  return ret;
194 }
195 
196 
198 parseVehicleClasses(const std::string& allowedS) {
199  if (allowedS == "all") {
200  return SVCAll;
201  }
202  SVCPermissions result = 0;
203  StringTokenizer sta(allowedS, " ");
204  while (sta.hasNext()) {
205  const std::string s = sta.next();
206  if (!SumoVehicleClassStrings.hasString(s)) {
207  WRITE_ERROR("Unknown vehicle class '" + s + "' encountered. It will be ignored.");
208  } else {
209  const SUMOVehicleClass vc = getVehicleClassID(s);
210  const std::string& realName = SumoVehicleClassStrings.getString(vc);
211  if (realName != s) {
213  }
214  result |= vc;
215  }
216  }
217  return result;
218 }
219 
220 
221 bool
222 canParseVehicleClasses(const std::string& classes) {
223  if (classes == "all") {
224  return true;
225  }
226  StringTokenizer sta(classes, " ");
227  while (sta.hasNext()) {
228  if (!SumoVehicleClassStrings.hasString(sta.next())) {
229  return false;
230  }
231  }
232  return true;
233 }
234 
235 
236 extern SVCPermissions parseVehicleClasses(const std::string& allowedS, const std::string& disallowedS) {
237  if (allowedS.size() == 0 && disallowedS.size() == 0) {
238  return SVCAll;
239  } else if (allowedS.size() > 0 && disallowedS.size() > 0) {
240  WRITE_WARNING("SVCPermissions must be specified either via 'allow' or 'disallow'. Ignoring 'disallow'");
241  return parseVehicleClasses(allowedS);
242  } else if (allowedS.size() > 0) {
243  return parseVehicleClasses(allowedS);
244  } else {
245  return SVCAll & ~parseVehicleClasses(disallowedS);
246  }
247 }
248 
249 
251 parseVehicleClasses(const std::vector<std::string>& allowedS) {
252  SVCPermissions result = 0;
253  for (std::vector<std::string>::const_iterator i = allowedS.begin(); i != allowedS.end(); ++i) {
254  const SUMOVehicleClass vc = getVehicleClassID(*i);
255  const std::string& realName = SumoVehicleClassStrings.getString(vc);
256  if (realName != *i) {
257  WRITE_WARNING("The vehicle class '" + (*i) + "' is deprecated, use '" + realName + "' instead.");
258  }
259  result |= getVehicleClassID(*i);
260  }
261  return result;
262 }
263 
264 
265 void
267  if (permissions == SVCAll) {
268  return;
269  } else if (permissions == 0) {
270  into.writeAttr(SUMO_ATTR_DISALLOW, "all");
271  return;
272  } else {
273  int num_allowed = 0;
274  for (int mask = 1; mask <= SUMOVehicleClass_MAX; mask = mask << 1) {
275  if ((mask & permissions) == mask) {
276  ++num_allowed;
277  }
278  }
279  if (num_allowed <= (SumoVehicleClassStrings.size() - num_allowed) && num_allowed > 0) {
280  into.writeAttr(SUMO_ATTR_ALLOW, getVehicleClassNames(permissions));
281  } else {
283  }
284  }
285 }
286 
287 
288 void
290  if (preferred == SVCAll || preferred == 0) {
291  return;
292  } else {
294  }
295 }
296 
297 
299 getVehicleShapeID(const std::string& name) {
300  if (SumoVehicleShapeStrings.hasString(name)) {
301  return SumoVehicleShapeStrings.get(name);
302  } else {
303  throw InvalidArgument("Unknown vehicle shape '" + name + "'.");
304  }
305 }
306 
307 
308 bool canParseVehicleShape(const std::string& shape) {
309  return SumoVehicleShapeStrings.hasString(shape);
310 }
311 
312 
313 std::string
315  return SumoVehicleShapeStrings.getString(id);
316 }
317 
318 
319 bool isRailway(SVCPermissions permissions) {
320  return (permissions & (SVC_RAIL_ELECTRIC | SVC_RAIL | SVC_RAIL_URBAN | SVC_TRAM)) > 0 && (permissions & SVC_PASSENGER) == 0;
321 }
322 
323 
324 bool isWaterway(SVCPermissions permissions) {
325  return permissions == SVC_SHIP;
326 }
327 
328 
329 bool isForbidden(SVCPermissions permissions) {
330  return (permissions & SVCAll) == 0;
331 }
332 
333 
334 const std::string DEFAULT_VTYPE_ID("DEFAULT_VEHTYPE");
335 const std::string DEFAULT_PEDTYPE_ID("DEFAULT_PEDTYPE");
336 
337 const double DEFAULT_VEH_PROB(1.);
338 
339 const double DEFAULT_PEDESTRIAN_SPEED(5. / 3.6);
340 
341 const double DEFAULT_CONTAINER_TRANSHIP_SPEED(5. / 3.6);
342 
343 /****************************************************************************/
344 
SUMOVehicleClass getVehicleClassID(const std::string &name)
Returns the class id of the abstract class given by its name.
std::string getVehicleClassNames(SVCPermissions permissions, bool expand)
Returns the ids of the given classes, divided using a &#39; &#39;.
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:256
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)
const double DEFAULT_VEH_PROB(1.)
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
const std::string & getString(const T key) const
vehicle is a bicycle
render as a flexible city bus
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
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
all VClasses are allowed
vehicle is a HOV
std::vector< std::string > getStrings() const
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 double DEFAULT_PEDESTRIAN_SPEED(5./3.6)
bool canParseVehicleShape(const std::string &shape)
Checks whether the given string contains only known vehicle shape.
int size() const
const int SUMOVehicleClass_MAX
const double DEFAULT_CONTAINER_TRANSHIP_SPEED(5./3.6)
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
T get(const std::string &str) 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.
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
render as a police car
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
render as a fire brigade
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:206
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
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
bool hasString(const std::string &str) 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")
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
Definition: ToString.h:228
vehicles ignoring classes
const SVCPermissions SVC_UNSPECIFIED
permissions not specified
render as a trolley bus
is a user-defined type
is an electric vehicle