Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEDemandElementDistribution.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-2024 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// A abstract class for demand elements distributions
19/****************************************************************************/
20
21#include <netedit/GNENet.h>
23
25
26// ===========================================================================
27// member method definitions
28// ===========================================================================
29
31 myDemandElement(demandElement) {
32}
33
34
35bool
39
40
41bool
43 return (myDistributionValues.count(key) > 0);
44}
45
46
47bool
48GNEDemandElementDistribution::isValueValid(const GNEDemandElement* key, const double value) const {
49 if (myDistributionValues.count(key) > 0) {
50 return ((value >= 0) && (value <= 1));
51 } else {
52 return false;
53 }
54}
55
56
57const std::map<const GNEDemandElement*, double>&
61
62
63std::map<std::string, GNEDemandElement*>
65 std::map<std::string, GNEDemandElement*> possibleKeys;
66 // get list of possible keys
67 auto allKeys = myDemandElement->getNet()->getAttributeCarriers()->getDemandElements().at(type);
68 // fill possible keys with non used keys
69 for (const auto& key : allKeys) {
70 if (!keyExists(key.second)) {
71 possibleKeys[key.second->getID()] = key.second;
72 }
73 }
74 return possibleKeys;
75}
76
77
78std::string
80 // first sort all keys by ID
81 std::set<std::string> sortedKeys;
82 for (const auto& values : myDistributionValues) {
83 sortedKeys.insert(values.first->getID());
84 }
85 // return keySortd
86 return toString(sortedKeys);
87}
88
89
90std::string
92 // first sort all keys by ID
93 std::map<std::string, const GNEDemandElement*> sortedKeys;
94 for (const auto& values : myDistributionValues) {
95 sortedKeys[values.first->getID()] = values.first;
96 }
97 // now obtain values sorted by ID
98 std::vector<double> values;
99 for (const auto& sortedKey : sortedKeys) {
100 values.push_back(myDistributionValues.at(sortedKey.second));
101 }
102 return toString(values);
103}
104
105
106double
108 if (myDistributionValues.count(key) > 0) {
109 return myDistributionValues.at(key);
110 } else {
111 throw ProcessError("Key doesn't exist");
112 }
113}
114
115
116void
118 GNEChange_Distribution::addKey(myDemandElement, key, value, undoList);
119}
120
121
122void
126
127
128void
130 GNEChange_Distribution::editValue(myDemandElement, key, newValue, undoList);
131}
132
133
134void
136 if (myDistributionValues.count(key) == 0) {
137 myDistributionValues[key] = value;
138 } else {
139 throw ProcessError("Key already exist");
140 }
141}
142
143
144void
146 if (myDistributionValues.count(key) > 0) {
147 myDistributionValues.erase(key);
148 } else {
149 throw ProcessError("Key doesn't exist");
150 }
151}
152
153
154void
156 myDistributionValues[key] = newValue;
157}
158
159/****************************************************************************/
SumoXMLTag
Numbers representing SUMO-XML - element names.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
GNENet * getNet() const
get pointer to net
static void editValue(GNEDemandElement *distribution, const GNEDemandElement *key, const double newValue, GNEUndoList *undoList)
edit value
static void addKey(GNEDemandElement *distribution, const GNEDemandElement *key, const double value, GNEUndoList *undoList)
add new key
static void removeKey(GNEDemandElement *distribution, const GNEDemandElement *key, GNEUndoList *undoList)
remove key
GNEDemandElement * myDemandElement
demand element
double getAttributeDistributionValue(const GNEDemandElement *key)
get attribute distribution value
void removeDistributionKey(const GNEDemandElement *key, GNEUndoList *undoList)
remove distribution key
std::map< const GNEDemandElement *, double > myDistributionValues
map with distribution keys and values
void addDistributionKey(const GNEDemandElement *key, const double value, GNEUndoList *undoList)
add distribution key
void editDistributionValue(const GNEDemandElement *key, const double newValue, GNEUndoList *undoList)
remove distribution (used in GNEDemandElementDistribution)
GNEDemandElementDistribution(GNEDemandElement *demandElement)
Constructor.
const std::map< const GNEDemandElement *, double > & getDistributionKeyValues() const
get map with distribution keys and values
std::map< std::string, GNEDemandElement * > getPossibleDistributionKeys(SumoXMLTag type) const
get list of possible keys sorted by ID
std::string getAttributeDistributionKeys() const
get attribute distribution keys in string format sorted by ID
bool isDistributionEmpty() const
check if distribution is empty
std::string getAttributeDistributionValues() const
get attribute distribution keys in string format sorted by ID
bool keyExists(const GNEDemandElement *key) const
check if the given key can be added in distribution
bool isValueValid(const GNEDemandElement *key, const double value) const
check if the given key-value can be added in distribution
const std::unordered_map< SumoXMLTag, std::unordered_map< const GUIGlObject *, GNEDemandElement * > > & getDemandElements() const
get demand elements
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:127