Loading [MathJax]/extensions/tex2jax.js

Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
randomGeographicalThresholdGraph.h
Go to the documentation of this file.
1
32#pragma once
33
34#include <ogdf/basic/Graph.h>
35
36namespace ogdf {
37
45
47
66template<typename D>
68 std::function<double(double)> h, int dimension = 2) {
70 OGDF_ASSERT(threshold >= 0.0);
71
72 G.clear();
73 Array<node> nodes(weights.size());
74
75 // Randomly distribute nodes in a d-dimensional area
76 NodeArray<int> nodeWeights = NodeArray<int>(G);
78 std::minstd_rand rng(randomSeed());
79 for (int i = 0; i < weights.size(); i++) {
80 nodes[i] = G.newNode();
81 nodeWeights[nodes[i]] = weights[i];
82 for (int j = 0; j < dimension; j++) {
83 cord[nodes[i]][j] = dist(rng);
84 }
85 }
86
87 for (node v : nodes) {
88 for (node w = v->succ(); w; w = w->succ()) {
89 double distance = 0.0;
90 for (int i = 0; i < dimension; i++) {
91 distance += (cord[v][i] - cord[w][i]) * (cord[v][i] - cord[w][i]);
92 }
93 distance = sqrt(distance);
94
95 if ((nodeWeights[v] + nodeWeights[w]) * h(distance) > threshold) {
96 G.newEdge(v, w);
97 }
98 }
99 }
100}
101
119template<typename D>
121 int alpha = 2, int dimension = 2) {
123 G, weights, dist, threshold, [alpha](double d) { return 1 / pow(d, alpha); }, dimension);
124}
125
127
130}
Includes declaration of graph class.
The parameterized class Array implements dynamic arrays of type E.
Definition Array.h:214
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:521
Dynamic arrays indexed with nodes.
Definition NodeArray.h:125
Class for the representation of nodes.
Definition Graph_d.h:177
node succ() const
Returns the successor in the list of all nodes.
Definition Graph_d.h:229
void randomGeographicalThresholdGraph(Graph &G, Array< int > &weights, D &dist, double threshold, std::function< double(double)> h, int dimension=2)
Creates a random geometric graph where edges are created based on their distance and the weight of no...
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition basic.h:41
long unsigned int randomSeed()
Returns a random value suitable as initial seed for a random number engine.
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
The namespace for all OGDF objects.