SUMO - Simulation of Urban MObility
VehicleType.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2017-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 /****************************************************************************/
17 // C++ TraCI client API implementation
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #ifdef _MSC_VER
25 #include <windows_config.h>
26 #else
27 #include <config.h>
28 #endif
29 
30 #include <microsim/MSNet.h>
34 #include "VehicleType.h"
35 #include "Helper.h"
36 
37 
38 // ===========================================================================
39 // method definitions
40 // ===========================================================================
41 namespace libsumo {
42 std::vector<std::string> VehicleType::getIDList() {
43  std::vector<std::string> ids;
45  return ids;
46 }
47 
48 
49 double VehicleType::getLength(const std::string& typeID) {
50  MSVehicleType* v = getVType(typeID);
51  return v->getLength();
52 }
53 
54 
55 double VehicleType::getMaxSpeed(const std::string& typeID) {
56  MSVehicleType* v = getVType(typeID);
57  return v->getMaxSpeed();
58 }
59 
60 
61 double VehicleType::getActionStepLength(const std::string& typeID) {
62  MSVehicleType* v = getVType(typeID);
63  return v->getActionStepLengthSecs();
64 }
65 
66 
67 double VehicleType::getSpeedFactor(const std::string& typeID) {
68  MSVehicleType* v = getVType(typeID);
69  return v->getSpeedFactor().getParameter()[0];
70 }
71 
72 
73 double VehicleType::getSpeedDeviation(const std::string& typeID) {
74  MSVehicleType* v = getVType(typeID);
75  return v->getSpeedFactor().getParameter()[1];
76 }
77 
78 
79 double VehicleType::getAccel(const std::string& typeID) {
80  MSVehicleType* v = getVType(typeID);
81  return v->getCarFollowModel().getMaxAccel();
82 }
83 
84 
85 double VehicleType::getDecel(const std::string& typeID) {
86  MSVehicleType* v = getVType(typeID);
87  return v->getCarFollowModel().getMaxDecel();
88 }
89 
90 
91 double VehicleType::getEmergencyDecel(const std::string& typeID) {
92  MSVehicleType* v = getVType(typeID);
94 }
95 
96 
97 double VehicleType::getApparentDecel(const std::string& typeID) {
98  MSVehicleType* v = getVType(typeID);
99  return v->getCarFollowModel().getApparentDecel();
100 }
101 
102 
103 double VehicleType::getImperfection(const std::string& typeID) {
104  MSVehicleType* v = getVType(typeID);
105  return v->getCarFollowModel().getImperfection();
106 }
107 
108 
109 double VehicleType::getTau(const std::string& typeID) {
110  MSVehicleType* v = getVType(typeID);
111  return v->getCarFollowModel().getHeadwayTime();
112 }
113 
114 
115 std::string VehicleType::getVehicleClass(const std::string& typeID) {
116  MSVehicleType* v = getVType(typeID);
117  return toString(v->getVehicleClass());
118 }
119 
120 
121 std::string VehicleType::getEmissionClass(const std::string& typeID) {
122  MSVehicleType* v = getVType(typeID);
124 }
125 
126 
127 std::string VehicleType::getShapeClass(const std::string& typeID) {
128  MSVehicleType* v = getVType(typeID);
129  return getVehicleShapeName(v->getGuiShape());
130 }
131 
132 
133 double VehicleType::getMinGap(const std::string& typeID) {
134  MSVehicleType* v = getVType(typeID);
135  return v->getMinGap();
136 }
137 
138 
139 double VehicleType::getWidth(const std::string& typeID) {
140  MSVehicleType* v = getVType(typeID);
141  return v->getWidth();
142 }
143 
144 
145 double VehicleType::getHeight(const std::string& typeID) {
146  MSVehicleType* v = getVType(typeID);
147  return v->getHeight();
148 }
149 
150 
151 TraCIColor VehicleType::getColor(const std::string& typeID) {
152  MSVehicleType* v = getVType(typeID);
153  return Helper::makeTraCIColor(v->getColor());
154 }
155 
156 
157 double VehicleType::getMinGapLat(const std::string& typeID) {
158  MSVehicleType* v = getVType(typeID);
159  return v->getMinGapLat();
160 }
161 
162 
163 double VehicleType::getMaxSpeedLat(const std::string& typeID) {
164  MSVehicleType* v = getVType(typeID);
165  return v->getMaxSpeedLat();
166 }
167 
168 
169 std::string VehicleType::getLateralAlignment(const std::string& typeID) {
170  MSVehicleType* v = getVType(typeID);
172 }
173 
174 
175 std::string
176 VehicleType::getParameter(const std::string& typeID, const std::string& key) {
177  MSVehicleType* v = getVType(typeID);
178  return v->getParameter().getParameter(key, "");
179 }
180 
181 
182 void VehicleType::setLength(const std::string& typeID, double length) {
183  MSVehicleType* v = getVType(typeID);
184  v->setLength(length);
185 }
186 
187 
188 void VehicleType::setMaxSpeed(const std::string& typeID, double speed) {
189  MSVehicleType* v = getVType(typeID);
190  v->setMaxSpeed(speed);
191 }
192 
193 
194 void VehicleType::setActionStepLength(const std::string& typeID, double actionStepLength, bool resetActionOffset) {
195  MSVehicleType* v = getVType(typeID);
196  v->setActionStepLength(SUMOVehicleParserHelper::processActionStepLength(actionStepLength), resetActionOffset);
197 }
198 
199 
200 void VehicleType::setVehicleClass(const std::string& typeID, const std::string& clazz) {
201  MSVehicleType* v = getVType(typeID);
202  v->setVClass(getVehicleClassID(clazz));
203 }
204 
205 
206 void VehicleType::setSpeedFactor(const std::string& typeID, double factor) {
207  MSVehicleType* v = getVType(typeID);
208  v->setSpeedFactor(factor);
209 }
210 
211 
212 void VehicleType::setSpeedDeviation(const std::string& typeID, double deviation) {
213  MSVehicleType* v = getVType(typeID);
214  v->setSpeedDeviation(deviation);
215 }
216 
217 
218 void VehicleType::setEmissionClass(const std::string& typeID, const std::string& clazz) {
219  MSVehicleType* v = getVType(typeID);
221 }
222 
223 
224 void VehicleType::setShapeClass(const std::string& typeID, const std::string& shapeClass) {
225  MSVehicleType* v = getVType(typeID);
226  v->setShape(getVehicleShapeID(shapeClass));
227 }
228 
229 
230 void VehicleType::setWidth(const std::string& typeID, double width) {
231  MSVehicleType* v = getVType(typeID);
232  v->setWidth(width);
233 }
234 
235 
236 void VehicleType::setHeight(const std::string& typeID, double height) {
237  MSVehicleType* v = getVType(typeID);
238  v->setHeight(height);
239 }
240 
241 
242 void VehicleType::setMinGap(const std::string& typeID, double minGap) {
243  MSVehicleType* v = getVType(typeID);
244  v->setMinGap(minGap);
245 }
246 
247 
248 void VehicleType::setAccel(const std::string& typeID, double accel) {
249  MSVehicleType* v = getVType(typeID);
250  v->getCarFollowModel().setMaxAccel(accel);
251 }
252 
253 
254 void VehicleType::setDecel(const std::string& typeID, double decel) {
255  MSVehicleType* v = getVType(typeID);
256  v->getCarFollowModel().setMaxDecel(decel);
257 }
258 
259 
260 void VehicleType::setEmergencyDecel(const std::string& typeID, double decel) {
261  MSVehicleType* v = getVType(typeID);
263 }
264 
265 
266 void VehicleType::setApparentDecel(const std::string& typeID, double decel) {
267  MSVehicleType* v = getVType(typeID);
269 }
270 
271 
272 void VehicleType::setImperfection(const std::string& typeID, double imperfection) {
273  MSVehicleType* v = getVType(typeID);
274  v->getCarFollowModel().setImperfection(imperfection);
275 }
276 
277 
278 void VehicleType::setTau(const std::string& typeID, double tau) {
279  MSVehicleType* v = getVType(typeID);
281 }
282 
283 
284 void VehicleType::setColor(const std::string& typeID, const TraCIColor& c) {
285  MSVehicleType* v = getVType(typeID);
287 
288 }
289 
290 
291 void VehicleType::setMinGapLat(const std::string& typeID, double minGapLat) {
292  MSVehicleType* v = getVType(typeID);
293  v->setMinGapLat(minGapLat);
294 }
295 
296 
297 void VehicleType::setMaxSpeedLat(const std::string& typeID, double speed) {
298  MSVehicleType* v = getVType(typeID);
299  v->setMaxSpeedLat(speed);
300 }
301 
302 
303 void VehicleType::setLateralAlignment(const std::string& typeID, const std::string& latAlignment) {
304  MSVehicleType* v = getVType(typeID);
306 }
307 
308 
309 void VehicleType::copy(const std::string& origTypeID, const std::string& newTypeID) {
310  getVType(origTypeID)->duplicateType(newTypeID, true);
311 }
312 
313 
314 void VehicleType::setParameter(const std::string& typeID, const std::string& name, const std::string& value) {
315  MSVehicleType* v = getVType(typeID);
316  ((SUMOVTypeParameter&)v->getParameter()).setParameter(name, value);
317 }
318 
319 
322  if (t == 0) {
323  throw TraCIException("Vehicle type '" + id + "' is not known");
324  }
325  return t;
326 }
327 }
328 
329 
330 /****************************************************************************/
static double getImperfection(const std::string &typeID)
SUMOVehicleClass getVehicleClassID(const std::string &name)
Returns the class id of the abstract class given by its name.
static void setSpeedFactor(const std::string &typeID, double factor)
static double getHeight(const std::string &typeID)
static double getDecel(const std::string &typeID)
Definition: VehicleType.cpp:85
void setMinGap(const double &minGap)
Set a new value for this type&#39;s minimum gap.
double getMinGap() const
Get the free space in front of vehicles of this class.
static double getEmergencyDecel(const std::string &typeID)
Definition: VehicleType.cpp:91
SUMOVehicleClass getVehicleClass() const
Get this vehicle type&#39;s vehicle class.
static double getSpeedDeviation(const std::string &typeID)
Definition: VehicleType.cpp:73
static double getSpeedFactor(const std::string &typeID)
Definition: VehicleType.cpp:67
void setShape(SUMOVehicleShape shape)
Set a new value for this type&#39;s shape.
Structure representing possible vehicle parameter.
std::vector< double > & getParameter()
Returns the parameters of this distribution.
static double getMaxSpeed(const std::string &typeID)
Definition: VehicleType.cpp:55
static void setSpeedDeviation(const std::string &typeID, double deviation)
static void setLength(const std::string &typeID, double length)
static std::string getParameter(const std::string &typeID, const std::string &key)
static SUMOTime processActionStepLength(double given)
Checks and converts given value for the action step length from seconds to miliseconds assuring it be...
virtual double getHeadwayTime() const
Get the driver&#39;s desired headway [s].
Definition: MSCFModel.h:246
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:167
double getMaxSpeed() const
Get vehicle&#39;s maximum speed [m/s].
static double getApparentDecel(const std::string &typeID)
Definition: VehicleType.cpp:97
void setLength(const double &length)
Set a new value for this type&#39;s length.
LateralAlignment getPreferredLateralAlignment() const
Get vehicle&#39;s preferred lateral alignment.
void insertVTypeIDs(std::vector< std::string > &into) const
Inserts ids of all known vehicle types and vehicle type distributions to the given vector...
void setMaxSpeed(const double &maxSpeed)
Set a new value for this type&#39;s maximum speed.
static void setMaxSpeed(const std::string &typeID, double speed)
virtual void setApparentDecel(double decel)
Sets a new value for the apparent deceleration [m/s^2].
Definition: MSCFModel.h:467
The car-following model and parameter.
Definition: MSVehicleType.h:72
double getEmergencyDecel() const
Get the vehicle type&#39;s maximal phisically possible deceleration [m/s^2].
Definition: MSCFModel.h:219
const MSCFModel & getCarFollowModel() const
Returns the vehicle type&#39;s car following model definition (const version)
std::string getVehicleShapeName(SUMOVehicleShape id)
Returns the class name of the shape class given by its id.
static double getLength(const std::string &typeID)
Definition: VehicleType.cpp:49
void setMinGapLat(const double &minGapLat)
Set a new value for this type&#39;s minimum lataral gap.
static void setApparentDecel(const std::string &typeID, double decel)
static void setTau(const std::string &typeID, double tau)
static MSVehicleType * getVType(std::string id)
const SUMOVTypeParameter & getParameter() const
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:55
static std::string getVehicleClass(const std::string &typeID)
static void setWidth(const std::string &typeID, double width)
double getHeight() const
Get the height which vehicles of this class shall have when being drawn.
virtual double getImperfection() const
Get the driver&#39;s imperfection.
Definition: MSCFModel.h:238
double getMaxDecel() const
Get the vehicle type&#39;s maximal comfortable deceleration [m/s^2].
Definition: MSCFModel.h:211
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:306
virtual void setHeadwayTime(double headwayTime)
Sets a new value for desired headway [s].
Definition: MSCFModel.h:483
void setHeight(const double &height)
Set a new value for this type&#39;s height.
static void setMinGapLat(const std::string &typeID, double minGapLat)
static void setShapeClass(const std::string &typeID, const std::string &shapeClass)
static void copy(const std::string &origTypeID, const std::string &newTypeID)
static TraCIColor makeTraCIColor(const RGBColor &color)
Definition: Helper.cpp:130
static double getMaxSpeedLat(const std::string &typeID)
void setEmissionClass(SUMOEmissionClass eclass)
Set a new value for this type&#39;s emission class.
static void setActionStepLength(const std::string &typeID, double actionStepLength, bool resetActionOffset)
static std::string getName(const SUMOEmissionClass c)
Checks whether the string describes a known vehicle class.
const std::string getParameter(const std::string &key, const std::string &defaultValue="") const
Returns the value for a given key.
static double getWidth(const std::string &typeID)
double getWidth() const
Get the width which vehicles of this class shall have when being drawn.
double getActionStepLengthSecs() const
Returns this type&#39;s default action step length in seconds.
void setSpeedDeviation(const double &dev)
Set a new value for this type&#39;s speed deviation.
void setSpeedFactor(const double &factor)
Set a new value for this type&#39;s speed factor.
Definition: Edge.cpp:31
SUMOVehicleShape getGuiShape() const
Get this vehicle type&#39;s shape.
void setActionStepLength(const SUMOTime actionStepLength, bool resetActionOffset)
Set a new value for this type&#39;s action step length.
static void setDecel(const std::string &typeID, double decel)
MSVehicleType * getVType(const std::string &id=DEFAULT_VTYPE_ID, std::mt19937 *rng=0)
Returns the named vehicle type or a sample from the named distribution.
static void setImperfection(const std::string &typeID, double imperfection)
double getMinGapLat() const
Get the minimum lateral gap that vehicles of this type maintain.
static std::string getEmissionClass(const std::string &typeID)
double getLength() const
Get vehicle&#39;s length [m].
static StringBijection< LateralAlignment > LateralAlignments
lateral alignments
const Distribution_Parameterized & getSpeedFactor() const
Returns this type&#39;s speed factor.
double getMaxAccel() const
Get the vehicle type&#39;s maximum acceleration [m/s^2].
Definition: MSCFModel.h:203
static void setParameter(const std::string &id, const std::string &name, const std::string &value)
static void setEmergencyDecel(const std::string &typeID, double decel)
static void setLateralAlignment(const std::string &typeID, const std::string &latAlignment)
virtual void setMaxDecel(double decel)
Sets a new value for maximal comfortable deceleration [m/s^2].
Definition: MSCFModel.h:451
static void setMinGap(const std::string &typeID, double minGap)
static SUMOEmissionClass getClassByName(const std::string &eClass, const SUMOVehicleClass vc=SVC_IGNORING)
Checks whether the string describes a known vehicle class.
virtual void setMaxAccel(double accel)
Sets a new value for maximum acceleration [m/s^2].
Definition: MSCFModel.h:443
static double getActionStepLength(const std::string &typeID)
Definition: VehicleType.cpp:61
static void setMaxSpeedLat(const std::string &typeID, double speed)
virtual void setImperfection(double imperfection)
Sets a new value for driver imperfection.
Definition: MSCFModel.h:475
void setWidth(const double &width)
Set a new value for this type&#39;s width.
static double getMinGap(const std::string &typeID)
const RGBColor & getColor() const
Returns this type&#39;s color.
void setVClass(SUMOVehicleClass vclass)
Set a new value for this type&#39;s vehicle class.
void setColor(const RGBColor &color)
Set a new value for this type&#39;s color.
static RGBColor makeRGBColor(const TraCIColor &color)
Definition: Helper.cpp:141
SUMOVehicleShape getVehicleShapeID(const std::string &name)
Returns the class id of the shape class given by its name.
static void setColor(const std::string &typeID, const TraCIColor &c)
virtual void setEmergencyDecel(double decel)
Sets a new value for maximal physically possible deceleration [m/s^2].
Definition: MSCFModel.h:459
static double getMinGapLat(const std::string &typeID)
static double getTau(const std::string &typeID)
static double getAccel(const std::string &typeID)
Definition: VehicleType.cpp:79
double getApparentDecel() const
Get the vehicle type&#39;s apparent deceleration [m/s^2] (the one regarded by its followers.
Definition: MSCFModel.h:227
static std::string getLateralAlignment(const std::string &typeID)
static void setHeight(const std::string &typeID, double height)
void setMaxSpeedLat(const double &maxSpeedLat)
Set a new value for this type&#39;s maximum lateral speed.
SUMOEmissionClass getEmissionClass() const
Get this vehicle type&#39;s emission class.
void setPreferredLateralAlignment(LateralAlignment latAlignment)
Set vehicle&#39;s preferred lateral alignment.
static void setEmissionClass(const std::string &typeID, const std::string &clazz)
MSVehicleType * duplicateType(const std::string &id, bool persistent) const
Duplicates the microsim vehicle type giving the newly created type the given id.
static void setVehicleClass(const std::string &typeID, const std::string &clazz)
double getMaxSpeedLat() const
Get vehicle&#39;s maximum lateral speed [m/s].
static std::string getShapeClass(const std::string &typeID)
static TraCIColor getColor(const std::string &typeID)
static void setAccel(const std::string &typeID, double accel)
static std::vector< std::string > getIDList()
Definition: VehicleType.cpp:42