SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-sim.org/
13 // Copyright (C) 2001-2013 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  {"unknown", SVC_UNKNOWN},
53  {"private", SVC_PRIVATE},
54  {"public_transport", SVC_PUBLIC_TRANSPORT},
55  {"public_emergency", SVC_PUBLIC_EMERGENCY},
56  {"public_authority", SVC_PUBLIC_AUTHORITY},
57  {"public_army", SVC_PUBLIC_ARMY},
58  {"vip", SVC_VIP},
59  {"ignoring", SVC_IGNORING},
60  {"passenger", SVC_PASSENGER},
61  {"hov", SVC_HOV},
62  {"taxi", SVC_TAXI},
63  {"bus", SVC_BUS},
64  {"delivery", SVC_DELIVERY},
65  {"transport", SVC_TRANSPORT},
66  {"lightrail", SVC_LIGHTRAIL},
67  {"cityrail", SVC_CITYRAIL},
68  {"rail_slow", SVC_RAIL_SLOW},
69  {"rail_fast", SVC_RAIL_FAST},
70  {"motorcycle", SVC_MOTORCYCLE},
71  {"bicycle", SVC_BICYCLE},
72  {"pedestrian", SVC_PEDESTRIAN},
73  {"custom1", SVC_CUSTOM1},
74  {"custom2", SVC_CUSTOM2}
75 };
76 
78  sumoVehicleClassStringInitializer, SVC_CUSTOM2);
79 
80 
82  {"pedestrian", SVS_PEDESTRIAN},
83  {"bicycle", SVS_BICYCLE},
84  {"motorcycle", SVS_MOTORCYCLE},
85  {"passenger", SVS_PASSENGER},
86  {"passenger/sedan", SVS_PASSENGER_SEDAN},
87  {"passenger/hatchback", SVS_PASSENGER_HATCHBACK},
88  {"passenger/wagon", SVS_PASSENGER_WAGON},
89  {"passenger/van", SVS_PASSENGER_VAN},
90  {"delivery", SVS_DELIVERY},
91  {"transport", SVS_TRANSPORT},
92  {"transport/semitrailer", SVS_TRANSPORT_SEMITRAILER},
93  {"transport/trailer", SVS_TRANSPORT_1TRAILER},
94  {"bus", SVS_BUS},
95  {"bus/city", SVS_BUS_CITY},
96  {"bus/flexible", SVS_BUS_CITY_FLEXIBLE},
97  {"bus/overland", SVS_BUS_OVERLAND},
98  {"bus/trolley", SVS_BUS_TROLLEY},
99  {"rail", SVS_RAIL},
100  {"rail/light", SVS_RAIL_LIGHT},
101  {"rail/city", SVS_RAIL_CITY},
102  {"rail/slow", SVS_RAIL_SLOW},
103  {"rail/fast", SVS_RAIL_FAST},
104  {"rail/cargo", SVS_RAIL_CARGO},
105  {"evehicle", SVS_E_VEHICLE},
106  {"ant", SVS_ANT},
107  {"", SVS_UNKNOWN}
108 };
109 
110 
112  sumoVehicleShapeStringInitializer, SVS_UNKNOWN);
113 
114 
116  {"unknown", SVE_UNKNOWN},
117  // heavy duty vehicles; 3 clusters
118  {"HDV_3_1", SVE_HDV_3_1},
119  {"HDV_3_2", SVE_HDV_3_2},
120  {"HDV_3_3", SVE_HDV_3_3},
121  // heavy duty vehicles; 6 clusters
122  {"HDV_6_1", SVE_HDV_6_1},
123  {"HDV_6_2", SVE_HDV_6_2},
124  {"HDV_6_3", SVE_HDV_6_3},
125  {"HDV_6_4", SVE_HDV_6_4},
126  {"HDV_6_5", SVE_HDV_6_5},
127  {"HDV_6_6", SVE_HDV_6_6},
128  // heavy duty vehicles; 12 clusters
129  {"HDV_12_1", SVE_HDV_12_1},
130  {"HDV_12_2", SVE_HDV_12_2},
131  {"HDV_12_3", SVE_HDV_12_3},
132  {"HDV_12_4", SVE_HDV_12_4},
133  {"HDV_12_5", SVE_HDV_12_5},
134  {"HDV_12_6", SVE_HDV_12_6},
135  {"HDV_12_7", SVE_HDV_12_7},
136  {"HDV_12_8", SVE_HDV_12_8},
137  {"HDV_12_9", SVE_HDV_12_9},
138  {"HDV_12_10", SVE_HDV_12_10},
139  {"HDV_12_11", SVE_HDV_12_11},
140  {"HDV_12_12", SVE_HDV_12_12},
141  // passenger & light duty vehicles; 7 clusters
142  {"P_7_1", SVE_P_LDV_7_1},
143  {"P_7_2", SVE_P_LDV_7_2},
144  {"P_7_3", SVE_P_LDV_7_3},
145  {"P_7_4", SVE_P_LDV_7_4},
146  {"P_7_5", SVE_P_LDV_7_5},
147  {"P_7_6", SVE_P_LDV_7_6},
148  {"P_7_7", SVE_P_LDV_7_7},
149  // passenger & light duty vehicles; 14 clusters
150  {"P_14_1", SVE_P_LDV_14_1},
151  {"P_14_2", SVE_P_LDV_14_2},
152  {"P_14_3", SVE_P_LDV_14_3},
153  {"P_14_4", SVE_P_LDV_14_4},
154  {"P_14_5", SVE_P_LDV_14_5},
155  {"P_14_6", SVE_P_LDV_14_6},
156  {"P_14_7", SVE_P_LDV_14_7},
157  {"P_14_8", SVE_P_LDV_14_8},
158  {"P_14_9", SVE_P_LDV_14_9},
159  {"P_14_10", SVE_P_LDV_14_10},
160  {"P_14_11", SVE_P_LDV_14_11},
161  {"P_14_12", SVE_P_LDV_14_12},
162  {"P_14_13", SVE_P_LDV_14_13},
163  {"P_14_14", SVE_P_LDV_14_14},
164  // no emissions
165  {"zero", SVE_ZERO_EMISSIONS},
166  // heavy duty vehicles, no accel; 3 clusters
167  {"HDV_A0_3_1", SVE_HDV_A0_3_1},
168  {"HDV_A0_3_2", SVE_HDV_A0_3_2},
169  {"HDV_A0_3_3", SVE_HDV_A0_3_3},
170  // heavy duty vehicles, no accel; 6 clusters
171  {"HDV_A0_6_1", SVE_HDV_A0_6_1},
172  {"HDV_A0_6_2", SVE_HDV_A0_6_2},
173  {"HDV_A0_6_3", SVE_HDV_A0_6_3},
174  {"HDV_A0_6_4", SVE_HDV_A0_6_4},
175  {"HDV_A0_6_5", SVE_HDV_A0_6_5},
176  {"HDV_A0_6_6", SVE_HDV_A0_6_6},
177  // heavy duty vehicles, no accel; 12 clusters
178  {"HDV_A0_12_1", SVE_HDV_A0_12_1},
179  {"HDV_A0_12_2", SVE_HDV_A0_12_2},
180  {"HDV_A0_12_3", SVE_HDV_A0_12_3},
181  {"HDV_A0_12_4", SVE_HDV_A0_12_4},
182  {"HDV_A0_12_5", SVE_HDV_A0_12_5},
183  {"HDV_A0_12_6", SVE_HDV_A0_12_6},
184  {"HDV_A0_12_7", SVE_HDV_A0_12_7},
185  {"HDV_A0_12_8", SVE_HDV_A0_12_8},
186  {"HDV_A0_12_9", SVE_HDV_A0_12_9},
187  {"HDV_A0_12_10", SVE_HDV_A0_12_10},
188  {"HDV_A0_12_11", SVE_HDV_A0_12_11},
189  {"HDV_A0_12_12", SVE_HDV_A0_12_12},
190  // passenger & light duty vehicles, no accel; 7 clusters
191  {"P_A0_7_1", SVE_P_LDV_A0_7_1},
192  {"P_A0_7_2", SVE_P_LDV_A0_7_2},
193  {"P_A0_7_3", SVE_P_LDV_A0_7_3},
194  {"P_A0_7_4", SVE_P_LDV_A0_7_4},
195  {"P_A0_7_5", SVE_P_LDV_A0_7_5},
196  {"P_A0_7_6", SVE_P_LDV_A0_7_6},
197  {"P_A0_7_7", SVE_P_LDV_A0_7_7},
198  // passenger & light duty vehicles, no accel; 14 clusters
199  {"P_A0_14_1", SVE_P_LDV_A0_14_1},
200  {"P_A0_14_2", SVE_P_LDV_A0_14_2},
201  {"P_A0_14_3", SVE_P_LDV_A0_14_3},
202  {"P_A0_14_4", SVE_P_LDV_A0_14_4},
203  {"P_A0_14_5", SVE_P_LDV_A0_14_5},
204  {"P_A0_14_6", SVE_P_LDV_A0_14_6},
205  {"P_A0_14_7", SVE_P_LDV_A0_14_7},
206  {"P_A0_14_8", SVE_P_LDV_A0_14_8},
207  {"P_A0_14_9", SVE_P_LDV_A0_14_9},
208  {"P_A0_14_10", SVE_P_LDV_A0_14_10},
209  {"P_A0_14_11", SVE_P_LDV_A0_14_11},
210  {"P_A0_14_12", SVE_P_LDV_A0_14_12},
211  {"P_A0_14_13", SVE_P_LDV_A0_14_13},
212  {"P_A0_14_14", SVE_P_LDV_A0_14_14}
213 };
214 
216  SumoEmissionClassStringInitializer, SVE_P_LDV_A0_14_14);
217 
218 
219 // ===========================================================================
220 // additional constants
221 // ===========================================================================
222 
225 
226 // ===========================================================================
227 // method definitions
228 // ===========================================================================
229 // ------------ Conversion of SUMOVehicleClass
230 
231 std::string
233  std::string ret;
234  const std::vector<std::string> names = SumoVehicleClassStrings.getStrings();
235  for (std::vector<std::string>::const_iterator it = names.begin(); it != names.end(); it++) {
236  if ((id & SumoVehicleClassStrings.get(*it))) {
237  ret += ("|" + *it);
238  }
239  }
240  if (ret.length() > 0) {
241  return ret.substr(1);
242  } else {
243  return ret;
244  }
245 }
246 
247 
248 std::string
250  return joinToString(getAllowedVehicleClassNamesList(permissions), ' ');
251 }
252 
253 
254 std::vector<std::string>
257  const std::vector<std::string> classNames = SumoVehicleClassStrings.getStrings();
258  std::vector<std::string> result;
259  for (std::vector<std::string>::const_iterator it = classNames.begin(); it != classNames.end(); it++) {
260  const int svc = (int)SumoVehicleClassStrings.get(*it);
261  if ((svc & permissions) == svc && svc != SVC_UNKNOWN) {
262  result.push_back(*it);
263  }
264  }
265  return result;
266 }
267 
268 
269 std::pair<std::string, bool>
271  // shortcut the common cases
272  if (permissions == SVCFreeForAll) {
273  return std::pair<std::string, bool>("", false); // nothing disallowed
274  }
275  // figure out whether its shorter to write allow or disallow
276  // @note: this code assumes that enum values are assigned contiguous powers of 2 from 1 to SUMOVehicleClass_MAX
277  size_t num_allowed = 0;
278  for (int mask = 1; mask <= SUMOVehicleClass_MAX; mask = mask << 1) {
279  if ((mask & permissions) == mask) {
280  ++num_allowed;
281  }
282  }
283  if (num_allowed <= (SumoVehicleClassStrings.size() - num_allowed) && num_allowed > 0) {
284  return std::pair<std::string, bool>(getAllowedVehicleClassNames(permissions), true);
285  } else {
286  return std::pair<std::string, bool>(getAllowedVehicleClassNames(~permissions), false);
287  }
288 }
289 
290 
292 getVehicleClassID(const std::string& name) {
293  if (SumoVehicleClassStrings.hasString(name)) {
294  return SumoVehicleClassStrings.get(name);
295  }
296  throw ProcessError("Unknown vehicle class '" + name + "'.");
297 }
298 
299 
300 int
301 getVehicleClassCompoundID(const std::string& name) {
302  int ret = SVC_UNKNOWN;
303  const std::vector<std::string> names = SumoVehicleClassStrings.getStrings();
304  for (std::vector<std::string>::const_iterator it = names.begin(); it != names.end(); it++) {
305  if (name.find(*it) != std::string::npos) {
306  ret = ret | (int) SumoVehicleClassStrings.get(*it);
307  }
308  }
309  return ret;
310 }
311 
312 
314 parseVehicleClasses(const std::string& allowedS) {
315  SVCPermissions result = 0;
316  StringTokenizer sta(allowedS, " ");
317  while (sta.hasNext()) {
318  result |= getVehicleClassID(sta.next());
319  }
320  return result;
321 }
322 
323 
324 bool
325 canParseVehicleClasses(const std::string& classes) {
326  StringTokenizer sta(classes, " ");
327  while (sta.hasNext()) {
328  if (!SumoVehicleClassStrings.hasString(sta.next())) {
329  return false;
330  }
331  }
332  return true;
333 }
334 
335 
336 extern SVCPermissions parseVehicleClasses(const std::string& allowedS, const std::string& disallowedS) {
337  if (allowedS.size() == 0 && disallowedS.size() == 0) {
338  return SVCFreeForAll;
339  } else if (allowedS.size() > 0 && disallowedS.size() > 0) {
340  WRITE_WARNING("SVCPermissions must be specified either via 'allow' or 'disallow'. Ignoring 'disallow'");
341  return parseVehicleClasses(allowedS);
342  } else if (allowedS.size() > 0) {
343  return parseVehicleClasses(allowedS);
344  } else {
345  return ~parseVehicleClasses(disallowedS);
346  }
347 }
348 
349 
351 parseVehicleClasses(const std::vector<std::string>& allowedS) {
352  SVCPermissions result = 0;
353  for (std::vector<std::string>::const_iterator i = allowedS.begin(); i != allowedS.end(); ++i) {
354  result |= getVehicleClassID(*i);
355  }
356  return result;
357 }
358 
359 
361 getVehicleShapeID(const std::string& name) {
362  if (SumoVehicleShapeStrings.hasString(name)) {
363  return SumoVehicleShapeStrings.get(name);
364  } else {
365  throw ProcessError("Unknown vehicle shape '" + name + "'.");
366  }
367 }
368 
369 
370 std::string
372  return SumoVehicleShapeStrings.getString(id);
373 }
374 
375 
376 bool isRailway(SVCPermissions permissions) {
377  const int anyRail = SVC_RAIL_FAST + SVC_RAIL_SLOW + SVC_CITYRAIL + SVC_LIGHTRAIL;
378  return (permissions & anyRail) > 0 && (permissions & SVC_PASSENGER) == 0;
379 }
380 
381 // ------------ Conversion of SUMOEmissionClass
383 getVehicleEmissionTypeID(const std::string& name) {
384  if (SumoEmissionClassStrings.hasString(name)) {
385  return SumoEmissionClassStrings.get(name);
386  } else {
387  throw ProcessError("Unknown emission type '" + name + "'.");
388  }
389 }
390 
391 std::string
393  return SumoEmissionClassStrings.getString(id);
394 }
395 
396 
397 const std::string DEFAULT_VTYPE_ID("DEFAULT_VEHTYPE");
398 const SUMOReal DEFAULT_VEH_MAXSPEED(70.0);
399 const SUMOReal DEFAULT_VEH_ACCEL(2.6);
400 const SUMOReal DEFAULT_VEH_DECEL(4.5);
401 const SUMOReal DEFAULT_VEH_SIGMA(0.5);
402 const SUMOReal DEFAULT_VEH_LENGTH(5.);
403 const SUMOReal DEFAULT_VEH_MINGAP(2.5);
404 const SUMOReal DEFAULT_VEH_TAU(1.);
406 const SUMOReal DEFAULT_VEH_PROB(1.);
409 const SUMOReal DEFAULT_VEH_WIDTH(2.);
410 const SUMOReal DEFAULT_VEH_HEIGHT(1.5);
412 const std::string DEFAULT_VEH_LANE_CHANGE_MODEL("dkrajzew2008");
414 const SUMOReal DEFAULT_VEH_TMP1(1.);
415 const SUMOReal DEFAULT_VEH_TMP2(1.);
416 const SUMOReal DEFAULT_VEH_TMP3(1.);
417 const SUMOReal DEFAULT_VEH_TMP4(1.);
418 const SUMOReal DEFAULT_VEH_TMP5(1.);
419 
420 const SUMOReal DEFAULT_PERSON_SPEED(5. / 3.6);
421 
422 /****************************************************************************/
423 
SUMOVehicleClass getVehicleClassID(const std::string &name)
Returns the class id of the abstract class given by its name.
SUMOEmissionClass getVehicleEmissionTypeID(const std::string &name)
Returns the class id of the emission class given by its name.
std::string getVehicleClassCompoundName(int id)
render as a light rail
const SUMOReal DEFAULT_VEH_TMP5
vehicle is a motorcycle
SumoXMLTag
Numbers representing SUMO-XML - element names.
render as a rail
std::string getVehicleEmissionTypeName(SUMOEmissionClass id)
Returns the class name of the emission class given by its id.
vehicle is a city rail
is a pedestrian
std::string next()
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types...
render as a slow (passenger) train
render as a motorcycle
vehicle is a large transport vehicle
vehicle is a bicycle
int SVCPermissions
vehicle is a small delivery vehicle
render as a city bus
std::string getAllowedVehicleClassNames(SVCPermissions permissions)
Returns the ids of the given classes, divided using a &#39; &#39;.
const SUMOVehicleShape DEFAULT_VEH_SHAPE
render as a fast (passenger) train
const SUMOReal DEFAULT_VEH_PROB
render as a delivery vehicle
const SumoXMLTag DEFAULT_VEH_FOLLOW_MODEL
StringBijection< SUMOVehicleClass >::Entry sumoVehicleClassStringInitializer[]
StringBijection< SUMOVehicleShape >::Entry sumoVehicleShapeStringInitializer[]
const SUMOReal DEFAULT_VEH_LENGTH
render as a sedan passenger vehicle (&quot;Stufenheck&quot;)
const SUMOReal DEFAULT_VEH_SIGMA
bool isRailway(SVCPermissions permissions)
Returns whether an edge with the given permission is a railway edge.
vehicle is a HOV
const std::string DEFAULT_VTYPE_ID
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:196
std::string getVehicleShapeName(SUMOVehicleShape id)
Returns the class name of the shape class given by its id.
render as a semi-trailer transport vehicle (&quot;Sattelschlepper&quot;)
is a user-defined type
SUMOEmissionClass
Definition of vehicle emission classes.
const SUMOReal DEFAULT_PERSON_SPEED
const int SUMOVehicleClass_MAX
#define max(a, b)
Definition: polyfonts.c:61
StringBijection< SUMOVehicleClass > SumoVehicleClassStrings(sumoVehicleClassStringInitializer, SVC_CUSTOM2)
vehicle is a light rail
StringBijection< SUMOVehicleShape > SumoVehicleShapeStrings(sumoVehicleShapeStringInitializer, SVS_UNKNOWN)
render as a hatchback passenger vehicle (&quot;Fliessheck&quot;)
StringBijection< SUMOEmissionClass > SumoEmissionClassStrings(SumoEmissionClassStringInitializer, SVE_P_LDV_A0_14_14)
StringBijection< SUMOEmissionClass >::Entry SumoEmissionClassStringInitializer[]
render as a bus
private vehicles
not defined
render as a bicycle
std::pair< std::string, bool > getPermissionEncoding(SVCPermissions permissions)
returns the shorter encoding of the given permissions (selects automatically wether to use allow or d...
army vehicles
const SUMOReal DEFAULT_VEH_TAU
const SUMOReal DEFAULT_VEH_MAXSPEED
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. ...
const SUMOReal DEFAULT_VEH_TMP3
render as a van
render as a passenger vehicle
const SUMOReal DEFAULT_VEH_SPEEDDEV
const SVCPermissions SVCFreeForAll
vehicle is a passenger car (a &quot;normal&quot; car)
bool canParseVehicleClasses(const std::string &classes)
Checks whether the given string contains only known vehicle classes.
render as a cargo train
render as a flexible city bus
authorities vehicles
vehicle is a taxi
const SUMOReal DEFAULT_VEH_MINGAP
vehicle is a bus
render as a giant ant
render as a pedestrian
public emergency vehicles
SUMOVehicleShape
Definition of vehicle classes to differ between different appearences.
vip vehicles
vehicle is a slow moving transport rail
const SUMOReal DEFAULT_VEH_WIDTH
render as a transport vehicle with one trailer
const SUMOReal DEFAULT_VEH_TMP2
const SUMOReal DEFAULT_VEH_HEIGHT
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:136
render as a (futuristic) e-vehicle
const SUMOReal DEFAULT_VEH_SPEEDFACTOR
const SUMOReal DEFAULT_VEH_ACCEL
std::vector< std::string > getAllowedVehicleClassNamesList(SVCPermissions permissions)
Returns the ids of the given classes, divided using a &#39; &#39;.
SUMOVehicleShape getVehicleShapeID(const std::string &name)
Returns the class id of the shape class given by its name.
const SUMOReal DEFAULT_VEH_TMP1
#define SUMOReal
Definition: config.h:221
public transport vehicles
const SUMOReal DEFAULT_VEH_TMP4
const SUMOVehicleClass DEFAULT_VEH_CLASS
render as a wagon passenger vehicle (&quot;Combi&quot;)
render as a overland bus
const SUMOReal DEFAULT_VEH_DECEL
vehicle is a fast moving rail
const std::string DEFAULT_VEH_LANE_CHANGE_MODEL
vehicles ignoring classes
render as a city rail
render as a trolley bus
render as a transport vehicle
is a user-defined type