Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEDemandElementFlow.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2025 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// An auxiliar, asbtract class for flow elements (vehicles, person and containers)
19/****************************************************************************/
20
22#include <netedit/GNEUndoList.h>
26
28
29// ===========================================================================
30// member method definitions
31// ===========================================================================
32
34 // set default flow attributes
35 setDefaultFlowAttributes(flowElement);
36}
37
38
40 SUMOVehicleParameter(vehicleParameters) {
41 // set default flow attributes
42 setDefaultFlowAttributes(flowElement);
43}
44
45
47
48
49void
50GNEDemandElementFlow::drawFlowLabel(const Position& position, const double rotation, const double width,
51 const double length, const double exaggeration) const {
52 // declare contour width
53 const double contourWidth = (0.05 * exaggeration);
54 // Push matrix
56 // Traslate to bot
57 glTranslated(position.x(), position.y(), GLO_VEHICLELABELS);
58 // glTranslated(position.x(), position.y(), GLO_ROUTE + getType() + 0.1 + GLO_PERSONFLOW + 0.1);
59 glRotated(rotation, 0, 0, -1);
60 glTranslated(-1 * ((width * 0.5 * exaggeration) + (0.35 * exaggeration)) - 0.05, 0, 0);
61 // draw external box
63 GLHelper::drawBoxLine(Position(), Position(), 0, (length * exaggeration), 0.3 * exaggeration);
64 // draw internal box
65 glTranslated(0, 0, 0.1);
67 GLHelper::drawBoxLine(Position(0, -contourWidth), Position(0, -contourWidth), 0, (length * exaggeration) - (contourWidth * 2), (0.3 * exaggeration) - contourWidth);
68 // draw stack label
69 GLHelper::drawText("Flow", Position(0, length * exaggeration * -0.5), (.1 * exaggeration), (0.6 * exaggeration), RGBColor::BLACK, 90, 0, -1);
70 // pop draw matrix
72}
73
74
75std::string
77 switch (key) {
79 case SUMO_ATTR_BEGIN:
81 return "triggered";
83 return "containerTriggered";
85 return "now";
87 return "split";
89 return "begin";
90 } else {
91 return time2string(depart);
92 }
93 case SUMO_ATTR_END:
101 case GNE_ATTR_POISSON:
103 case SUMO_ATTR_PROB:
105 case SUMO_ATTR_NUMBER:
111 } else {
112 return toString(SUMO_ATTR_END);
113 }
116 } else {
117 return "invalid terminate";
118 }
129 return toString(SUMO_ATTR_PROB);
132 } else {
133 return "invalid flow spacing";
134 }
135 default:
136 return flowElement->getCommonAttribute(key);
137 }
138}
139
140
141double
143 switch (key) {
144 case SUMO_ATTR_DEPART:
145 case SUMO_ATTR_BEGIN:
146 return STEPS2TIME(depart);
147 default:
148 throw InvalidArgument("Flow doesn't have a double attribute of type '" + toString(key) + "'");
149 }
150}
151
152
153void
155 switch (key) {
156 case SUMO_ATTR_DEPART:
157 case SUMO_ATTR_BEGIN:
158 case SUMO_ATTR_END:
159 case SUMO_ATTR_NUMBER:
163 case SUMO_ATTR_PERIOD:
164 case GNE_ATTR_POISSON:
165 case SUMO_ATTR_PROB:
168 GNEChange_Attribute::changeAttribute(flowElement, key, value, undoList);
169 break;
170 default:
171 return flowElement->setCommonAttribute(key, value, undoList);
172 }
173}
174
175
176bool
178 // declare string error
179 std::string error;
180 switch (key) {
181 case SUMO_ATTR_DEPART:
182 case SUMO_ATTR_BEGIN: {
183 SUMOTime dummyDepart;
184 DepartDefinition dummyDepartProcedure;
185 parseDepart(value, flowElement->getTagProperty()->getTagStr(), id, dummyDepart, dummyDepartProcedure, error);
186 // if error is empty, given value is valid
187 return error.empty();
188 }
189 case SUMO_ATTR_END:
192 } else {
193 return false;
194 }
198 case SUMO_ATTR_PERIOD:
199 case GNE_ATTR_POISSON:
202 } else {
203 return false;
204 }
205 case SUMO_ATTR_PROB:
207 const double prob = GNEAttributeCarrier::parse<double>(value);
208 return ((prob >= 0) && (prob <= 1));
209 } else {
210 return false;
211 }
212 case SUMO_ATTR_NUMBER:
215 } else {
216 return false;
217 }
220 const auto& flowValues = flowElement->getTagProperty()->getAttributeProperties(key)->getDiscreteValues();
221 if (std::find(flowValues.begin(), flowValues.end(), value) != flowValues.end()) {
222 return true;
223 } else {
224 return false;
225 }
226 }
227 default:
228 return flowElement->isCommonAttributeValid(key, value);
229 }
230}
231
232
233void
235 switch (key) {
236 case SUMO_ATTR_END:
237 case SUMO_ATTR_NUMBER:
241 case SUMO_ATTR_PERIOD:
242 case GNE_ATTR_POISSON:
243 case SUMO_ATTR_PROB:
244 undoList->add(new GNEChange_ToggleAttribute(flowElement, key, true), true);
245 return;
246 default:
247 throw InvalidArgument(flowElement->getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
248 }
249}
250
251
252void
254 switch (key) {
255 case SUMO_ATTR_END:
256 case SUMO_ATTR_NUMBER:
260 case SUMO_ATTR_PERIOD:
261 case GNE_ATTR_POISSON:
262 case SUMO_ATTR_PROB:
263 undoList->add(new GNEChange_ToggleAttribute(flowElement, key, false), true);
264 return;
265 default:
266 throw InvalidArgument(flowElement->getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
267 }
268}
269
270
271bool
273 switch (key) {
274 case SUMO_ATTR_END:
275 return (parametersSet & VEHPARS_END_SET) != 0;
276 case SUMO_ATTR_NUMBER:
277 return (parametersSet & VEHPARS_NUMBER_SET) != 0;
281 return (parametersSet & VEHPARS_VPH_SET) != 0;
282 case SUMO_ATTR_PERIOD:
283 return (parametersSet & VEHPARS_PERIOD_SET) != 0;
284 case GNE_ATTR_POISSON:
285 return (parametersSet & VEHPARS_POISSON_SET) != 0;
286 case SUMO_ATTR_PROB:
287 return (parametersSet & VEHPARS_PROB_SET) != 0;
290 default:
291 return true;
292 }
293}
294
295
296void
298 // declare string error
299 std::string error;
300 switch (key) {
301 case SUMO_ATTR_DEPART:
302 case SUMO_ATTR_BEGIN: {
303 parseDepart(value, flowElement->getTagProperty()->getTagStr(), id, depart, departProcedure, error);
304 break;
305 }
306 case SUMO_ATTR_END:
308 break;
314 break;
315 case SUMO_ATTR_PERIOD:
318 break;
319 case GNE_ATTR_POISSON:
322 break;
323 case SUMO_ATTR_PROB:
325 break;
326 case SUMO_ATTR_NUMBER:
328 break;
333 // in this special case, disable other spacing
338 } else {
339 // if previously end-number was enabled, enable perHour
342 }
343 if (value == toString(SUMO_ATTR_END)) {
346 } else if (value == toString(SUMO_ATTR_NUMBER)) {
349 }
350 }
351 break;
360 } else if (value == toString(SUMO_ATTR_PERIOD)) {
365 } else if (value == toString(GNE_ATTR_POISSON)) {
370 } else if (value == toString(SUMO_ATTR_PROB)) {
375 }
376 break;
377 default:
378 flowElement->setCommonAttribute(key, value);
379 break;
380 }
381}
382
383
384void
386 // modify parameters depending of given Flow attribute
387 if (value) {
388 switch (attribute) {
389 case SUMO_ATTR_END:
391 break;
392 case SUMO_ATTR_NUMBER:
394 break;
399 break;
400 case SUMO_ATTR_PERIOD:
402 break;
403 case GNE_ATTR_POISSON:
405 break;
406 case SUMO_ATTR_PROB:
408 break;
409 default:
410 break;
411 }
412 } else {
413 switch (attribute) {
414 case SUMO_ATTR_END:
416 break;
417 case SUMO_ATTR_NUMBER:
419 break;
424 break;
425 case SUMO_ATTR_PERIOD:
427 break;
428 case GNE_ATTR_POISSON:
430 break;
431 case SUMO_ATTR_PROB:
433 break;
434 default:
435 break;
436 }
437 }
438}
439
440
441void
443 // first check that this demand element is a flow
444 if (flowElement->getTagProperty()->isFlow()) {
445 // end
446 if ((parametersSet & VEHPARS_END_SET) == 0) {
448 }
449 // number
450 if ((parametersSet & VEHPARS_NUMBER_SET) == 0) {
452 }
453 // vehicles/person/container per hour
454 if (((parametersSet & VEHPARS_PERIOD_SET) == 0) &&
456 ((parametersSet & VEHPARS_VPH_SET) == 0)) {
458 }
459 // probability
460 if ((parametersSet & VEHPARS_PROB_SET) == 0) {
462 }
463 // poisson
464 if (repetitionOffset < 0) {
468 } else {
470 }
471 }
472}
473
474/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
@ GLO_VEHICLELABELS
stack and flow labels (used in netedit)
const std::string invalid_return< std::string >::value
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
Definition SUMOTime.cpp:46
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition SUMOTime.cpp:91
#define STEPS2TIME(x)
Definition SUMOTime.h:55
#define TIME2STEPS(x)
Definition SUMOTime.h:57
const long long int VEHPARS_END_SET
const long long int VEHPARS_PERIOD_SET
const long long int VEHPARS_POISSON_SET
const long long int VEHPARS_PROB_SET
const long long int VEHPARS_VPH_SET
const long long int VEHPARS_NUMBER_SET
DepartDefinition
Possible ways to depart.
@ BEGIN
The departure is at simulation start.
@ NOW
The vehicle is discarded if emission fails (not fully implemented yet).
@ SPLIT
The departure is triggered by a train split.
@ CONTAINER_TRIGGERED
The departure is container triggered.
@ TRIGGERED
The departure is person triggered.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_NUMBER
@ SUMO_ATTR_DEPART
@ SUMO_ATTR_VEHSPERHOUR
@ SUMO_ATTR_BEGIN
weights: time range begin
@ GNE_ATTR_POISSON
poisson definition (used in flow)
@ SUMO_ATTR_CONTAINERSPERHOUR
@ SUMO_ATTR_PERIOD
@ SUMO_ATTR_END
weights: time range end
@ SUMO_ATTR_PROB
@ GNE_ATTR_FLOW_SPACING
flow spacing
@ GNE_ATTR_FLOW_TERMINATE
flow terminating
@ SUMO_ATTR_PERSONSPERHOUR
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition GLHelper.cpp:653
static void popMatrix()
pop matrix
Definition GLHelper.cpp:135
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition GLHelper.cpp:300
static void pushMatrix()
push matrix
Definition GLHelper.cpp:122
static void drawText(const std::string &text, const Position &pos, const double layer, const double size, const RGBColor &col=RGBColor::BLACK, const double angle=0, const int align=0, double width=-1)
Definition GLHelper.cpp:747
static T parse(const std::string &string)
parses a value of type T from string (used for basic types: int, double, bool, etc....
void setCommonAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
const std::string & getTagStr() const
get tag assigned to this object in string format
static bool canParse(const std::string &string)
true if a value of type T can be parsed from string
const GNETagProperties * getTagProperty() const
get tagProperty associated with this Attribute Carrier
bool isCommonAttributeValid(SumoXMLAttr key, const std::string &value) const
std::string getCommonAttribute(SumoXMLAttr key) const
static void changeAttribute(GNEAttributeCarrier *AC, SumoXMLAttr key, const std::string &value, GNEUndoList *undoList, const bool force=false)
change attribute
the function-object for an editing operation (abstract base)
void toggleFlowAttribute(const SumoXMLAttr attribute, const bool value)
toggle flow parameters (used in toggleAttribute(...) function of vehicles, persons and containers
void drawFlowLabel(const Position &position, const double rotation, const double width, const double length, const double exaggeration) const
draw flow label
std::string getFlowAttribute(const GNEDemandElement *flowElement, SumoXMLAttr key) const
inherited from GNEAttributeCarrier and adapted to GNEDemandElementFlow
void disableFlowAttribute(GNEDemandElement *flowElement, SumoXMLAttr key, GNEUndoList *undoList)
bool isFlowAttributeEnabled(SumoXMLAttr key) const
double getFlowAttributeDouble(SumoXMLAttr key) const
GNEDemandElementFlow(GNEDemandElement *flowElement)
constructor
bool isValidFlowAttribute(GNEDemandElement *flowElement, SumoXMLAttr key, const std::string &value)
void enableFlowAttribute(GNEDemandElement *flowElement, SumoXMLAttr key, GNEUndoList *undoList)
void setFlowAttribute(GNEDemandElement *flowElement, SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
void setDefaultFlowAttributes(GNEDemandElement *flowElement)
set flow default attributes
bool isFlow() const
return true if tag correspond to a flow element
const std::string & getTagStr() const
get Tag vinculated with this attribute Property in String Format (used to avoid multiple calls to toS...
const std::vector< const GNEAttributeProperties * > & getAttributeProperties() const
get all attribute properties
bool hasAttribute(SumoXMLAttr attr) const
check if current TagProperties owns the attribute "attr"
const std::string & getDefaultStringValue(SumoXMLAttr attr) const
default values
void add(GNEChange *command, bool doit=false, bool merge=true)
Add new command, executing it if desired. The new command will be merged with the previous command if...
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
double x() const
Returns the x-position.
Definition Position.h:52
double y() const
Returns the y-position.
Definition Position.h:57
static const RGBColor GREY
Definition RGBColor.h:197
static const RGBColor CYAN
Definition RGBColor.h:192
static const RGBColor BLACK
Definition RGBColor.h:196
double repetitionProbability
The probability for emitting a vehicle per second.
SUMOTime repetitionOffset
The time offset between vehicle reinsertions.
long long int parametersSet
Information for the router which parameter were set, TraCI may modify this (when changing color).
double poissonRate
The rate for emitting vehicles with a poisson distribution.
SUMOTime repetitionEnd
The time at which the flow ends (only needed when using repetitionProbability).
static bool parseDepart(const std::string &val, const std::string &element, const std::string &id, SUMOTime &depart, DepartDefinition &dd, std::string &error, const std::string &attr="departure")
Validates a given depart value.
DepartDefinition departProcedure
Information how the vehicle shall choose the depart time.
static std::string adjustDecimalValue(double value, int precision)
write with maximum precision if needed but remove trailing zeros