SUMO - Simulation of Urban MObility
GNECalibratorFlow.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 
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(""), 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  std::string 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(""), 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  setColor(color);
88  setDepartLane(departLane);
89  setDepartPos(departPos);
90  setDepartSpeed(departSpeed);
91  setArrivalLane(arrivalLane);
92  setArrivalPos(arrivalPos);
93  setArrivalSpeed(arrivalSpeed);
94  setLine(line);
95  setPersonNumber(personNumber);
96  setContainerNumber(containerNumber);
97  setReroute(reroute);
98  setDepartPosLat(departPosLat);
99  setArrivalPosLat(arrivalPosLat);
100  setBegin(begin);
101  setEnd(end);
102  setVehsPerHour(vehsPerHour);
103  setPeriod(period);
104  setProbability(probability);
105  setNumber(number);
106 }
107 
108 
110 
111 
114  return myCalibratorParent;
115 }
116 
117 
120  return SUMO_TAG_FLOW;
121 }
122 
123 
124 const std::string&
126  return myFlowID;
127 }
128 
129 
130 const std::string&
132  return myVehicleType;
133 }
134 
135 
136 const std::string&
138  return myRoute;
139 }
140 
141 
142 const std::string&
144  return myColor;
145 }
146 
147 
148 const std::string&
150  return myDepartLane;
151 }
152 
153 
154 const std::string&
156  return myDepartPos;
157 }
158 
159 
160 const std::string&
162  return myDepartSpeed;
163 }
164 
165 
166 const std::string&
168  return myArrivalLane;
169 }
170 
171 
172 const std::string&
174  return myArrivalPos;
175 }
176 
177 
178 const std::string&
180  return myArrivalSpeed;
181 }
182 
183 
184 const std::string&
186  return myLine;
187 }
188 
189 
190 int
192  return myPersonNumber;
193 }
194 
195 
196 int
198  return myContainerNumber;
199 }
200 
201 
202 bool
204  return myReroute;
205 }
206 
207 
208 std::string
210  return myDepartPosLat;
211 }
212 
213 
214 std::string
216  return myArrivalPosLat;
217 }
218 
219 
220 double
222  return myBegin;
223 }
224 
225 
226 double
228  return myEnd;
229 }
230 
231 
232 double
234  return myVehsPerHour;
235 }
236 
237 
238 double
240  return myPeriod;
241 }
242 
243 
244 double
246  return myProbability;
247 }
248 
249 
250 int
252  return myNumber;
253 }
254 
255 
258  return myTypeOfFlow;
259 }
260 
261 
262 bool
263 GNECalibratorFlow::setFlowID(std::string flowID) {
264  if (flowID.empty()) {
265  return false;
266  } else if (myCalibratorParent->getViewNet()->getNet()->flowExists(flowID) == true) {
267  return false;
268  } else {
269  myFlowID = flowID;
270  return true;
271  }
272 }
273 
274 
275 bool
276 GNECalibratorFlow::setVehicleType(std::string vehicleType) {
277  if (vehicleType.empty()) {
278  return false;
279  } else if (myCalibratorParent->getViewNet()->getNet()->vehicleTypeExists(vehicleType) == false) {
280  return false;
281  } else {
282  myVehicleType = vehicleType;
283  return true;
284  }
285 }
286 
287 
288 bool
289 GNECalibratorFlow::setRoute(std::string route) {
290  if (route.empty()) {
291  return false;
292  } else if (myCalibratorParent->getViewNet()->getNet()->routeExists(route) == false) {
293  return false;
294  } else {
295  myRoute = route;
296  return true;
297  }
298 }
299 
300 
301 bool
302 GNECalibratorFlow::setColor(std::string color) {
303  myColor = color;
304  return true;
305 }
306 
307 
308 bool
309 GNECalibratorFlow::setDepartLane(std::string departLane) {
310  int departLaneInt = -1;
311  if (GNEAttributeCarrier::canParse<int>(departLane)) {
312  departLaneInt = GNEAttributeCarrier::parse<int>(departLane);
313  }
314  if ((departLaneInt < 0) && (departLane != "random") && (departLane != "free") &&
315  (departLane != "allowed") && (departLane != "best") && (departLane != "first")) {
316  return false;
317  } else {
318  myDepartLane = departLane;
319  return true;
320  }
321 }
322 
323 
324 bool
325 GNECalibratorFlow::setDepartPos(std::string departPos) {
326  double departPosFloat = -1;
327  if (GNEAttributeCarrier::canParse<double>(departPos)) {
328  departPosFloat = GNEAttributeCarrier::parse<double>(departPos);
329  }
330  if ((departPosFloat < 0) && (departPos != "random") && (departPos != "free") &&
331  (departPos != "random_free") && (departPos != "base") && (departPos != "last")) {
332  return false;
333  } else {
334  myDepartPos = departPos;
335  return true;
336  }
337 }
338 
339 
340 bool
341 GNECalibratorFlow::setDepartSpeed(std::string departSpeed) {
342  double departSpeedDouble = -1;
343  if (GNEAttributeCarrier::canParse<double>(departSpeed)) {
344  departSpeedDouble = GNEAttributeCarrier::parse<double>(departSpeed);
345  }
346  if ((departSpeedDouble < 0) && (departSpeed != "random") && (departSpeed != "max")) {
347  return false;
348  } else {
349  myDepartSpeed = departSpeed;
350  return true;
351  }
352 }
353 
354 
355 bool
356 GNECalibratorFlow::setArrivalLane(std::string arrivalLane) {
357  int arrivalLaneInt = -1;
358  if (GNEAttributeCarrier::canParse<int>(arrivalLane)) {
359  arrivalLaneInt = GNEAttributeCarrier::parse<int>(arrivalLane);
360  }
361  if ((arrivalLaneInt < 0) && (arrivalLane != "current")) {
362  return false;
363  } else {
364  myArrivalLane = arrivalLane;
365  return true;
366  }
367 }
368 
369 
370 bool
371 GNECalibratorFlow::setArrivalPos(std::string arrivalPos) {
372  double arrivalPosFloat = -1;
373  if (GNEAttributeCarrier::canParse<double>(arrivalPos)) {
374  arrivalPosFloat = GNEAttributeCarrier::parse<double>(arrivalPos);
375  }
376  if ((arrivalPosFloat < 0) && (arrivalPos != "random") && (arrivalPos != "max")) {
377  return false;
378  } else {
379  myArrivalPos = arrivalPos;
380  return true;
381  }
382 }
383 
384 
385 bool
386 GNECalibratorFlow::setArrivalSpeed(std::string arrivalSpeed) {
387  double arrivalSpeedDouble = -1;
388  if (GNEAttributeCarrier::canParse<double>(arrivalSpeed)) {
389  arrivalSpeedDouble = GNEAttributeCarrier::parse<double>(arrivalSpeed);
390  }
391  if ((arrivalSpeedDouble < 0) && (arrivalSpeed != "current")) {
392  return false;
393  } else {
394  myArrivalSpeed = arrivalSpeed;
395  return true;
396  }
397 }
398 
399 
400 bool
401 GNECalibratorFlow::setLine(std::string line) {
402  myLine = line;
403  return true;
404 }
405 
406 
407 bool
409  if (personNumber < 0) {
410  return false;
411  } else {
412  myPersonNumber = personNumber;
413  return true;
414  }
415 }
416 
417 
418 bool
419 GNECalibratorFlow::setPersonNumber(std::string personNumber) {
420  if (GNEAttributeCarrier::canParse<int>(personNumber)) {
421  return setPersonNumber(GNEAttributeCarrier::parse<int>(personNumber));
422  } else if (GNEAttributeCarrier::canParse<double>(personNumber)) {
423  double personNumberDouble = GNEAttributeCarrier::parse<double>(personNumber);
424  // check if double is an integer
425  if (fmod(personNumberDouble, 1) == 0) {
426  return setPersonNumber((int)personNumberDouble);
427  } else {
428  return false;
429  }
430  } else {
431  return false;
432  }
433 }
434 
435 
436 bool
438  if (containerNumber < 0) {
439  return false;
440  } else {
441  myContainerNumber = containerNumber;
442  return true;
443  }
444 }
445 
446 
447 bool
448 GNECalibratorFlow::setContainerNumber(std::string ContainerNumber) {
449  if (GNEAttributeCarrier::canParse<int>(ContainerNumber)) {
450  return setContainerNumber(GNEAttributeCarrier::parse<int>(ContainerNumber));
451  } else if (GNEAttributeCarrier::canParse<double>(ContainerNumber)) {
452  double ContainerNumberDouble = GNEAttributeCarrier::parse<double>(ContainerNumber);
453  // check if double is an integer
454  if (fmod(ContainerNumberDouble, 1) == 0) {
455  return setContainerNumber((int)ContainerNumberDouble);
456  } else {
457  return false;
458  }
459  } else {
460  return false;
461  }
462 }
463 
464 
465 bool
467  myReroute = value;
468  return true;
469 }
470 
471 
472 bool
473 GNECalibratorFlow::setReroute(std::string value) {
474  if (GNEAttributeCarrier::canParse<bool>(value)) {
475  return setReroute(GNEAttributeCarrier::parse<bool>(value));
476  } else {
477  return false;
478  }
479 }
480 
481 
482 bool
483 GNECalibratorFlow::setDepartPosLat(std::string departPosLat) {
484  double departPosLatFloat = -1;
485  if (GNEAttributeCarrier::canParse<double>(departPosLat)) {
486  departPosLatFloat = GNEAttributeCarrier::parse<double>(departPosLat);
487  }
488  if ((departPosLatFloat < 0) && (departPosLat != "random") && (departPosLat != "random_free") &&
489  (departPosLat != "left") && (departPosLat != "right") && (departPosLat != "center")) {
490  return false;
491  } else {
492  myDepartPosLat = departPosLat;
493  return true;
494  }
495 }
496 
497 
498 bool
499 GNECalibratorFlow::setArrivalPosLat(std::string arrivalPosLat) {
500  double arrivalPosLatFloat = -1;
501  if (GNEAttributeCarrier::canParse<double>(arrivalPosLat)) {
502  arrivalPosLatFloat = GNEAttributeCarrier::parse<double>(arrivalPosLat);
503  }
504  if ((arrivalPosLatFloat < 0) && (arrivalPosLat != "left") && (arrivalPosLat != "right") && (arrivalPosLat != "center") && (arrivalPosLat != "")) {
505  return false;
506  } else {
507  myArrivalPosLat = arrivalPosLat;
508  return true;
509  }
510 }
511 
512 
513 bool
515  if (begin < 0) {
516  return false;
517  } else {
518  myBegin = begin;
519  return true;
520  }
521 }
522 
523 
524 bool
525 GNECalibratorFlow::setBegin(std::string begin) {
526  if (GNEAttributeCarrier::canParse<double>(begin)) {
527  return setBegin(GNEAttributeCarrier::parse<double>(begin));
528  } else {
529  return false;
530  }
531 }
532 
533 
534 bool
536  if (end < 0) {
537  return false;
538  } else {
539  myEnd = end;
540  return true;
541  }
542 }
543 
544 
545 bool
546 GNECalibratorFlow::setEnd(std::string end) {
547  if (GNEAttributeCarrier::canParse<double>(end)) {
548  return setEnd(GNEAttributeCarrier::parse<double>(end));
549  } else {
550  return false;
551  }
552 }
553 
554 
555 bool
557  if (vehsPerHour < 0) {
558  return false;
559  } else {
560  myVehsPerHour = vehsPerHour;
561  return true;
562  }
563 }
564 
565 
566 bool
567 GNECalibratorFlow::setVehsPerHour(std::string vehsPerHour) {
568  if (GNEAttributeCarrier::canParse<double>(vehsPerHour)) {
569  return setVehsPerHour(GNEAttributeCarrier::parse<double>(vehsPerHour));
570  } else {
571  return false;
572  }
573 }
574 
575 
576 bool
578  if (period < 0) {
579  return false;
580  } else {
581  myPeriod = period;
582  return true;
583  }
584 }
585 
586 
587 bool
588 GNECalibratorFlow::setPeriod(std::string period) {
589  if (GNEAttributeCarrier::canParse<double>(period)) {
590  return setPeriod(GNEAttributeCarrier::parse<double>(period));
591  } else {
592  return false;
593  }
594 }
595 
596 bool
598  if ((probability < 0) || (probability > 1)) {
599  return false;
600  } else {
601  myProbability = probability;
602  return true;
603  }
604 }
605 
606 
607 bool
608 GNECalibratorFlow::setProbability(std::string probability) {
609  if (GNEAttributeCarrier::canParse<double>(probability)) {
610  return setProbability(GNEAttributeCarrier::parse<double>(probability));
611  } else {
612  return false;
613  }
614 }
615 
616 
617 bool
619  if (number < 0) {
620  return false;
621  } else {
622  myNumber = number;
623  return true;
624  }
625 }
626 
627 
628 bool
629 GNECalibratorFlow::setNumber(std::string number) {
630  if (GNEAttributeCarrier::canParse<int>(number)) {
631  return setNumber(GNEAttributeCarrier::parse<int>(number));
632  } else if (GNEAttributeCarrier::canParse<double>(number)) {
633  double numberDouble = GNEAttributeCarrier::parse<double>(number);
634  // check if double is an integer
635  if (fmod(numberDouble, 1) == 0) {
636  return setNumber((int)numberDouble);
637  } else {
638  return false;
639  }
640  } else {
641  return false;
642  }
643 }
644 
645 
646 bool
649  myTypeOfFlow = type;
650  return true;
651  } else {
652  return false;
653  }
654 }
655 
656 
657 bool
658 GNECalibratorFlow::operator==(const GNECalibratorFlow& calibratorFlow) const {
659  return (myFlowID == calibratorFlow.getFlowID());
660 }
661 
662 /****************************************************************************/
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
bool flowExists(const std::string &flowID) const
Check if exist a flow with these ID.
Definition: GNENet.cpp:1443
const std::string & getArrivalLane() const
get arrival lane
bool setColor(std::string color="")
set color of flow
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:1430
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:1417
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
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 myColor
color of flow
std::string myArrivalSpeed
arrival speed
const std::string & getColor() const
get color of flow
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
double getEnd() const
get end time step