Eclipse SUMO - Simulation of Urban MObility
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
GNEHierarchicalElement.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// A abstract class for representation of hierarchical elements
19/****************************************************************************/
20
21#include <netedit/GNENet.h>
23
25
26// ===========================================================================
27// member method definitions
28// ===========================================================================
29
30// ---------------------------------------------------------------------------
31// GNEHierarchicalElement - methods
32// ---------------------------------------------------------------------------
33
35
36
38
39
44
45
46void
50
51
56
57
62
63
68
69
74
75
79 for (const auto& additional : getParentAdditionals()) {
80 if (additional->getTagProperty()->isStoppingPlace()) {
81 stoppingPlaces.push_back(additional);
82 }
83 }
84 return stoppingPlaces;
85}
86
87
91 for (const auto& additional : getParentAdditionals()) {
92 if (additional->getTagProperty()->isTAZElement()) {
93 TAZs.push_back(additional);
94 }
95 }
96 return TAZs;
97}
98
99
104
105
110
111
116
117
122
123
128
129
134
135
140
141
146
147
152
153
154std::string
155GNEHierarchicalElement::getNewListOfParents(const GNENetworkElement* currentElement, const GNENetworkElement* newNextElement) const {
156 std::vector<std::string> solution;
157 if ((currentElement->getTagProperty()->getTag() == SUMO_TAG_EDGE) && (newNextElement->getTagProperty()->getTag() == SUMO_TAG_EDGE)) {
158 // reserve solution
159 solution.reserve(getParentEdges().size());
160 // iterate over edges
161 for (const auto& edge : getParentEdges()) {
162 // add edge ID
163 solution.push_back(edge->getID());
164 // if current edge is the current element, then insert newNextElement ID
165 if (edge == currentElement) {
166 solution.push_back(newNextElement->getID());
167 }
168 }
169 } else if ((currentElement->getTagProperty()->getTag() == SUMO_TAG_LANE) && (newNextElement->getTagProperty()->getTag() == SUMO_TAG_LANE)) {
170 // reserve solution
171 solution.reserve(getParentLanes().size());
172 // iterate over lanes
173 for (const auto& lane : getParentLanes()) {
174 // add lane ID
175 solution.push_back(lane->getID());
176 // if current lane is the current element, then insert newNextElement ID
177 if (lane == currentElement) {
178 solution.push_back(newNextElement->getID());
179 }
180 }
181 }
182 // remove consecutive (adjacent) duplicates
183 solution.erase(std::unique(solution.begin(), solution.end()), solution.end());
184 // return solution
185 return toString(solution);
186}
187
188
189bool
191 // declare a vector to keep sorted children
192 std::vector<std::pair<std::pair<double, double>, GNEAdditional*> > sortedChildren;
193 // iterate over child meanData
194 for (const auto& meanData : getChildAdditionals()) {
195 sortedChildren.push_back(std::make_pair(std::make_pair(0., 0.), meanData));
196 // set begin/start attribute
197 if (meanData->getTagProperty()->hasAttribute(SUMO_ATTR_TIME) && GNEAttributeCarrier::canParse<double>(meanData->getAttribute(SUMO_ATTR_TIME))) {
198 sortedChildren.back().first.first = meanData->getAttributeDouble(SUMO_ATTR_TIME);
199 } else if (meanData->getTagProperty()->hasAttribute(SUMO_ATTR_BEGIN) && GNEAttributeCarrier::canParse<double>(meanData->getAttribute(SUMO_ATTR_BEGIN))) {
200 sortedChildren.back().first.first = meanData->getAttributeDouble(SUMO_ATTR_BEGIN);
201 }
202 // set end attribute
203 if (meanData->getTagProperty()->hasAttribute(SUMO_ATTR_END) && GNEAttributeCarrier::canParse<double>(meanData->getAttribute(SUMO_ATTR_END))) {
204 sortedChildren.back().first.second = meanData->getAttributeDouble(SUMO_ATTR_END);
205 } else {
206 sortedChildren.back().first.second = sortedChildren.back().first.first;
207 }
208 }
209 // sort children
210 std::sort(sortedChildren.begin(), sortedChildren.end());
211 // make sure that number of sorted children is the same as the child meanData
212 if (sortedChildren.size() == getChildAdditionals().size()) {
213 if (sortedChildren.size() <= 1) {
214 return true;
215 } else {
216 // check overlapping
217 for (int i = 0; i < (int)sortedChildren.size() - 1; i++) {
218 if (sortedChildren.at(i).first.second > sortedChildren.at(i + 1).first.first) {
219 return false;
220 }
221 }
222 }
223 return true;
224 } else {
225 throw ProcessError(TL("Some child meanData were lost during sorting"));
226 }
227}
228
229
230bool
234
235/****************************************************************************/
std::set< ChildType > GNEHierarchicalContainerChildrenSet
std::vector< ChildType > GNEHierarchicalContainerChildren
std::vector< ParentType > GNEHierarchicalContainerParents
#define TL(string)
Definition MsgHandler.h:305
@ SUMO_TAG_LANE
begin/end of the description of a single lane
@ SUMO_TAG_EDGE
begin/end of the description of an edge
@ SUMO_ATTR_BEGIN
weights: time range begin
@ SUMO_ATTR_END
weights: time range end
@ SUMO_ATTR_TIME
trigger: the time of the step
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
virtual double getAttributeDouble(SumoXMLAttr key) const =0
const std::string getID() const
get ID (all Attribute Carriers have one)
const GNETagProperties * getTagProperty() const
get tagProperty associated with this Attribute Carrier
A road/street connecting two junctions (netedit-version)
Definition GNEEdge.h:53
const GNEHierarchicalContainerChildren< GNEEdge * > & getChildEdges() const
get child edges
GNEHierarchicalStructureChildren myHierarchicalStructureChildren
hierarchical structure with children
const GNEHierarchicalContainerParents< GNEAdditional * > & getParentAdditionals() const
get parent additionals
const GNEHierarchicalContainerParents< GNEDemandElement * > & getParentDemandElements() const
get parent demand elements
const GNEHierarchicalContainerParents< GNEEdge * > & getParentEdges() const
get parent edges
const GNEHierarchicalContainerChildren< GNEGenericData * > & getChildGenericDatas() const
return child generic data elements
GNEHierarchicalElement()
default Constructor
const GNEHierarchicalContainerChildren< GNELane * > & getChildLanes() const
get child lanes
const GNEHierarchicalContainerParents< GNEGenericData * > & getParentGenericDatas() const
get parent demand elements
const GNEHierarchicalContainerChildren< GNEAdditional * > & getChildAdditionals() const
return child additionals
bool checkChildAdditionalsOverlapping() const
check if children are overlapped (Used by Rerouters)
const GNEHierarchicalContainerChildrenSet< GNETAZSourceSink * > & getChildTAZSourceSinks() const
return child TAZSourceSinks (Set)
bool checkChildDemandElementsOverlapping() const
check if child demand elements are overlapped
const GNEHierarchicalContainerChildren< GNEJunction * > & getChildJunctions() const
get child junctions
GNEHierarchicalStructureParents myHierarchicalStructureParents
hierarchical structure with parents
const GNEHierarchicalContainerParents< GNEJunction * > & getParentJunctions() const
get parent junctions
const GNEHierarchicalContainerParents< GNELane * > & getParentLanes() const
get parent lanes
const GNEHierarchicalStructureParents getParents() const
get parents(used in GNE_Change)
const GNEHierarchicalContainerParents< GNEAdditional * > getParentStoppingPlaces() const
get parent stoppingPlaces (used by plans)
const GNEHierarchicalContainerChildren< GNEDemandElement * > & getChildDemandElements() const
return child demand elements
std::string getNewListOfParents(const GNENetworkElement *currentElement, const GNENetworkElement *newNextElement) const
if use edge/parent lanes as a list of consecutive elements, obtain a list of IDs of elements after in...
void clearParents()
clear hierarchical structure parents (used in GNE_Change)
const GNEHierarchicalContainerParents< GNEAdditional * > getParentTAZs() const
get parent TAZs (used by plans)
const GNEHierarchicalContainerChildren< ChildType > & get() const
get children
const GNEHierarchicalContainerChildrenSet< ChildType > & getSet() const
get children (set)
Hierarchical structure used for keep parents.
const GNEHierarchicalContainerParents< ParentType > & get() const
get parents
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition GNELane.h:46
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property