Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netgen/NGNet.h
169665 views
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
/****************************************************************************/
14
/// @file NGNet.h
15
/// @author Markus Hartinger
16
/// @author Daniel Krajzewicz
17
/// @author Michael Behrisch
18
/// @date Mar, 2003
19
///
20
// The class storing the generated network
21
/****************************************************************************/
22
#pragma once
23
#include <config.h>
24
25
#include <utils/distribution/Distribution_Parameterized.h>
26
#include "NGEdge.h"
27
#include "NGNode.h"
28
29
30
// ===========================================================================
31
// class declarations
32
// ===========================================================================
33
class NBNetBuilder;
34
35
36
// ===========================================================================
37
// class definitions
38
// ===========================================================================
39
/**
40
* @class NGNet
41
* @brief The class storing the generated network
42
*
43
* An instance of this class stores both the edges and the nodes build during
44
* the generation of a network (using any type of generation algorithm).
45
* These instances are later transformed into netbuild-structures using toNB().
46
*/
47
class NGNet {
48
public:
49
/// @brief Constructor
50
NGNet(NBNetBuilder& nb);
51
52
53
/// @brief Destructor
54
~NGNet();
55
56
57
/** @brief Returns the node at the given position
58
*
59
* Searches for a node with the given position within myNodeList.
60
* Returns the matching node, if one exists, or 0 otherwise.
61
*
62
* @param[in] xPos The x-position of the searched node
63
* @param[in] yPos The y-position of the searched node
64
* @return The node with the given position, or 0 if no such node exists
65
*/
66
NGNode* findNode(int xPos, int yPos);
67
68
69
/** @brief Returns the next free id
70
*
71
* Uses the value of myLastID to return a new (numeric) id. Increases
72
* myLastID.
73
*
74
* @return A new, unique numerical id
75
*/
76
std::string getNextFreeID();
77
78
79
/** @brief Returns the x-position resulting from the given radius and angle
80
*
81
* @param[in] radius The radius of the circle
82
* @param[in] phi The angle the position is located at
83
* @return The x-position at the described circle at angle phi
84
*/
85
double radialToX(double radius, double phi);
86
87
88
/** @brief Returns the y-position resulting from the given radius and angle
89
*
90
* @param[in] radius The radius of the circle
91
* @param[in] phi The angle the position is located at
92
* @return The y-position at the described circle at angle phi
93
*/
94
double radialToY(double radius, double phi);
95
96
97
/** @brief Creates a grid network
98
*
99
* Performs a double-loop over numX, then numY. Builds NGNodes
100
* at the according positions and connects them using NGNet::connect.
101
* Stores both the nodes and the edges within the internal container.
102
*
103
* The nodes get an id using &lt;RUNNING_X&gt;/&lt;RUNNING_Y&gt;. The ids
104
* of the links are set in NGNet::connect.
105
*
106
* @param[in] numX The number of nodes in x-direction
107
* @param[in] numY The number of nodes in y-direction
108
* @param[in] spaceX The space between nodes in x-direction
109
* @param[in] spaceY The space between nodes in y-direction
110
* @param[in] xAttachLength The length of streets attached at the border in x-direction
111
* @param[in] yAttachLength The length of streets attached at the border in y-direction
112
* @see NGNet::connect
113
*/
114
void createChequerBoard(int numX, int numY, double spaceX, double spaceY, double xAttachLength, double yAttachLength);
115
116
117
/** @brief Creates a spider network
118
*
119
* Creates a spider web by going through all arms and then all circles in a loop.
120
* Builds the NGNodes at the positions obtained using radialToX and radialToY and
121
* connects them using NGNet::connect. Builds optionally a center node, and connects
122
* it, too.
123
*
124
* The nodes get an id using &lt;RUNNING_ARM_NUMBER&gt;/&lt;RUNNING_CIRCLE_NUMBER&gt;.
125
* The ids of the links are set in NGNet::connect.
126
*
127
* @param[in] numRadDiv The number of arms to build
128
* @param[in] numCircles The number of circles to build
129
* @param[in] spaceRad The distance between the circles
130
* @param[in] hasCenter Information whether a center node shall be built
131
* @see NGNet::connect
132
* @todo consolidate the name of the center node
133
*/
134
void createSpiderWeb(int numRadDiv, int numCircles, double spaceRad, bool hasCenter, double attachLength);
135
136
137
/** @brief Converts the stored network into its netbuilder-representation
138
*
139
* Goes through all stored nodes, first, converts them into their netbuilder
140
* representations using NGNode::buildNBNode, and stores the built NBNodes into the
141
* net builder myNetBuilder.
142
*
143
* Then, the method goes through all edges, converts them into their netbuilder
144
* representations using NGEdge::buildNBEdge, and stores the built NBEdges into the
145
* net builder myNetBuilder.
146
*
147
* If one of the nodes is controlled by a tls and the built logic could not be added
148
* to net builder's storage, a ProcessError is thrown. This in fact may only happen
149
* when two same ids occur, what is not possible.
150
*
151
* @exception ProcessError If a built tls logic could not be added (should never happen)
152
* @todo Check whether throwing an exception is really necessary, here
153
*/
154
void toNB() const;
155
156
157
/** @brief Adds the given node to the network
158
*
159
* The node is added to myNodeList.
160
*
161
* @param[in] node The node to add
162
*/
163
void add(NGNode* node);
164
165
166
/** @brief Adds the given edge to the network
167
*
168
* The edge is added to myEdgeList.
169
*
170
* @param[in] edge The edge to add
171
*/
172
void add(NGEdge* edge);
173
174
175
/** @brief Returns the number of stored nodes
176
*
177
* @return The number of stored nodes
178
*/
179
int nodeNo() const;
180
181
182
private:
183
/** @brief Connects both nodes with two edges, one for each direction
184
*
185
* Builds one link for each direction and appends the links to myEdgeList.
186
* The name of a link is as following: &lt;FROM_NODE_ID&gt;to&lt;TO_NODE_ID&gt;.
187
*
188
* @param[in] node1 The first node to connect
189
* @param[in] node2 The second node to connect
190
*/
191
void connect(NGNode* node1, NGNode* node2);
192
193
/// @brief return a letter code for the given integer index
194
std::string alphabeticalCode(int i, int iMax);
195
196
/// @brief get distribution from option
197
static Distribution_Parameterized getDistribution(const std::string& option);
198
199
private:
200
/// @brief The last ID given to node or link
201
int myLastID;
202
203
/// @brief Whether to use alphanumericalIDs
204
const bool myAlphaIDs;
205
206
/// @brief The builder used to build NB*-structures
207
NBNetBuilder& myNetBuilder;
208
209
/// @brief The list of nodes
210
NGNodeList myNodeList;
211
212
/// @brief The list of links
213
NGEdgeList myEdgeList;
214
215
private:
216
/// @brief Invalidated copy constructor.
217
NGNet(const NGNet&);
218
219
/// @brief Invalidated assignment operator.
220
NGNet& operator=(const NGNet&);
221
222
};
223
224