Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNERouteProbReroute.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-2026 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
22#include <netedit/GNENet.h>
24
25#include "GNERouteProbReroute.h"
26
27// ===========================================================================
28// member method definitions
29// ===========================================================================
30
31#ifdef _MSC_VER
32#pragma warning(push)
33#pragma warning(disable: 4355) // mask warning about "this" in initializers
34#endif
39
40
41GNERouteProbReroute::GNERouteProbReroute(GNEAdditional* rerouterIntervalParent, GNEDemandElement* route, double probability) :
42 GNEAdditional(rerouterIntervalParent, SUMO_TAG_ROUTE_PROB_REROUTE, ""),
44 myProbability(probability) {
45 // set parents
46 setParent<GNEAdditional*>(rerouterIntervalParent);
47 setParent<GNEDemandElement*>(route);
48 // update boundary of rerouter parent
49 rerouterIntervalParent->getParentAdditionals().front()->updateCenteringBoundary(true);
50}
51#ifdef _MSC_VER
52#pragma warning(pop)
53#endif
54
55
57
58
61 return nullptr;
62}
63
64
67 return nullptr;
68}
69
70
71const Parameterised*
73 return nullptr;
74}
75
76
77void
80 // write common additional attributes
82 // write specific attributes
85 device.closeTag();
86}
87
88
89bool
91 return true;
92}
93
94
95std::string
99
100
101void
103 // nothing to fix
104}
105
106
107bool
109 return false;
110}
111
112
113void
117
118
123
124
125void
127 // nothing to do
128}
129
130
131void
132GNERouteProbReroute::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
133 // geometry of this element cannot be splitted
134}
135
136
137std::string
139 return getParentAdditionals().at(0)->getID();
140}
141
142
143void
149
150
151std::string
153 switch (key) {
154 case SUMO_ATTR_ID:
155 return getMicrosimID();
156 case SUMO_ATTR_ROUTE:
157 return getParentDemandElements().front()->getID();
158 case SUMO_ATTR_PROB:
159 return toString(myProbability);
160 case GNE_ATTR_PARENT:
161 return getParentAdditionals().at(0)->getID();
162 default:
163 return getCommonAttribute(key);
164 }
165}
166
167
168double
172
173
178
179
184
185
186void
187GNERouteProbReroute::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
188 if (value == getAttribute(key)) {
189 return; //avoid needless changes, later logic relies on the fact that attributes have changed
190 }
191 switch (key) {
192 case SUMO_ATTR_ID:
193 case SUMO_ATTR_ROUTE:
194 case SUMO_ATTR_PROB:
195 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
196 break;
197 default:
198 setCommonAttribute(key, value, undoList);
199 break;
200 }
201}
202
203
204bool
205GNERouteProbReroute::isValid(SumoXMLAttr key, const std::string& value) {
206 switch (key) {
207 case SUMO_ATTR_ID:
208 return isValidAdditionalID(value);
209 case SUMO_ATTR_ROUTE:
210 return (myNet->getAttributeCarriers()->retrieveDemandElements(NamespaceIDs::routes, value, false) == nullptr);
211 case SUMO_ATTR_PROB:
212 return canParse<double>(value);
213 default:
214 return isCommonAttributeValid(key, value);
215 }
216}
217
218
219std::string
221 return getTagStr();
222}
223
224
225std::string
227 return getTagStr() + ": " + getParentDemandElements().front()->getID();
228}
229
230// ===========================================================================
231// private
232// ===========================================================================
233
234void
235GNERouteProbReroute::setAttribute(SumoXMLAttr key, const std::string& value) {
236 switch (key) {
237 case SUMO_ATTR_ID:
238 // update microsimID
239 setAdditionalID(value);
240 break;
241 case SUMO_ATTR_ROUTE:
243 break;
244 case SUMO_ATTR_PROB:
245 myProbability = parse<double>(value);
246 break;
247 default:
248 setCommonAttribute(key, value);
249 break;
250 }
251}
252
253/****************************************************************************/
@ REROUTER_ROUTEPROBREROUTE
@ SUMO_TAG_ROUTE_PROB_REROUTE
probability of route of a reroute
@ SUMO_TAG_ROUTE
description of a route
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ GNE_ATTR_PARENT
parent of an additional element
@ SUMO_ATTR_PROB
@ SUMO_ATTR_ROUTE
@ SUMO_ATTR_ID
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:49
bool isValidAdditionalID(const std::string &value) const
check if a new additional ID is valid
void setAdditionalID(const std::string &newID)
set additional ID
void writeAdditionalAttributes(OutputDevice &device) const
write common additional attributes
void replaceDemandElementParent(SumoXMLTag tag, const std::string &value, const int parentIndex)
replace demand element parent
void drawListedAdditional(const GUIVisualizationSettings &s, const RGBColor baseCol, const RGBColor textCol, GUITexture texture, const std::string text) const
draw listed additional
Position getListedPositionInView() const
get listed position in view
void updateGeometryListedAdditional()
update geometry of listed additional
double getCommonAttributeDouble(SumoXMLAttr key) const
PositionVector getCommonAttributePositionVector(SumoXMLAttr key) const
void setCommonAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
const std::string & getTagStr() const
get tag assigned to this object in string format
Position getCommonAttributePosition(SumoXMLAttr key) const
GNENet * myNet
pointer to net
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
const GNEHierarchicalContainerParents< GNEAdditional * > & getParentAdditionals() const
get parent additionals
const GNEHierarchicalContainerParents< GNEDemandElement * > & getParentDemandElements() const
get parent demand elements
GNEDemandElement * retrieveDemandElements(const std::vector< SumoXMLTag > types, const std::string &id, bool hardFail=true) const
Returns the named demand element.
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:174
double myProbability
probability with which a vehicle will use the given edge as destination
bool isValid(SumoXMLAttr key, const std::string &value) override
std::string getParentName() const override
Returns the name of the parent object.
PositionVector getAttributePositionVector(SumoXMLAttr key) const override
std::string getAdditionalProblem() const override
return a string with the current additional problem (must be reimplemented in all detector children)
GNEMoveElement * getMoveElement() const override
methods to retrieve the elements linked to this routeProbReroute
Position getPositionInView() const override
Returns position of additional in view.
Parameterised * getParameters() override
get parameters associated with this routeProbReroute
std::string getHierarchyName() const override
get Hierarchy Name (Used in AC Hierarchy)
GNERouteProbReroute(GNENet *net)
default constructor
void updateGeometry() override
update pre-computed geometry information
Position getAttributePosition(SumoXMLAttr key) const override
void writeAdditional(OutputDevice &device) const override
write additional element into a xml file
std::string getPopUpID() const override
get PopPup ID (Used in AC Hierarchy)
void drawGL(const GUIVisualizationSettings &s) const override
Draws the object.
void fixAdditionalProblem() override
fix additional problem (must be reimplemented in all detector children)
double getAttributeDouble(SumoXMLAttr key) const override
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList) override
split geometry
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
void updateCenteringBoundary(const bool updateGrid) override
update centering boundary (implies change in RTREE)
bool checkDrawMoveContour() const override
check if draw move contour (red)
std::string getAttribute(SumoXMLAttr key) const override
bool isAdditionalValid() const override
check if current additional is valid to be written into XML (must be reimplemented in all detector ch...
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
Stores the information about how to visualize structures.
static const std::vector< SumoXMLTag > routes
route namespace
Static storage of an output device and its base (abstract) implementation.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const ATTR_TYPE &attr, const T &val, const bool isNull=false)
writes a named attribute
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
An upper class for objects with additional parameters.
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
A list of positions.
static const RGBColor YELLOW
Definition RGBColor.h:195
static const RGBColor RED
named colors
Definition RGBColor.h:192