SUMO - Simulation of Urban MObility
GNECalibratorVehicleType.cpp
Go to the documentation of this file.
1 /****************************************************************************/
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
10 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software; you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation; either version 3 of the License, or
17 // (at your option) any later version.
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 <string>
31 #include <iostream>
32 #include <utility>
37 #include <utils/common/ToString.h>
38 #include <utils/geom/GeomHelper.h>
45 #include <utils/gui/div/GLHelper.h>
49 
51 #include "GNECalibrator.h"
52 #include "GNEViewNet.h"
53 #include "GNENet.h"
54 
55 
56 // ===========================================================================
57 // member method definitions
58 // ===========================================================================
59 
60 
62  myCalibratorParent(calibratorParent), myVehicleTypeID(calibratorParent->generateVehicleTypeID()) {
63  // setset default parameters
64  setAccel();
65  setDecel();
66  setSigma();
67  setTau();
68  setLength();
69  setMinGap();
70  setMaxSpeed();
72  setSpeedDev();
73  setColor();
74  setVClass();
76  setShape();
77  setWidth();
78  setFilename();
79  setImpatience();
87  setMinGapLat();
89 }
90 
91 
92 GNECalibratorVehicleType::GNECalibratorVehicleType(GNECalibrator* calibratorParent, std::string vehicleTypeID,
93  double accel, double decel, double sigma, double tau, double length, double minGap, double maxSpeed,
94  double speedFactor, double speedDev, const std::string& color, SUMOVehicleClass vClass, const std::string& emissionClass,
95  SUMOVehicleShape shape, double width, const std::string& filename, double impatience, const std::string& laneChangeModel,
96  const std::string& carFollowModel, int personCapacity, int containerCapacity, double boardingDuration,
97  double loadingDuration, const std::string& latAlignment, double minGapLat, double maxSpeedLat) :
98  myCalibratorParent(calibratorParent), myVehicleTypeID(calibratorParent->generateVehicleTypeID()) {
99  // set parameters using the set functions, to avoid non valid values
100  setVehicleTypeID(vehicleTypeID);
101  setAccel(accel);
102  setDecel(decel);
103  setSigma(sigma);
104  setTau(tau);
105  setLength(length);
106  setMinGap(minGap);
107  setMaxSpeed(maxSpeed);
108  setSpeedFactor(speedFactor);
109  setSpeedDev(speedDev);
110  setColor(color);
111  setVClass(vClass);
112  setEmissionClass(emissionClass);
113  setShape(shape);
114  setWidth(width);
115  setFilename(filename);
116  setImpatience(impatience);
117  setLaneChangeModel(laneChangeModel);
118  setCarFollowModel(carFollowModel);
119  setPersonCapacity(personCapacity);
120  setContainerCapacity(containerCapacity);
121  setBoardingDuration(boardingDuration);
122  setLoadingDuration(loadingDuration);
123  setLatAlignment(latAlignment);
124  setMinGapLat(minGapLat);
125  setMaxSpeedLat(maxSpeedLat);
126 }
127 
128 
130 
131 
134  return myCalibratorParent;
135 }
136 
137 
140  return SUMO_TAG_VTYPE;
141 }
142 
143 
144 std::string
146  return myVehicleTypeID;
147 }
148 
149 
150 double
152  return myAccel;
153 }
154 
155 
156 double
158  return myDecel;
159 }
160 
161 
162 double
164  return mySigma;
165 }
166 
167 
168 double
170  return myTau;
171 }
172 
173 
174 double
176  return myLength;
177 }
178 
179 
180 double
182  return myMinGap;
183 }
184 
185 
186 double
188  return myMaxSpeed;
189 }
190 
191 
192 double
194  return mySpeedFactor;
195 }
196 
197 
198 double
200  return mySpeedDev;
201 }
202 
203 
204 std::string
206  return myColor;
207 }
208 
209 
212  return myVClass;
213 }
214 
215 
216 std::string
218  return myEmissionClass;
219 }
220 
221 
224  return myShape;
225 }
226 
227 
228 double
230  return myWidth;
231 }
232 
233 
234 std::string
236  return myFilename;
237 }
238 
239 
240 double
242  return myImpatience;
243 }
244 
245 
246 std::string
248  return myLaneChangeModel;
249 }
250 
251 
252 std::string
254  return myCarFollowModel;
255 }
256 
257 
258 int
260  return myPersonCapacity;
261 }
262 
263 
264 int
266  return myContainerCapacity;
267 }
268 
269 
270 double
272  return myBoardingDuration;
273 }
274 
275 
276 double
278  return myLoadingDuration;
279 }
280 
281 
282 std::string
284  return myLatAlignment;
285 }
286 
287 
288 double
290  return myMinGapLat;
291 }
292 
293 
294 double
296  return myMaxSpeedLat;
297 }
298 
299 bool
300 GNECalibratorVehicleType::setVehicleTypeID(std::string vehicleTypeID) {
301  if (vehicleTypeID.empty()) {
302  return false;
303  } else if (myCalibratorParent->getViewNet()->getNet()->vehicleTypeExists(vehicleTypeID) == true) {
304  return false;
305  } else {
306  myVehicleTypeID = vehicleTypeID;
307  return true;
308  }
309 }
310 
311 
312 bool
314  if (accel < 0) {
315  return false;
316  } else {
317  myAccel = accel;
318  return true;
319  }
320 }
321 
322 
323 bool
325  if (GNEAttributeCarrier::canParse<double>(accel)) {
326  return setAccel(GNEAttributeCarrier::parse<double>(accel));
327  } else {
328  return false;
329  }
330 }
331 
332 
333 bool
335  if (decel < 0) {
336  return false;
337  } else {
338  myDecel = decel;
339  return true;
340  }
341 }
342 
343 
344 bool
346  if (GNEAttributeCarrier::canParse<double>(decel)) {
347  return setDecel(GNEAttributeCarrier::parse<double>(decel));
348  } else {
349  return false;
350  }
351 }
352 
353 
354 bool
356  if (sigma < 0) {
357  return false;
358  } else {
359  mySigma = sigma;
360  return true;
361  }
362 }
363 
364 
365 bool
367  if (GNEAttributeCarrier::canParse<double>(sigma)) {
368  return setSigma(GNEAttributeCarrier::parse<double>(sigma));
369  } else {
370  return false;
371  }
372 }
373 
374 
375 bool
377  if (tau < 0) {
378  return false;
379  } else {
380  myTau = tau;
381  return true;
382  }
383 }
384 
385 
386 bool
388  if (GNEAttributeCarrier::canParse<double>(tau)) {
389  return setTau(GNEAttributeCarrier::parse<double>(tau));
390  } else {
391  return false;
392  }
393 }
394 
395 
396 bool
398  if (length < 0) {
399  return false;
400  } else {
401  myLength = length;
402  return true;
403  }
404 }
405 
406 
407 bool
409  if (GNEAttributeCarrier::canParse<double>(length)) {
410  return setLength(GNEAttributeCarrier::parse<double>(length));
411  } else {
412  return false;
413  }
414 }
415 
416 
417 bool
419  if (minGap < 0) {
420  return false;
421  } else {
422  myMinGap = minGap;
423  return true;
424  }
425 }
426 
427 
428 bool
430  if (GNEAttributeCarrier::canParse<double>(minGap)) {
431  return setMinGap(GNEAttributeCarrier::parse<double>(minGap));
432  } else {
433  return false;
434  }
435 }
436 
437 
438 bool
440  if (maxSpeed < 0) {
441  return false;
442  } else {
443  myMaxSpeed = maxSpeed;
444  return true;
445  }
446 }
447 
448 
449 bool
451  if (GNEAttributeCarrier::canParse<double>(maxSpeed)) {
452  return setMaxSpeed(GNEAttributeCarrier::parse<double>(maxSpeed));
453  } else {
454  return false;
455  }
456 }
457 
458 
459 bool
461  if (speedFactor < 0) {
462  return false;
463  } else {
464  mySpeedFactor = speedFactor;
465  return true;
466  }
467 }
468 
469 
470 bool
472  if (GNEAttributeCarrier::canParse<double>(speedFactor)) {
473  return setSpeedFactor(GNEAttributeCarrier::parse<double>(speedFactor));
474  } else {
475  return false;
476  }
477 }
478 
479 
480 bool
482  if (speedDev < 0) {
483  return false;
484  } else {
485  mySpeedDev = speedDev;
486  return true;
487  }
488 }
489 
490 
491 bool
493  if (GNEAttributeCarrier::canParse<double>(speedDev)) {
494  return setSpeedDev(GNEAttributeCarrier::parse<double>(speedDev));
495  } else {
496  return false;
497  }
498 }
499 
500 
501 bool
503  myColor = color;
504  return true;
505 }
506 
507 
508 bool
510  myVClass = vClass;
511  return true;
512 }
513 
514 
515 bool
517  if (canParseVehicleClasses(vClass) == true) {
518  return setVClass(getVehicleClassID(vClass));
519  } else {
520  return false;
521  }
522 }
523 
524 
525 bool
526 GNECalibratorVehicleType::setEmissionClass(std::string emissionClass) {
527  myEmissionClass = emissionClass;
528  return true;
529 }
530 
531 
532 bool
534  myShape = shape;
535  return true;
536 }
537 
538 
539 bool
541  if (canParseVehicleShape(shape)) {
542  return setShape(getVehicleShapeID(shape));
543  } else {
544  return false;
545  }
546 }
547 
548 
549 bool
551  if (width < 0) {
552  return false;
553  } else {
554  myWidth = width;
555  return true;
556  }
557 }
558 
559 
560 bool
562  if (GNEAttributeCarrier::canParse<double>(width)) {
563  return setWidth(GNEAttributeCarrier::parse<double>(width));
564  } else {
565  return false;
566  }
567 }
568 
569 
570 bool
572  myFilename = filename;
573  return true;
574 }
575 
576 
577 bool
579  if (impatience < 0) {
580  return false;
581  } else {
582  myImpatience = impatience;
583  return true;
584  }
585 }
586 
587 
588 bool
590  if (GNEAttributeCarrier::canParse<double>(impatience)) {
591  return setImpatience(GNEAttributeCarrier::parse<double>(impatience));
592  } else {
593  return false;
594  }
595 }
596 
597 
598 bool
599 GNECalibratorVehicleType::setLaneChangeModel(std::string laneChangeModel) {
600  myLaneChangeModel = laneChangeModel;
601  return true;
602 }
603 
604 
605 bool
606 GNECalibratorVehicleType::setCarFollowModel(std::string carFollowModel) {
607  myCarFollowModel = carFollowModel;
608  return true;
609 }
610 
611 
612 bool
614  if (personCapacity < 0) {
615  return false;
616  } else {
617  myPersonCapacity = personCapacity;
618  return true;
619  }
620 }
621 
622 
623 bool
624 GNECalibratorVehicleType::setPersonCapacity(std::string personCapacity) {
625  if (GNEAttributeCarrier::canParse<double>(personCapacity)) {
626  double personCapacityD = GNEAttributeCarrier::parse<double>(personCapacity);
627  // Check that double doesn't have decimals
628  if (fmod(personCapacityD, 1) == 0) {
629  return setPersonCapacity((int)personCapacityD);
630  } else {
631  return false;
632  }
633  } else {
634  return false;
635  }
636 }
637 
638 
639 bool
641  if (containerCapacity < 0) {
642  return false;
643  } else {
644  myContainerCapacity = containerCapacity;
645  return true;
646  }
647 }
648 
649 
650 bool
651 GNECalibratorVehicleType::setContainerCapacity(std::string containerCapacity) {
652  if (GNEAttributeCarrier::canParse<double>(containerCapacity)) {
653  double containerCapacityD = GNEAttributeCarrier::parse<double>(containerCapacity);
654  // Check that double doesn't have decimals
655  if (fmod(containerCapacityD, 1) == 0) {
656  return setContainerCapacity((int)containerCapacityD);
657  } else {
658  return false;
659  }
660  } else {
661  return false;
662  }
663 }
664 
665 
666 bool
668  if (boardingDuration < 0) {
669  return false;
670  } else {
671  myBoardingDuration = boardingDuration;
672  return true;
673  }
674 }
675 
676 
677 bool
678 GNECalibratorVehicleType::setBoardingDuration(std::string boardingDuration) {
679  if (GNEAttributeCarrier::canParse<double>(boardingDuration)) {
680  return setBoardingDuration(GNEAttributeCarrier::parse<double>(boardingDuration));
681  } else {
682  return false;
683  }
684 }
685 
686 
687 bool
689  if (loadingDuration < 0) {
690  return false;
691  } else {
692  myLoadingDuration = loadingDuration;
693  return true;
694  }
695 }
696 
697 
698 bool
699 GNECalibratorVehicleType::setLoadingDuration(std::string loadingDuration) {
700  if (GNEAttributeCarrier::canParse<double>(loadingDuration)) {
701  return setLoadingDuration(GNEAttributeCarrier::parse<double>(loadingDuration));
702  } else {
703  return false;
704  }
705 }
706 
707 
708 bool
709 GNECalibratorVehicleType::setLatAlignment(std::string latAlignment) {
710  if ((latAlignment == "left") || (latAlignment == "right") || (latAlignment == "center") ||
711  (latAlignment == "compact") || (latAlignment == "nice") || (latAlignment == "arbitrary")) {
712  myLatAlignment = latAlignment;
713  return true;
714  } else {
715  return false;
716  }
717 }
718 
719 
720 bool
722  if (minGapLat < 0) {
723  return false;
724  } else {
725  myMinGapLat = minGapLat;
726  return true;
727  }
728 }
729 
730 
731 bool
733  if (GNEAttributeCarrier::canParse<double>(minGapLat)) {
734  return setMinGapLat(GNEAttributeCarrier::parse<double>(minGapLat));
735  } else {
736  return false;
737  }
738 }
739 
740 
741 bool
743  if (maxSpeedLat < 0) {
744  return false;
745  } else {
746  myMaxSpeedLat = maxSpeedLat;
747  return true;
748  }
749 }
750 
751 
752 bool
754  if (GNEAttributeCarrier::canParse<double>(maxSpeedLat)) {
755  return setMaxSpeedLat(GNEAttributeCarrier::parse<double>(maxSpeedLat));
756  } else {
757  return false;
758  }
759 }
760 
761 
762 bool
764  return (myVehicleTypeID == calibratorVehicleType.getVehicleTypeID());
765 }
766 
767 /****************************************************************************/
SUMOVehicleClass getVehicleClassID(const std::string &name)
Returns the class id of the abstract class given by its name.
SUMOVehicleShape getShape() const
get shape
double myTau
Car-following model parameter.
double getMinGapLat() const
get min gap lat
double myMinGap
Empty space after leader [m].
double myMaxSpeedLat
The maximum lateral speed when using the sublane-model.
SumoXMLTag
Numbers representing SUMO-XML - element names.
SUMOVehicleClass getVClass() const
get VClass
bool setTau(double tau=1.0)
set tau
description of a vehicle type
bool setDecel(double decel=4.5)
set decel
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types...
std::string getLatAlignment() const
get lateral lat
bool setLength(double length=5.0)
set length
double getWidth() const
get width
bool setImpatience(double impatience=0.0)
set impatience
bool setAccel(double accel=2.6)
set accel
double myImpatience
Willingess of drivers to impede vehicles with higher priority. See below for semantics.
bool setMinGapLat(double minGapLat=0.12)
set min gap lat
bool setEmissionClass(std::string emissionClass="P_7_7")
set emission class
double getSigma() const
get sigma
bool setShape(std::string shape)
set shape (string version)
bool vehicleTypeExists(const std::string &vehicleTypeID) const
Check if exist a vehicle type with these ID.
Definition: GNENet.cpp:1430
std::string getEmissionClass() const
get emission class
bool operator==(const GNECalibratorVehicleType &calibratorVehicleType) const
overload operator ==
double myWidth
The vehicle&#39;s width [m] (only used for drawing)
double myAccel
The acceleration ability of vehicles of this type (in m/s^2)
double getLoadingDuration() const
get loading duration
bool setFilename(std::string filename="")
set filename
GNECalibrator * myCalibratorParent
pointer to calibrator parent
double myDecel
The deceleration ability of vehicles of this type (in m/s^2)
bool setMaxSpeed(double maxSpeed=70.0)
set max speed
double getSpeedDev() const
get speed dev
std::string getLaneChangeModel() const
get lane change model
std::string myLatAlignment
The preferred lateral alignment when using the sublane-model. One of (left, right, center, compact, nice, arbitrary).
double myLength
The vehicle&#39;s netto-length (length) (in m)
double getMaxSpeed() const
get max speed
bool canParseVehicleShape(const std::string &shape)
Checks whether the given string contains only known vehicle shape.
double mySigma
Car-following model parameter.
std::string getCarFollowModel() const
get car follow model
std::string myCarFollowModel
The model used for car following.
bool setWidth(double width=2.0)
set width
std::string myVehicleTypeID
vehicleType ID
std::string getVehicleTypeID() const
get VehicleTypeID
std::string getColor() const
get color
int myPersonCapacity
The number of persons (excluding an autonomous driver) the vehicle can transport. ...
double mySpeedDev
The deviation of the speedFactor; see below for details.
int getPersonCapacity() const
get person capacity
double getDecel() const
get decel
bool setPersonCapacity(int personCapacity=4)
set person capacity
double getSpeedFactor() const
get speed factor
SUMOVehicleClass myVClass
An abstract vehicle class.
GNECalibratorVehicleType(GNECalibrator *calibratorParent)
constructor
double getImpatience() const
get impatience
SUMOVehicleShape myShape
How this vehicle is rendered.
std::string getFilename() const
get filename
std::string myEmissionClass
An abstract emission class.
double getMinGap() const
get min gap
bool setSigma(double sigma=0.5)
set sigma
double getBoardingDuration() const
get boarding duration
std::string myFilename
Image file for rendering vehicles of this type (should be grayscale to allow functional coloring) ...
double getLength() const
get length
bool setSpeedDev(double speedDev=0.0)
set speed dev
bool setBoardingDuration(double boardingDuration=0.5)
set boarding duration
bool setMaxSpeedLat(double maxSpeedLat=1.0)
set max speed lat
bool canParseVehicleClasses(const std::string &classes)
Checks whether the given string contains only known vehicle classes.
GNEViewNet * getViewNet() const
Returns a pointer to GNEViewNet in which additional element is located.
bool setLaneChangeModel(std::string laneChangeModel="LC2013")
set lane change model
double myBoardingDuration
The time required by a person to board the vehicle.
SUMOVehicleShape
Definition of vehicle classes to differ between different appearences.
bool setCarFollowModel(std::string carFollowModel="Krauss")
set car follow model
bool setMinGap(double minGap=2.5)
set min gap
bool setSpeedFactor(double speedFactor=1.0)
set speed factor
GNENet * getNet() const
get the net object
GNECalibrator * getCalibratorParent() const
get pointer to calibrator parent
double myLoadingDuration
The time required to load a container onto the vehicle.
SUMOVehicleShape getVehicleShapeID(const std::string &name)
Returns the class id of the shape class given by its name.
std::string myColor
This vehicle type&#39;s color.
double myMinGapLat
The minimum lateral gap at a speed difference of 100km/h when using the sublane-model.
bool setVClass(SUMOVehicleClass vClass=SVC_PRIVATE)
set VClass
int getContainerCapacity() const
get container capacity
bool setColor(std::string color="1,1,0")
set color
double getAccel() const
get accel
bool setLoadingDuration(double loadingDuration=90.0)
set loading duration
SumoXMLTag getTag() const
get tag
bool setContainerCapacity(int containerCapacity=0)
set container capacity
double myMaxSpeed
The vehicle&#39;s maximum velocity (in m/s)
double mySpeedFactor
The vehicles expected multiplicator for lane speed limits.
std::string myLaneChangeModel
The model used for changing lanes.
int myContainerCapacity
The number of containers the vehicle can transport.
bool setVehicleTypeID(std::string vehicleTypeID)
set vehicleType ID
bool setLatAlignment(std::string latAlignment="center")
set lateral lat
double getMaxSpeedLat() const
get max speed lat