Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEVTypeDistribution.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-2023 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// VehicleType distribution used in netedit
19/****************************************************************************/
20#include <netedit/GNENet.h>
21#include <netedit/GNEUndoList.h>
24
26
27
28// ===========================================================================
29// member method definitions
30// ===========================================================================
31
34 GNEPathManager::PathElement::Options::DEMAND_ELEMENT, {}, {}, {}, {}, {}, {}) {
35 // reset default values
36 resetDefaultValues();
37}
38
39
40GNEVTypeDistribution::GNEVTypeDistribution(GNENet* net, const std::string& vTypeID, const int deterministic) :
42 GNEPathManager::PathElement::Options::DEMAND_ELEMENT, {}, {}, {}, {}, {}, {}),
43 myDeterministic(deterministic) {
44}
45
46
48
49
52 return nullptr;
53}
54
55
56void
58 // get vtypes that has this vType distribution
59 std::vector<std::string> vTypes;
60 std::vector<std::string> probabilities;
61 for (const auto& vType : myNet->getAttributeCarriers()->getDemandElements().at(SUMO_TAG_VTYPE)) {
62 // get type distributions and probabilities
63 const auto typeDistributionIDs = StringTokenizer(vType->getAttribute(GNE_ATTR_VTYPE_DISTRIBUTION)).getVector();
64 const auto distributionProbabilities = StringTokenizer(vType->getAttribute(GNE_ATTR_VTYPE_DISTRIBUTION_PROBABILITY)).getVector();
65 for (int i = 0; i < (int)typeDistributionIDs.size(); i++) {
66 if (typeDistributionIDs.at(i) == getID()) {
67 vTypes.push_back(vType->getID());
68 probabilities.push_back(distributionProbabilities.at(i));
69 }
70 }
71 }
72 // only save if there is vTypes to save
73 if (vTypes.size() > 0) {
74 device.openTag(getTagProperty().getTag());
75 device.writeAttr(SUMO_ATTR_ID, getID());
76 device.writeAttr(SUMO_ATTR_VTYPES, vTypes);
77 device.writeAttr(SUMO_ATTR_PROBS, probabilities);
78 device.closeTag();
79 }
80}
81
82
85 // currently vTypeDistributions don't have problems
87}
88
89
90std::string
94
95
96void
100
101
106
107
108const RGBColor&
112
113
114void
116 // nothing to update
117}
118
119
124
125
126std::string
130
131
134 // VehicleType distribution doesn't have boundaries
135 return Boundary(-0.1, -0.1, 0.1, 0.1);
136}
137
138
139void
140GNEVTypeDistribution::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
141 // geometry of this element cannot be splitted
142}
143
144
145void
147 // Vehicle Types aren't draw
148}
149
150
151void
153 // nothing to compute
154}
155
156
157void
158GNEVTypeDistribution::drawPartialGL(const GUIVisualizationSettings& /*s*/, const GNELane* /*lane*/, const GNEPathManager::Segment* /*segment*/, const double /*offsetFront*/) const {
159 // vehicleType distributions don't use drawPartialGL
160}
161
162
163void
164GNEVTypeDistribution::drawPartialGL(const GUIVisualizationSettings& /*s*/, const GNELane* /*fromLane*/, const GNELane* /*toLane*/, const GNEPathManager::Segment* /*segment*/, const double /*offsetFront*/) const {
165 // vehicleType distributions don't use drawPartialGL
166}
167
168
169GNELane*
171 // vehicle types don't use lanes
172 return nullptr;
173}
174
175
176GNELane*
178 // vehicle types don't use lanes
179 return nullptr;
180}
181
182
183std::string
185 switch (key) {
186 case SUMO_ATTR_ID:
187 return getMicrosimID();
189 if (myDeterministic == -1) {
190 return "";
191 } else {
193 }
194 default:
195 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
196 }
197}
198
199
200double
202 if (key == GNE_ATTR_ADDITIONALCHILDREN) {
203 double counter = 0;
204 for (const auto& vType : myNet->getAttributeCarriers()->getDemandElements().at(SUMO_TAG_VTYPE)) {
205 // only write if appear in this distribution
206 if (vType->getAttribute(GNE_ATTR_VTYPE_DISTRIBUTION) == getID() && vType->getChildAdditionals().size() > 0) {
207 counter++;
208 }
209 }
210 return counter;
211 } else {
212 // obtain all types with the given typeDistribution sorted by ID
213 std::map<std::string, GNEDemandElement*> sortedTypes;
214 for (const auto &type : myNet->getAttributeCarriers()->getDemandElements().at(SUMO_TAG_VTYPE)) {
215 if (type->getAttribute(GNE_ATTR_VTYPE_DISTRIBUTION) == getID()) {
216 sortedTypes[type->getID()] = type;
217 }
218 }
219 // return first type, or default vType
220 if (sortedTypes.size() > 0) {
221 return sortedTypes.begin()->second->getAttributeDouble(key);
222 } else {
223 return 0;
224 }
225 }
226}
227
228
231 throw InvalidArgument(getTagStr() + " doesn't have a Position attribute of type '" + toString(key) + "'");
232}
233
234
235void
236GNEVTypeDistribution::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
237 if (value == getAttribute(key)) {
238 return; //avoid needless changes, later logic relies on the fact that attributes have changed
239 }
240 switch (key) {
241 case SUMO_ATTR_ID:
243 undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
244 break;
245 default:
246 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
247 }
248}
249
250
251bool
252GNEVTypeDistribution::isValid(SumoXMLAttr key, const std::string& value) {
253 switch (key) {
254 case SUMO_ATTR_ID:
255 if (value == getID()) {
256 return true;
257 } else if (SUMOXMLDefinitions::isValidVehicleID(value)) {
259 } else {
260 return false;
261 }
263 if (value == "-1" || value.empty()) {
264 return true;
265 } else {
266 return canParse<int>(value) && (parse<int>(value) >= 0);
267 }
268 default:
269 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
270 }
271}
272
273
274std::string
276 return getTagStr();
277}
278
279
280std::string
284
285
288 throw InvalidArgument(getTagStr() + " doesn't have parameters");
289}
290
291// ===========================================================================
292// private
293// ===========================================================================
294
295void
296GNEVTypeDistribution::setAttribute(SumoXMLAttr key, const std::string& value) {
297 switch (key) {
298 case SUMO_ATTR_ID:
299 setMicrosimID(value);
300 break;
302 if (value.empty()) {
303 myDeterministic = -1;
304 } else {
305 myDeterministic = parse<int>(value);
306 }
307 break;
308 default:
309 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
310 }
311}
312
313
314void
316 // vehicleType distributions cannot be moved
317}
318
319
320void
322 // vehicleType distributions cannot be moved
323}
324
325/****************************************************************************/
@ GLO_VTYPE
@bief vTypes
GUIIcon
An enumeration of icons used by the gui applications.
Definition GUIIcons.h:33
@ VTYPEDISTRIBUTION
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_IGNORING
vehicles ignoring classes
@ SUMO_TAG_VTYPE
description of a vehicle/person/container type
@ SUMO_TAG_VTYPE_DISTRIBUTION
distribution of a vehicle type
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_PROBS
@ GNE_ATTR_VTYPE_DISTRIBUTION
vehicle type distribution
@ GNE_ATTR_ADDITIONALCHILDREN
check number of additional children (used in vTypeDistribution)
@ SUMO_ATTR_VTYPES
@ SUMO_ATTR_DETERMINISTIC
@ GNE_ATTR_VTYPE_DISTRIBUTION_PROBABILITY
vehicle type distribution
@ SUMO_ATTR_ID
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
A class that stores a 2D geometrical boundary.
Definition Boundary.h:39
const std::string getID() const
get ID (all Attribute Carriers have one)
friend class GNEChange_Attribute
declare friend class
const std::string & getTagStr() const
get tag assigned to this object in string format
const GNETagProperties & getTagProperty() const
get tagProperty associated with this Attribute Carrier
GNENet * myNet
pointer to net
An Element which don't belong to GNENet but has influence in the simulation.
bool demandElementExist(const std::string &id, const std::vector< SumoXMLTag > tags) const
check if the given demand element exist
Problem
enum class for demandElement problems
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition GNELane.h:46
move operation
move result
const std::map< SumoXMLTag, std::set< GNEDemandElement * > > & getDemandElements() const
get demand elements
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:120
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
void changeAttribute(GNEChange_Attribute *change)
special method for change attributes, avoid empty changes, always execute
void drawPartialGL(const GUIVisualizationSettings &s, const GNELane *lane, const GNEPathManager::Segment *segment, const double offsetFront) const
Draws partial object.
std::string getParentName() const
Returns the name of the parent object.
void computePathElement()
compute pathElement
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform demand element changes
Problem isDemandElementValid() const
check if current demand element is valid to be writed into XML
void writeDemandElement(OutputDevice &device) const
write demand element element into a xml file
std::string getAttribute(SumoXMLAttr key) const
inherited from GNEAttributeCarrier
GNELane * getFirstPathLane() const
get first path lane
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
Position getPositionInView() const
Returns position of additional in view.
void updateGeometry()
update pre-computed geometry information
GNEVTypeDistribution(GNENet *net)
default constructor
const RGBColor & getColor() const
get color
double getAttributeDouble(SumoXMLAttr key) const
int myDeterministic
deterministic attribute
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
SUMOVehicleClass getVClass() const
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
const Parameterised::Map & getACParametersMap() const
get parameters map
GNELane * getLastPathLane() const
get last path lane
Position getAttributePosition(SumoXMLAttr key) const
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
GNEMoveOperation * getMoveOperation()
get move operation
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
void fixDemandElementProblem()
fix demand element problem
std::string getDemandElementProblem() const
return a string with the current demand element problem
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
virtual void setMicrosimID(const std::string &newID)
Changes the microsimID of the object.
Stores the information about how to visualize structures.
Static storage of an output device and its base (abstract) implementation.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
std::map< std::string, std::string > Map
parameters map
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
static const RGBColor BLACK
Definition RGBColor.h:193
static bool isValidVehicleID(const std::string &value)
whether the given string is a valid id for a vehicle or flow
std::vector< std::string > getVector()
return vector of strings