SUMO - Simulation of Urban MObility
GNECalibratorFlow.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 //
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 
50 #include "GNEViewNet.h"
51 #include "GNENet.h"
52 #include "GNECalibratorFlow.h"
53 #include "GNECalibrator.h"
54 
55 
56 // ===========================================================================
57 // member method definitions
58 // ===========================================================================
59 
60 
62  myCalibratorParent(calibratorParent), myFlowID(calibratorParent->generateFlowID()), myVehicleType(""), myRoute(""), myColor(RGBColor::BLACK), myDepartLane("first"),
63  myDepartPos("base"), myDepartSpeed("0"), myArrivalLane("current"), myArrivalPos("max"), myArrivalSpeed("current"),
64  myLine(""), myPersonNumber(0), myContainerNumber(0), myReroute(false), myDepartPosLat("center"), myArrivalPosLat(""),
65  myBegin(0), myEnd(0), myVehsPerHour(0), myPeriod(0), myProbability(0), myNumber(0), myTypeOfFlow(GNE_CALIBRATORFLOW_VEHSPERHOUR) {
66  if (myCalibratorParent->getCalibratorRoutes().size() > 0) {
67  myRoute = myCalibratorParent->getCalibratorRoutes().front().getRouteID();
68  }
70  myVehicleType = myCalibratorParent->getCalibratorVehicleTypes().front().getVehicleTypeID();
71  }
72 }
73 
74 
75 GNECalibratorFlow::GNECalibratorFlow(GNECalibrator* calibratorParent, std::string flowID, std::string vehicleType, std::string route,
76  const RGBColor& color, std::string departLane, std::string departPos, std::string departSpeed, std::string arrivalLane, std::string arrivalPos,
77  std::string arrivalSpeed, std::string line, int personNumber, int containerNumber, bool reroute, std::string departPosLat,
78  std::string arrivalPosLat, double begin, double end, double vehsPerHour, double period, double probability, int number) :
79  myCalibratorParent(calibratorParent), myFlowID(calibratorParent->generateFlowID()), myVehicleType(vehicleType), myRoute(route), myColor(color), myDepartLane("first"),
80  myDepartPos("base"), myDepartSpeed("0"), myArrivalLane("current"), myArrivalPos("max"), myArrivalSpeed("current"),
83  // set parameters using the set functions, to avoid non valid values
84  setFlowID(flowID);
85  setVehicleType(vehicleType);
86  setRoute(route);
87  setDepartLane(departLane);
88  setDepartPos(departPos);
89  setDepartSpeed(departSpeed);
90  setArrivalLane(arrivalLane);
91  setArrivalPos(arrivalPos);
92  setArrivalSpeed(arrivalSpeed);
93  setLine(line);
94  setPersonNumber(personNumber);
95  setContainerNumber(containerNumber);
96  setReroute(reroute);
97  setDepartPosLat(departPosLat);
98  setArrivalPosLat(arrivalPosLat);
99  setBegin(begin);
100  setEnd(end);
101  setVehsPerHour(vehsPerHour);
102  setPeriod(period);
103  setProbability(probability);
104  setNumber(number);
105 }
106 
107 
109 
110 
113  return myCalibratorParent;
114 }
115 
116 
119  return SUMO_TAG_FLOW;
120 }
121 
122 
123 const std::string&
125  return myFlowID;
126 }
127 
128 
129 const std::string&
131  return myVehicleType;
132 }
133 
134 
135 const std::string&
137  return myRoute;
138 }
139 
140 
141 const RGBColor&
143  return myColor;
144 }
145 
146 
147 const std::string&
149  return myDepartLane;
150 }
151 
152 
153 const std::string&
155  return myDepartPos;
156 }
157 
158 
159 const std::string&
161  return myDepartSpeed;
162 }
163 
164 
165 const std::string&
167  return myArrivalLane;
168 }
169 
170 
171 const std::string&
173  return myArrivalPos;
174 }
175 
176 
177 const std::string&
179  return myArrivalSpeed;
180 }
181 
182 
183 const std::string&
185  return myLine;
186 }
187 
188 
189 int
191  return myPersonNumber;
192 }
193 
194 
195 int
197  return myContainerNumber;
198 }
199 
200 
201 bool
203  return myReroute;
204 }
205 
206 
207 std::string
209  return myDepartPosLat;
210 }
211 
212 
213 std::string
215  return myArrivalPosLat;
216 }
217 
218 
219 double
221  return myBegin;
222 }
223 
224 
225 double
227  return myEnd;
228 }
229 
230 
231 double
233  return myVehsPerHour;
234 }
235 
236 
237 double
239  return myPeriod;
240 }
241 
242 
243 double
245  return myProbability;
246 }
247 
248 
249 int
251  return myNumber;
252 }
253 
254 
257  return myTypeOfFlow;
258 }
259 
260 
261 bool
262 GNECalibratorFlow::setFlowID(std::string flowID) {
263  if (flowID.empty()) {
264  return false;
265  } else if (myCalibratorParent->getViewNet()->getNet()->flowExists(flowID)) {
266  return false;
267  } else {
268  myFlowID = flowID;
269  return true;
270  }
271 }
272 
273 
274 bool
275 GNECalibratorFlow::setVehicleType(std::string vehicleType) {
276  if (vehicleType.empty()) {
277  return false;
278  } else if (myCalibratorParent->getViewNet()->getNet()->vehicleTypeExists(vehicleType) == false) {
279  return false;
280  } else {
281  myVehicleType = vehicleType;
282  return true;
283  }
284 }
285 
286 
287 bool
288 GNECalibratorFlow::setRoute(std::string route) {
289  if (route.empty()) {
290  return false;
291  } else if (myCalibratorParent->getViewNet()->getNet()->routeExists(route) == false) {
292  return false;
293  } else {
294  myRoute = route;
295  return true;
296  }
297 }
298 
299 
300 bool
302  myColor = color;
303  return true;
304 }
305 
306 
307 bool
308 GNECalibratorFlow::setColor(std::string color) {
309  if (GNEAttributeCarrier::canParse<RGBColor>(color)) {
310  return setColor(GNEAttributeCarrier::parse<RGBColor>(color));
311  } else {
312  return false;
313  }
314 }
315 
316 bool
317 GNECalibratorFlow::setDepartLane(std::string departLane) {
318  int departLaneInt = -1;
319  if (GNEAttributeCarrier::canParse<int>(departLane)) {
320  departLaneInt = GNEAttributeCarrier::parse<int>(departLane);
321  }
322  if ((departLaneInt < 0) && (departLane != "random") && (departLane != "free") &&
323  (departLane != "allowed") && (departLane != "best") && (departLane != "first")) {
324  return false;
325  } else {
326  myDepartLane = departLane;
327  return true;
328  }
329 }
330 
331 
332 bool
333 GNECalibratorFlow::setDepartPos(std::string departPos) {
334  double departPosFloat = -1;
335  if (GNEAttributeCarrier::canParse<double>(departPos)) {
336  departPosFloat = GNEAttributeCarrier::parse<double>(departPos);
337  }
338  if ((departPosFloat < 0) && (departPos != "random") && (departPos != "free") &&
339  (departPos != "random_free") && (departPos != "base") && (departPos != "last")) {
340  return false;
341  } else {
342  myDepartPos = departPos;
343  return true;
344  }
345 }
346 
347 
348 bool
349 GNECalibratorFlow::setDepartSpeed(std::string departSpeed) {
350  double departSpeedDouble = -1;
351  if (GNEAttributeCarrier::canParse<double>(departSpeed)) {
352  departSpeedDouble = GNEAttributeCarrier::parse<double>(departSpeed);
353  }
354  if ((departSpeedDouble < 0) && (departSpeed != "random") && (departSpeed != "max")) {
355  return false;
356  } else {
357  myDepartSpeed = departSpeed;
358  return true;
359  }
360 }
361 
362 
363 bool
364 GNECalibratorFlow::setArrivalLane(std::string arrivalLane) {
365  int arrivalLaneInt = -1;
366  if (GNEAttributeCarrier::canParse<int>(arrivalLane)) {
367  arrivalLaneInt = GNEAttributeCarrier::parse<int>(arrivalLane);
368  }
369  if ((arrivalLaneInt < 0) && (arrivalLane != "current")) {
370  return false;
371  } else {
372  myArrivalLane = arrivalLane;
373  return true;
374  }
375 }
376 
377 
378 bool
379 GNECalibratorFlow::setArrivalPos(std::string arrivalPos) {
380  double arrivalPosFloat = -1;
381  if (GNEAttributeCarrier::canParse<double>(arrivalPos)) {
382  arrivalPosFloat = GNEAttributeCarrier::parse<double>(arrivalPos);
383  }
384  if ((arrivalPosFloat < 0) && (arrivalPos != "random") && (arrivalPos != "max")) {
385  return false;
386  } else {
387  myArrivalPos = arrivalPos;
388  return true;
389  }
390 }
391 
392 
393 bool
394 GNECalibratorFlow::setArrivalSpeed(std::string arrivalSpeed) {
395  double arrivalSpeedDouble = -1;
396  if (GNEAttributeCarrier::canParse<double>(arrivalSpeed)) {
397  arrivalSpeedDouble = GNEAttributeCarrier::parse<double>(arrivalSpeed);
398  }
399  if ((arrivalSpeedDouble < 0) && (arrivalSpeed != "current")) {
400  return false;
401  } else {
402  myArrivalSpeed = arrivalSpeed;
403  return true;
404  }
405 }
406 
407 
408 bool
409 GNECalibratorFlow::setLine(std::string line) {
410  myLine = line;
411  return true;
412 }
413 
414 
415 bool
417  if (personNumber < 0) {
418  return false;
419  } else {
420  myPersonNumber = personNumber;
421  return true;
422  }
423 }
424 
425 
426 bool
427 GNECalibratorFlow::setPersonNumber(std::string personNumber) {
428  if (GNEAttributeCarrier::canParse<int>(personNumber)) {
429  return setPersonNumber(GNEAttributeCarrier::parse<int>(personNumber));
430  } else if (GNEAttributeCarrier::canParse<double>(personNumber)) {
431  double personNumberDouble = GNEAttributeCarrier::parse<double>(personNumber);
432  // check if double is an integer
433  if (fmod(personNumberDouble, 1) == 0) {
434  return setPersonNumber((int)personNumberDouble);
435  } else {
436  return false;
437  }
438  } else {
439  return false;
440  }
441 }
442 
443 
444 bool
446  if (containerNumber < 0) {
447  return false;
448  } else {
449  myContainerNumber = containerNumber;
450  return true;
451  }
452 }
453 
454 
455 bool
456 GNECalibratorFlow::setContainerNumber(std::string ContainerNumber) {
457  if (GNEAttributeCarrier::canParse<int>(ContainerNumber)) {
458  return setContainerNumber(GNEAttributeCarrier::parse<int>(ContainerNumber));
459  } else if (GNEAttributeCarrier::canParse<double>(ContainerNumber)) {
460  double ContainerNumberDouble = GNEAttributeCarrier::parse<double>(ContainerNumber);
461  // check if double is an integer
462  if (fmod(ContainerNumberDouble, 1) == 0) {
463  return setContainerNumber((int)ContainerNumberDouble);
464  } else {
465  return false;
466  }
467  } else {
468  return false;
469  }
470 }
471 
472 
473 bool
475  myReroute = value;
476  return true;
477 }
478 
479 
480 bool
481 GNECalibratorFlow::setReroute(std::string value) {
482  if (GNEAttributeCarrier::canParse<bool>(value)) {
483  return setReroute(GNEAttributeCarrier::parse<bool>(value));
484  } else {
485  return false;
486  }
487 }
488 
489 
490 bool
491 GNECalibratorFlow::setDepartPosLat(std::string departPosLat) {
492  double departPosLatFloat = -1;
493  if (GNEAttributeCarrier::canParse<double>(departPosLat)) {
494  departPosLatFloat = GNEAttributeCarrier::parse<double>(departPosLat);
495  }
496  if ((departPosLatFloat < 0) && (departPosLat != "random") && (departPosLat != "random_free") &&
497  (departPosLat != "left") && (departPosLat != "right") && (departPosLat != "center")) {
498  return false;
499  } else {
500  myDepartPosLat = departPosLat;
501  return true;
502  }
503 }
504 
505 
506 bool
507 GNECalibratorFlow::setArrivalPosLat(std::string arrivalPosLat) {
508  double arrivalPosLatFloat = -1;
509  if (GNEAttributeCarrier::canParse<double>(arrivalPosLat)) {
510  arrivalPosLatFloat = GNEAttributeCarrier::parse<double>(arrivalPosLat);
511  }
512  if ((arrivalPosLatFloat < 0) && (arrivalPosLat != "left") && (arrivalPosLat != "right") && (arrivalPosLat != "center") && (arrivalPosLat != "")) {
513  return false;
514  } else {
515  myArrivalPosLat = arrivalPosLat;
516  return true;
517  }
518 }
519 
520 
521 bool
523  if (begin < 0) {
524  return false;
525  } else {
526  myBegin = begin;
527  return true;
528  }
529 }
530 
531 
532 bool
533 GNECalibratorFlow::setBegin(std::string begin) {
534  if (GNEAttributeCarrier::canParse<double>(begin)) {
535  return setBegin(GNEAttributeCarrier::parse<double>(begin));
536  } else {
537  return false;
538  }
539 }
540 
541 
542 bool
544  if (end < 0) {
545  return false;
546  } else {
547  myEnd = end;
548  return true;
549  }
550 }
551 
552 
553 bool
554 GNECalibratorFlow::setEnd(std::string end) {
555  if (GNEAttributeCarrier::canParse<double>(end)) {
556  return setEnd(GNEAttributeCarrier::parse<double>(end));
557  } else {
558  return false;
559  }
560 }
561 
562 
563 bool
565  if (vehsPerHour < 0) {
566  return false;
567  } else {
568  myVehsPerHour = vehsPerHour;
569  return true;
570  }
571 }
572 
573 
574 bool
575 GNECalibratorFlow::setVehsPerHour(std::string vehsPerHour) {
576  if (GNEAttributeCarrier::canParse<double>(vehsPerHour)) {
577  return setVehsPerHour(GNEAttributeCarrier::parse<double>(vehsPerHour));
578  } else {
579  return false;
580  }
581 }
582 
583 
584 bool
586  if (period < 0) {
587  return false;
588  } else {
589  myPeriod = period;
590  return true;
591  }
592 }
593 
594 
595 bool
596 GNECalibratorFlow::setPeriod(std::string period) {
597  if (GNEAttributeCarrier::canParse<double>(period)) {
598  return setPeriod(GNEAttributeCarrier::parse<double>(period));
599  } else {
600  return false;
601  }
602 }
603 
604 bool
606  if ((probability < 0) || (probability > 1)) {
607  return false;
608  } else {
609  myProbability = probability;
610  return true;
611  }
612 }
613 
614 
615 bool
616 GNECalibratorFlow::setProbability(std::string probability) {
617  if (GNEAttributeCarrier::canParse<double>(probability)) {
618  return setProbability(GNEAttributeCarrier::parse<double>(probability));
619  } else {
620  return false;
621  }
622 }
623 
624 
625 bool
627  if (number < 0) {
628  return false;
629  } else {
630  myNumber = number;
631  return true;
632  }
633 }
634 
635 
636 bool
637 GNECalibratorFlow::setNumber(std::string number) {
638  if (GNEAttributeCarrier::canParse<int>(number)) {
639  return setNumber(GNEAttributeCarrier::parse<int>(number));
640  } else if (GNEAttributeCarrier::canParse<double>(number)) {
641  double numberDouble = GNEAttributeCarrier::parse<double>(number);
642  // check if double is an integer
643  if (fmod(numberDouble, 1) == 0) {
644  return setNumber((int)numberDouble);
645  } else {
646  return false;
647  }
648  } else {
649  return false;
650  }
651 }
652 
653 
654 bool
657  myTypeOfFlow = type;
658  return true;
659  } else {
660  return false;
661  }
662 }
663 
664 
665 bool
666 GNECalibratorFlow::operator==(const GNECalibratorFlow& calibratorFlow) const {
667  return (myFlowID == calibratorFlow.getFlowID());
668 }
669 
670 /****************************************************************************/
bool setLine(std::string line="")
set line of busStop/containerStop
bool setDepartSpeed(std::string departSpeed="0")
set depart speed
SumoXMLTag
Numbers representing SUMO-XML - element names.
const std::vector< GNECalibratorRoute > & getCalibratorRoutes() const
get calibrator routes
bool operator==(const GNECalibratorFlow &calibratorFlow) const
overload operator ==
SumoXMLTag getTag() const
get tag
RGBColor myColor
color of flow
bool flowExists(const std::string &flowID) const
Check if exist a flow with these ID.
Definition: GNENet.cpp:1792
const std::string & getArrivalLane() const
get arrival lane
bool setContainerNumber(int containerNumber=0)
set number of container
const std::vector< GNECalibratorVehicleType > & getCalibratorVehicleTypes() const
get calibrator vehicleTypes
a flow definition (used by router)
int getNumber() const
get number of flows
bool setVehicleType(std::string vehicleType)
set vehicleType of flow
const std::string & getArrivalSpeed() const
get arrival speed
~GNECalibratorFlow()
destructor
std::string myLine
line of bus/container stop
const std::string & getDepartSpeed() const
get arrival speed
bool vehicleTypeExists(const std::string &vehicleTypeID) const
Check if exist a vehicle type with these ID.
Definition: GNENet.cpp:1779
std::string getArrivalPosLat() const
const std::string & getArrivalPos() const
get arrival position
std::string myDepartPosLat
departPosLat
bool routeExists(const std::string &routeID) const
Check if exist a route with these ID.
Definition: GNENet.cpp:1766
GNECalibrator * getCalibratorParent() const
get pointer to calibrator parent
bool setPeriod(double period)
set period of flows
bool setArrivalLane(std::string arrivalLane="current")
set arrival lane
bool setArrivalPos(std::string arrivalPos="max")
set arrival position
const std::string & getVehicleType() const
get vehicle type of flow
double getBegin() const
double myPeriod
period
int myNumber
number of flow
bool myReroute
reroute
std::string myArrivalPos
arrival pos
std::string getDepartPosLat() const
get departPosLat
bool setVehsPerHour(double vehsPerHour)
set flows per hour
const std::string & getRoute() const
get route in which this flow is used
double myEnd
time step end
std::string myArrivalPosLat
int myPersonNumber
number of person
bool setPersonNumber(int personNumber=0)
set number of persons
std::string myDepartPos
depart position
TypeOfFlow
type of flow
bool setBegin(double begin)
set begin step
TypeOfFlow getFlowType() const
get type of flow
bool setDepartPosLat(std::string departPosLat="center")
set departPosLat
GNEViewNet * getViewNet() const
Returns a pointer to GNEViewNet in which additional element is located.
std::string myRoute
route in which this flow is used
std::string myDepartLane
depart lane
bool setRoute(std::string route)
set route in which this flow is used
bool setColor(const RGBColor &color)
set color of flow
double getPeriod() const
get period of flow
std::string myArrivalLane
arrival lane
const std::string & getDepartPos() const
get depart position
bool setDepartPos(std::string departPos="base")
set depart position
bool setReroute(bool value)
set reroute
double myVehsPerHour
flows per hour
const std::string & getFlowID() const
get ID of flow
std::string myFlowID
ID of flow.
int myContainerNumber
number of container
bool setArrivalSpeed(std::string arrivalSpeed="current")
set arrival speed
bool setFlowID(std::string ID)
set ID of flow
const std::string & getDepartLane() const
get depart lane
GNECalibratorFlow(GNECalibrator *calibratorParent)
constructor
int getContainerNumber() const
get number of containers
double getVehsPerHour() const
get flows per hour
bool setProbability(double probability)
set probability of flow
double myProbability
probability
GNECalibrator * myCalibratorParent
pointer to calibrator parent
std::string myArrivalSpeed
arrival speed
int getPersonNumber() const
get number of persons
bool setTypeOfFlow(TypeOfFlow type)
set type of flow
std::string myDepartSpeed
depart speed
const std::string & getLine() const
get line of busStop/containerStop
bool setDepartLane(std::string departLane="first")
set depart lane
bool setNumber(int number)
set number of flows
GNENet * getNet() const
get the net object
TypeOfFlow myTypeOfFlow
type of flow
double getProbability() const
get probability of flow
bool setArrivalPosLat(std::string arrivalPosLat="")
set arrivalPosLat
bool getReroute() const
get reroute
std::string myVehicleType
type of flow
bool setEnd(double end)
set end step
const RGBColor & getColor() const
get color of flow
double getEnd() const
get end time step