Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netgen/NGRandomNetBuilder.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 NGRandomNetBuilder.h
15
/// @author Markus Hartinger
16
/// @author Daniel Krajzewicz
17
/// @author Michael Behrisch
18
/// @date Mar, 2003
19
///
20
// Additional structures for building random nets
21
/****************************************************************************/
22
#pragma once
23
#include <config.h>
24
25
#include <map>
26
#include <utils/distribution/RandomDistributor.h>
27
#include "NGNet.h"
28
29
30
// ===========================================================================
31
// class definitions
32
// ===========================================================================
33
/**
34
* @class NGRandomNetBuilder
35
* @brief A class that builds random network using an algorithm by Markus Hartinger.
36
*
37
* @todo Describe the algorithm
38
*/
39
class NGRandomNetBuilder {
40
public:
41
/** @brief Constructor
42
*
43
* @param[in] net The network to fill with generated structures
44
* @param[in] minAngle The minimum allowed angle between two streets
45
* @param[in] minDistance The minimum allowed distance between two nodes
46
* @param[in] maxDistance The maximum allowed distance between two nodes
47
* @param[in] connectivity The connectivity factor
48
* @param[in] numTries ?
49
* @todo check meanings of connectivity/numTries
50
*/
51
NGRandomNetBuilder(NGNet& net, double minAngle, double minDistance, double maxDistance, double connectivity,
52
int numTries, const RandomDistributor<int>& neighborDist);
53
54
55
56
/** @brief Builds a NGNet using the set values
57
*
58
* @param[in] numNodes Number of iterations (node insertions) to perform
59
* @todo Describe the algorithm
60
*/
61
void createNet(int numNodes, bool gridMode);
62
63
64
private:
65
/** @brief Removes the given node from the list of outer nodes
66
*
67
* @param[in] node The node to remove
68
*/
69
void removeOuterNode(NGNode* node);
70
71
72
/** @brief Checks whether the angle of this node's connections are valid
73
*
74
* Checks whether the connections of the nodes are in common with the value of myMinLinkAngle.
75
*
76
* @param[in] node The node to check connections of
77
* @return Whether the settings allow to connect both nodes
78
*/
79
bool checkAngles(const NGNode* const node);
80
81
82
/** @brief Checks whether connecting the given two nodes complies with the set restrictions
83
*
84
* Checks whether the distance, the angle, and the connectivity is within the defined range
85
* when both nodes would be connected
86
*
87
* @param[in] baseNode The first node of the combination to check
88
* @param[in] newNode The second node of the combination to check
89
* @return Whether the settings allow to connect both nodes
90
*/
91
bool canConnect(NGNode* baseNode, NGNode* newNode);
92
93
94
/** @brief Creates new random node
95
*
96
* Returns true, if creation was successful.
97
*
98
* @param[in] baseNode ?
99
* @todo Describe better
100
*/
101
bool createNewNode(NGNode* baseNode, bool gridMode);
102
103
104
/** @brief finds possible connections between Node and OuterNodes complying with restrictions
105
*
106
* @param[in] node ?
107
* @todo Describe better
108
*/
109
void findPossibleOuterNodes(NGNode* node);
110
111
112
private:
113
/// @brief The network to fill
114
NGNet& myNet;
115
116
/// @brief The list of outer nodes
117
NGNodeList myOuterNodes;
118
119
/// @brief The list of outer links
120
NGEdgeList myOuterLinks;
121
122
// list of possible new connections
123
NGNodeList myConNodes;
124
125
126
/// @name restrictions
127
//@{
128
129
/// @brief Minimum angle allowed between two links
130
double myMinLinkAngle;
131
132
/// @brief Minimum distance allowed between two nodes
133
double myMinDistance;
134
135
/// @brief Maximum distance allowed between two nodes
136
double myMaxDistance;
137
138
/// @brief Probability of connecting to a existing node if possible
139
double myConnectivity;
140
//@}
141
142
143
/// @brief Number of tries to create a new node
144
int myNumTries;
145
146
/// @brief Number of nodes to be created
147
int myNumNodes;
148
149
/// @brief The distribution of number of neighbours
150
RandomDistributor<int> myNeighbourDistribution;
151
152
private:
153
/// @brief Invalidated copy constructor.
154
NGRandomNetBuilder(const NGRandomNetBuilder&);
155
156
/// @brief Invalidated assignment operator.
157
NGRandomNetBuilder& operator=(const NGRandomNetBuilder&);
158
159
};
160
161