SUMO - Simulation of Urban MObility
SUMOVehicleClass.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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
20 // Definitions of SUMO vehicle classes and helper functions
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <string>
34 #include <map>
35 #include "SUMOVehicleClass.h"
37 #include <utils/common/ToString.h>
41 
42 
43 // ===========================================================================
44 // static members
45 // ===========================================================================
46 
48  {"ignoring", SVC_IGNORING},
49  {"private", SVC_PRIVATE},
50  {"public_emergency", SVC_EMERGENCY}, // !!! deprecated
51  {"emergency", SVC_EMERGENCY},
52  {"public_authority", SVC_AUTHORITY}, // !!! deprecated
53  {"authority", SVC_AUTHORITY},
54  {"public_army", SVC_ARMY}, // !!! deprecated
55  {"army", SVC_ARMY},
56  {"vip", SVC_VIP},
57  {"passenger", SVC_PASSENGER},
58  {"hov", SVC_HOV},
59  {"taxi", SVC_TAXI},
60  {"public_transport", SVC_BUS}, // !!! deprecated
61  {"bus", SVC_BUS},
62  {"coach", SVC_COACH},
63  {"delivery", SVC_DELIVERY},
64  {"transport", SVC_TRUCK},
65  {"truck", SVC_TRUCK},
66  {"trailer", SVC_TRAILER},
67  {"lightrail", SVC_TRAM}, // !!! deprecated
68  {"tram", SVC_TRAM},
69  {"cityrail", SVC_RAIL_URBAN}, // !!! deprecated
70  {"rail_urban", SVC_RAIL_URBAN},
71  {"rail_slow", SVC_RAIL}, // !!! deprecated
72  {"rail", SVC_RAIL},
73  {"rail_fast", SVC_RAIL_ELECTRIC}, // !!! deprecated
74  {"rail_electric", SVC_RAIL_ELECTRIC},
75  {"motorcycle", SVC_MOTORCYCLE},
76  {"moped", SVC_MOPED},
77  {"bicycle", SVC_BICYCLE},
78  {"pedestrian", SVC_PEDESTRIAN},
79  {"evehicle", SVC_E_VEHICLE},
80  {"ship", SVC_SHIP},
81  {"custom1", SVC_CUSTOM1},
82  {"custom2", SVC_CUSTOM2}
83 };
84 
86  sumoVehicleClassStringInitializer, SVC_CUSTOM2, false);
87 
88 
89 std::set<std::string> deprecatedVehicleClassesSeen;
90 
91 
93  {"pedestrian", SVS_PEDESTRIAN},
94  {"bicycle", SVS_BICYCLE},
95  {"moped", SVS_MOPED},
96  {"motorcycle", SVS_MOTORCYCLE},
97  {"passenger", SVS_PASSENGER},
98  {"passenger/sedan", SVS_PASSENGER_SEDAN},
99  {"passenger/hatchback", SVS_PASSENGER_HATCHBACK},
100  {"passenger/wagon", SVS_PASSENGER_WAGON},
101  {"passenger/van", SVS_PASSENGER_VAN},
102  {"delivery", SVS_DELIVERY},
103  {"transport", SVS_TRUCK}, // !!! deprecated
104  {"truck", SVS_TRUCK},
105  {"transport/semitrailer", SVS_TRUCK_SEMITRAILER}, // !!! deprecated
106  {"truck/semitrailer", SVS_TRUCK_SEMITRAILER},
107  {"transport/trailer", SVS_TRUCK_1TRAILER}, // !!! deprecated
108  {"truck/trailer", SVS_TRUCK_1TRAILER},
109  {"bus/city", SVS_BUS}, // !!! deprecated
110  {"bus", SVS_BUS},
111  {"bus/overland", SVS_BUS_COACH}, // !!! deprecated
112  {"bus/coach", SVS_BUS_COACH},
113  {"bus/flexible", SVS_BUS_FLEXIBLE},
114  {"bus/trolley", SVS_BUS_TROLLEY},
115  {"rail/slow", SVS_RAIL}, // !!! deprecated
116  {"rail/fast", SVS_RAIL}, // !!! deprecated
117  {"rail", SVS_RAIL},
118  {"rail/light", SVS_RAIL_CAR}, // !!! deprecated
119  {"rail/city", SVS_RAIL_CAR}, // !!! deprecated
120  {"rail/railcar", SVS_RAIL_CAR},
121  {"rail/cargo", SVS_RAIL_CARGO},
122  {"evehicle", SVS_E_VEHICLE},
123  {"ant", SVS_ANT},
124  {"ship", SVS_SHIP},
125  {"emergency", SVS_EMERGENCY},
126  {"firebrigade", SVS_FIREBRIGADE},
127  {"police", SVS_POLICE},
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
151 getVehicleClassNames(SVCPermissions permissions, bool expand) {
152  if (permissions == SVCAll && !expand) {
153  return "all";
154  }
155  return joinToString(getVehicleClassNamesList(permissions), ' ');
156 }
157 
158 
159 std::vector<std::string>
162  const std::vector<std::string> classNames = SumoVehicleClassStrings.getStrings();
163  std::vector<std::string> result;
164  for (std::vector<std::string>::const_iterator it = classNames.begin(); it != classNames.end(); it++) {
165  const int svc = (int)SumoVehicleClassStrings.get(*it);
166  if ((svc & permissions) == svc && svc != SVC_IGNORING) {
167  result.push_back(*it);
168  }
169  }
170  return result;
171 }
172 
173 
175 getVehicleClassID(const std::string& name) {
176  if (SumoVehicleClassStrings.hasString(name)) {
177  return SumoVehicleClassStrings.get(name);
178  }
179  throw InvalidArgument("Unknown vehicle class '" + name + "'.");
180 }
181 
182 
183 int
184 getVehicleClassCompoundID(const std::string& name) {
185  int ret = SVC_IGNORING;
186  const std::vector<std::string> names = SumoVehicleClassStrings.getStrings();
187  for (std::vector<std::string>::const_iterator it = names.begin(); it != names.end(); it++) {
188  if (name.find(*it) != std::string::npos) {
189  ret = ret | (int) SumoVehicleClassStrings.get(*it);
190  }
191  }
192  return ret;
193 }
194 
195 
197 parseVehicleClasses(const std::string& allowedS) {
198  if (allowedS == "all") {
199  return SVCAll;
200  }
201  SVCPermissions result = 0;
202  StringTokenizer sta(allowedS, " ");
203  while (sta.hasNext()) {
204  const std::string s = sta.next();
205  if (!SumoVehicleClassStrings.hasString(s)) {
206  WRITE_ERROR("Unknown vehicle class '" + s + "' encountered. It will be ignored.");
207  } else {
208  const SUMOVehicleClass vc = getVehicleClassID(s);
209  const std::string& realName = SumoVehicleClassStrings.getString(vc);
210  if (realName != s) {
212  }
213  result |= vc;
214  }
215  }
216  return result;
217 }
218 
219 
220 bool
221 canParseVehicleClasses(const std::string& classes) {
222  if (classes == "all") {
223  return true;
224  }
225  StringTokenizer sta(classes, " ");
226  while (sta.hasNext()) {
227  if (!SumoVehicleClassStrings.hasString(sta.next())) {
228  return false;
229  }
230  }
231  return true;
232 }
233 
234 
235 extern SVCPermissions parseVehicleClasses(const std::string& allowedS, const std::string& disallowedS) {
236  if (allowedS.size() == 0 && disallowedS.size() == 0) {
237  return SVCAll;
238  } else if (allowedS.size() > 0 && disallowedS.size() > 0) {
239  WRITE_WARNING("SVCPermissions must be specified either via 'allow' or 'disallow'. Ignoring 'disallow'");
240  return parseVehicleClasses(allowedS);
241  } else if (allowedS.size() > 0) {
242  return parseVehicleClasses(allowedS);
243  } else {
244  return invertPermissions(parseVehicleClasses(disallowedS));
245  }
246 }
247 
248 extern SVCPermissions
250  return SVCAll & ~permissions;
251 }
252 
254 parseVehicleClasses(const std::vector<std::string>& allowedS) {
255  SVCPermissions result = 0;
256  for (std::vector<std::string>::const_iterator i = allowedS.begin(); i != allowedS.end(); ++i) {
257  const SUMOVehicleClass vc = getVehicleClassID(*i);
258  const std::string& realName = SumoVehicleClassStrings.getString(vc);
259  if (realName != *i) {
260  WRITE_WARNING("The vehicle class '" + (*i) + "' is deprecated, use '" + realName + "' instead.");
261  }
262  result |= getVehicleClassID(*i);
263  }
264  return result;
265 }
266 
267 
268 void
270  if (permissions == SVCAll) {
271  return;
272  } else if (permissions == 0) {
273  into.writeAttr(SUMO_ATTR_DISALLOW, "all");
274  return;
275  } else {
276  int num_allowed = 0;
277  for (int mask = 1; mask <= SUMOVehicleClass_MAX; mask = mask << 1) {
278  if ((mask & permissions) == mask) {
279  ++num_allowed;
280  }
281  }
282  if (num_allowed <= (SumoVehicleClassStrings.size() - num_allowed) && num_allowed > 0) {
283  into.writeAttr(SUMO_ATTR_ALLOW, getVehicleClassNames(permissions));
284  } else {
286  }
287  }
288 }
289 
290 
291 void
293  if (preferred == SVCAll || preferred == 0) {
294  return;
295  } else {
297  }
298 }
299 
300 
302 getVehicleShapeID(const std::string& name) {
303  if (SumoVehicleShapeStrings.hasString(name)) {
304  return SumoVehicleShapeStrings.get(name);
305  } else {
306  throw InvalidArgument("Unknown vehicle shape '" + name + "'.");
307  }
308 }
309 
310 
311 bool canParseVehicleShape(const std::string& shape) {
312  return SumoVehicleShapeStrings.hasString(shape);
313 }
314 
315 
316 std::string
318  return SumoVehicleShapeStrings.getString(id);
319 }
320 
321 
322 bool isRailway(SVCPermissions permissions) {
323  return (permissions & (SVC_RAIL_ELECTRIC | SVC_RAIL | SVC_RAIL_URBAN | SVC_TRAM)) > 0 && (permissions & SVC_PASSENGER) == 0;
324 }
325 
326 
327 bool isWaterway(SVCPermissions permissions) {
328  return permissions == SVC_SHIP;
329 }
330 
331 
332 bool isForbidden(SVCPermissions permissions) {
333  return (permissions & SVCAll) == 0;
334 }
335 
336 
337 const std::string DEFAULT_VTYPE_ID("DEFAULT_VEHTYPE");
338 const std::string DEFAULT_PEDTYPE_ID("DEFAULT_PEDTYPE");
339 
340 const double DEFAULT_VEH_PROB(1.);
341 
342 const double DEFAULT_PEDESTRIAN_SPEED(5. / 3.6);
343 
344 const double DEFAULT_CONTAINER_TRANSHIP_SPEED(5. / 3.6);
345 
346 /****************************************************************************/
347 
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:260
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:199
authorities vehicles
SVCPermissions invertPermissions(SVCPermissions permissions)
negate the given permissions and ensure that only relevant bits are set
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:205
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:70
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:236
vehicles ignoring classes
const SVCPermissions SVC_UNSPECIFIED
permissions not specified
render as a trolley bus
is a user-defined type
is an electric vehicle