Eclipse SUMO - Simulation of Urban MObility
GNECalibratorFlow.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2020 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
18 //
19 /****************************************************************************/
20 #include <netedit/GNENet.h>
21 #include <netedit/GNEUndoList.h>
23 
24 #include "GNECalibratorFlow.h"
25 
26 
27 // ===========================================================================
28 // member method definitions
29 // ===========================================================================
30 
31 
33  GNEAdditional(calibratorParent->getNet(), GLO_CALIBRATOR, SUMO_TAG_FLOW_CALIBRATOR, "", false,
34 {}, {}, {}, {calibratorParent}, {}, {}, {}, {}),
35 myVehicleType(calibratorParent->getNet()->retrieveDemandElement(SUMO_TAG_VTYPE, DEFAULT_VTYPE_ID)),
36 myRoute(calibratorParent->getNet()->getAttributeCarriers()->getDemandElements().at(SUMO_TAG_ROUTE).begin()->second) {
37  // update centering boundary without updating grid
38  updateCenteringBoundary(false);
39  // fill calibrator flows with default values
40  setDefaultValues();
41 }
42 
43 
44 GNECalibratorFlow::GNECalibratorFlow(GNEAdditional* calibratorParent, GNEDemandElement* vehicleType, GNEDemandElement* route, const std::string& vehsPerHour, const std::string& speed,
45  const RGBColor& color, const std::string& departLane, const std::string& departPos, const std::string& departSpeed, const std::string& arrivalLane,
46  const std::string& arrivalPos, const std::string& arrivalSpeed, const std::string& line, int personNumber, int containerNumber, bool reroute,
47  const std::string& departPosLat, const std::string& arrivalPosLat, SUMOTime begin, SUMOTime end) :
48  GNEAdditional(calibratorParent->getNet(), GLO_CALIBRATOR, SUMO_TAG_FLOW_CALIBRATOR, "", false,
49 {}, {}, {}, {calibratorParent}, {}, {}, {}, {}),
50 myVehicleType(vehicleType),
51 myRoute(route),
52 myVehsPerHour(vehsPerHour),
53 mySpeed(speed),
54 myColor(color),
55 myDepartLane(departLane),
56 myDepartPos(departPos),
57 myDepartSpeed(departSpeed),
58 myArrivalLane(arrivalLane),
59 myArrivalPos(arrivalPos),
60 myArrivalSpeed(arrivalSpeed),
61 myLine(line),
62 myPersonNumber(personNumber),
63 myContainerNumber(containerNumber),
64 myReroute(reroute),
65 myDepartPosLat(departPosLat),
66 myArrivalPosLat(arrivalPosLat),
67 myBegin(begin),
68 myEnd(end) {
69  // update centering boundary without updating grid
70  updateCenteringBoundary(false);
71 }
72 
73 
75 
76 
78 GNECalibratorFlow::getMoveOperation(const double /*shapeOffset*/) {
79  // calibrators flow cannot be moved
80  return nullptr;
81 }
82 
83 
84 void
86  // use geometry of calibrator parent
88 }
89 
90 
91 void
92 GNECalibratorFlow::updateCenteringBoundary(const bool /*updateGrid*/) {
93  // use boundary of parent element
94  myBoundary = getParentAdditionals().front()->getCenteringBoundary();
95 }
96 
97 
98 void
99 GNECalibratorFlow::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
100  // geometry of this element cannot be splitted
101 }
102 
103 
104 std::string
106  return getParentAdditionals().at(0)->getID();
107 }
108 
109 
110 void
112  // Currently This additional isn't drawn
113 }
114 
115 
116 std::string
118  switch (key) {
119  case SUMO_ATTR_ID:
120  return getID();
121  case SUMO_ATTR_TYPE:
122  return myVehicleType->getID();
123  case SUMO_ATTR_ROUTE:
124  return myRoute->getID();
126  return myVehsPerHour;
127  case SUMO_ATTR_SPEED:
128  return mySpeed;
129  case SUMO_ATTR_COLOR:
130  return toString(myColor);
131  case SUMO_ATTR_BEGIN:
132  return time2string(myBegin);
133  case SUMO_ATTR_END:
134  return time2string(myEnd);
136  return myDepartLane;
137  case SUMO_ATTR_DEPARTPOS:
138  return myDepartPos;
140  return myDepartSpeed;
142  return myArrivalLane;
144  return myArrivalPos;
146  return myArrivalSpeed;
147  case SUMO_ATTR_LINE:
148  return myLine;
150  return toString(myPersonNumber);
152  return toString(myContainerNumber);
153  case SUMO_ATTR_REROUTE:
154  return toString(myReroute);
156  return myDepartPosLat;
158  return myArrivalPosLat;
159  case GNE_ATTR_PARENT:
160  return getParentAdditionals().at(0)->getID();
161  case GNE_ATTR_PARAMETERS:
162  return getParametersStr();
163  default:
164  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
165  }
166 }
167 
168 
169 double
171  switch (key) {
172  case SUMO_ATTR_BEGIN:
173  return STEPS2TIME(myBegin);
174  case SUMO_ATTR_END:
175  return STEPS2TIME(myEnd);
176  default:
177  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
178  }
179 }
180 
181 
182 void
183 GNECalibratorFlow::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
184  if (value == getAttribute(key)) {
185  return; //avoid needless changes, later logic relies on the fact that attributes have changed
186  }
187  switch (key) {
188  case SUMO_ATTR_ID:
189  case SUMO_ATTR_TYPE:
190  case SUMO_ATTR_ROUTE:
191  case SUMO_ATTR_COLOR:
193  case SUMO_ATTR_SPEED:
194  case SUMO_ATTR_BEGIN:
195  case SUMO_ATTR_END:
197  case SUMO_ATTR_DEPARTPOS:
202  case SUMO_ATTR_LINE:
205  case SUMO_ATTR_REROUTE:
208  case GNE_ATTR_PARAMETERS:
209  undoList->p_add(new GNEChange_Attribute(this, key, value));
210  break;
211  default:
212  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
213  }
214 }
215 
216 
217 bool
218 GNECalibratorFlow::isValid(SumoXMLAttr key, const std::string& value) {
219  switch (key) {
220  case SUMO_ATTR_ID:
221  return isValidAdditionalID(value);
222  case SUMO_ATTR_TYPE:
223  return SUMOXMLDefinitions::isValidTypeID(value) && (myNet->retrieveDemandElement(SUMO_TAG_VTYPE, value, false) != nullptr);
224  case SUMO_ATTR_ROUTE:
225  return SUMOXMLDefinitions::isValidVehicleID(value) && (myNet->retrieveAdditional(SUMO_TAG_ROUTE, value, false) != nullptr);
227  if (value.empty()) {
228  // speed and vehsPerHour cannot be empty at the same time
229  if (mySpeed.empty()) {
230  return false;
231  } else {
232  return true;
233  }
234  } else if (canParse<double>(value)) {
235  return (parse<double>(value) >= 0);
236  } else {
237  return false;
238  }
239  case SUMO_ATTR_SPEED:
240  if (value.empty()) {
241  // speed and vehsPerHour cannot be empty at the same time
242  if (myVehsPerHour.empty()) {
243  return false;
244  } else {
245  return true;
246  }
247  } else if (canParse<double>(value)) {
248  return (parse<double>(value) >= 0);
249  } else {
250  return false;
251  }
252  case SUMO_ATTR_COLOR:
253  return canParse<RGBColor>(value);
254  case SUMO_ATTR_BEGIN:
255  return canParse<SUMOTime>(value);
256  case SUMO_ATTR_END:
257  return canParse<SUMOTime>(value);
259  if ((value == "random") || (value == "free") || (value == "allowed") || (value == "best") || (value == "first")) {
260  return true;
261  } else {
262  return (myNet->retrieveLane(value, false) != nullptr);
263  }
264  case SUMO_ATTR_DEPARTPOS:
265  if ((value == "random") || (value == "free") || (value == "random_free") || (value == "base") || (value == "last")) {
266  return true;
267  } else {
268  return canParse<double>(value);
269  }
271  if ((value == "random") || (value == "max")) {
272  return true;
273  } else {
274  return canParse<double>(value);
275  }
277  if (value == "current") {
278  return true;
279  } else {
280  return (myNet->retrieveLane(value, false) != nullptr);
281  }
283  if ((value == "random") || (value == "max")) {
284  return true;
285  } else {
286  return canParse<double>(value);
287  }
289  if (value == "current") {
290  return true;
291  } else {
292  return canParse<double>(value);
293  }
294  case SUMO_ATTR_LINE:
295  return true;
297  return canParse<int>(value) && parse<int>(value) >= 0;
299  return canParse<int>(value) && parse<int>(value) >= 0;
300  case SUMO_ATTR_REROUTE:
301  return canParse<bool>(value);
306  case GNE_ATTR_PARAMETERS:
307  return Parameterised::areParametersValid(value);
308  default:
309  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
310  }
311 }
312 
313 
314 bool
316  return true;
317 }
318 
319 
320 std::string
322  return getTagStr();
323 }
324 
325 
326 std::string
328  return getTagStr() + ": " + getAttribute(SUMO_ATTR_BEGIN) + " -> " + getAttribute(SUMO_ATTR_END);
329 }
330 
331 // ===========================================================================
332 // private
333 // ===========================================================================
334 
335 void
336 GNECalibratorFlow::setAttribute(SumoXMLAttr key, const std::string& value) {
337  switch (key) {
338  case SUMO_ATTR_ID:
339  myNet->getAttributeCarriers()->updateID(this, value);
340  break;
341  case SUMO_ATTR_TYPE:
343  break;
344  case SUMO_ATTR_ROUTE:
346  break;
348  myVehsPerHour = value;
349  break;
350  case SUMO_ATTR_SPEED:
351  mySpeed = value;
352  break;
353  case SUMO_ATTR_COLOR:
354  myColor = parse<RGBColor>(value);
355  break;
356  case SUMO_ATTR_BEGIN:
357  myBegin = parse<SUMOTime>(value);
358  break;
359  case SUMO_ATTR_END:
360  myEnd = parse<SUMOTime>(value);
361  break;
363  myDepartLane = value;
364  break;
365  case SUMO_ATTR_DEPARTPOS:
366  myDepartPos = value;
367  break;
369  myDepartSpeed = value;
370  break;
372  myArrivalLane = value;
373  break;
375  myArrivalPos = value;
376  break;
378  myArrivalSpeed = value;
379  break;
380  case SUMO_ATTR_LINE:
381  myLine = value;
382  break;
384  myPersonNumber = parse<int>(value);
385  break;
387  myContainerNumber = parse<int>(value);
388  break;
389  case SUMO_ATTR_REROUTE:
390  myReroute = parse<bool>(value);
391  break;
393  myDepartPosLat = value;
394  break;
396  myArrivalPosLat = value;
397  break;
398  case GNE_ATTR_PARAMETERS:
399  setParametersStr(value);
400  break;
401  default:
402  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
403  }
404 }
405 
406 
407 void GNECalibratorFlow::setMoveShape(const GNEMoveResult& /*moveResult*/) {
408  // nothing to do
409 }
410 
411 void GNECalibratorFlow::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
412  // nothing to do
413 }
414 
415 
416 /****************************************************************************/
@ GLO_CALIBRATOR
a Calibrator
std::string time2string(SUMOTime t)
convert SUMOTime to string
Definition: SUMOTime.cpp:68
#define STEPS2TIME(x)
Definition: SUMOTime.h:53
long long int SUMOTime
Definition: SUMOTime.h:31
const std::string DEFAULT_VTYPE_ID
@ SUMO_TAG_VTYPE
description of a vehicle type
@ SUMO_TAG_ROUTE
begin/end of the description of a route
@ SUMO_TAG_FLOW_CALIBRATOR
a flow definition within in Calibrator (used in NETEDIT)
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_ARRIVALSPEED
@ SUMO_ATTR_ARRIVALLANE
@ SUMO_ATTR_VEHSPERHOUR
@ SUMO_ATTR_SPEED
@ SUMO_ATTR_DEPARTPOS_LAT
@ GNE_ATTR_PARENT
parent of an additional element
@ SUMO_ATTR_ARRIVALPOS
@ SUMO_ATTR_BEGIN
weights: time range begin
@ GNE_ATTR_PARAMETERS
parameters "key1=value1|key2=value2|...|keyN=valueN"
@ SUMO_ATTR_CONTAINER_NUMBER
@ SUMO_ATTR_LINE
@ SUMO_ATTR_DEPARTPOS
@ SUMO_ATTR_REROUTE
@ SUMO_ATTR_DEPARTSPEED
@ SUMO_ATTR_END
weights: time range end
@ SUMO_ATTR_DEPARTLANE
@ SUMO_ATTR_TYPE
@ SUMO_ATTR_ROUTE
@ SUMO_ATTR_PERSON_NUMBER
@ SUMO_ATTR_COLOR
A color information.
@ SUMO_ATTR_ID
@ SUMO_ATTR_ARRIVALPOS_LAT
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:44
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:47
const std::string & getID() const
get ID
GNEGeometry::Geometry myAdditionalGeometry
geometry to be precomputed in updateGeometry(...)
Boundary myBoundary
Additional Boundary.
const GNEGeometry::Geometry & getAdditionalGeometry() const
obtain additional geometry
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
friend class GNEChange_Attribute
declare friend class
const std::string & getTagStr() const
get tag assigned to this object in string format
GNENet * myNet
pointer to net
double getAttributeDouble(SumoXMLAttr key) const
std::string myDepartSpeed
depart speed
std::string myArrivalPos
arrival pos
int myContainerNumber
number of container
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
std::string myArrivalLane
arrival lane
~GNECalibratorFlow()
destructor
std::string myDepartLane
depart lane
RGBColor myColor
color of flow
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes
std::string myArrivalPosLat
void updateGeometry()
update pre-computed geometry information
GNECalibratorFlow(GNEAdditional *calibratorParent)
default constructor (used only in GNECalibratorDialog)
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
SUMOTime myEnd
time step end
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
std::string myLine
line of bus/container stop
int myPersonNumber
number of person
std::string mySpeed
flow speed (String instead float because can be empty)
std::string myArrivalSpeed
arrival speed
GNEDemandElement * myVehicleType
type of flow
bool isAttributeEnabled(SumoXMLAttr key) const
GNEMoveOperation * getMoveOperation(const double shapeOffset)
get move operation for the given shapeOffset
GNEDemandElement * myRoute
route in which this flow is used
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
std::string myDepartPosLat
departPosLat
std::string getParentName() const
Returns the name of the parent object.
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
std::string getAttribute(SumoXMLAttr key) const
inherited from GNEAttributeCarrier
std::string myVehsPerHour
flows per hour (String instead float because can be empty)
std::string myDepartPos
depart position
An Element which don't belongs to GNENet but has influency in the simulation.
const std::string & getID() const
get ID
void updateGeometry(const PositionVector &shape, double startPos=-1, double endPos=-1, const Position &extraFirstPosition=Position::INVALID, const Position &extraLastPosition=Position::INVALID)
update geometry shape
Definition: GNEGeometry.cpp:81
const std::vector< GNEAdditional * > & getParentAdditionals() const
get parent additionals
move operation
move result
void updateID(GNEAttributeCarrier *AC, const std::string newID)
update ID
GNELane * retrieveLane(const std::string &id, bool failHard=true, bool checkVolatileChange=false)
get lane by id
Definition: GNENet.cpp:1337
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
retrieve all attribute carriers of Net
Definition: GNENet.cpp:130
GNEAdditional * retrieveAdditional(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named additional.
Definition: GNENet.cpp:2316
GNEDemandElement * retrieveDemandElement(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named demand element.
Definition: GNENet.cpp:2435
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
Stores the information about how to visualize structures.
static bool areParametersValid(const std::string &value, bool report=false, ParameterisedAttrType attrType=ParameterisedAttrType::STRING, const std::string kvsep="=", const std::string sep="|")
check if given string can be parsed to a parameters map "key1=value1|key2=value2|....
void setParametersStr(const std::string &paramsString, const std::string kvsep="=", const std::string sep="|")
set the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN"
std::string getParametersStr(const std::string kvsep="=", const std::string sep="|") const
Returns the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN".
static bool isValidTypeID(const std::string &value)
whether the given string is a valid id for an edge or vehicle type
static bool isValidVehicleID(const std::string &value)
whether the given string is a valid id for a vehicle or flow
static StringBijection< LateralAlignment > LateralAlignments
lateral alignments
bool hasString(const std::string &str) const