Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

randomGeographicalThresholdGraph.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/Array.h>
35 #include <ogdf/basic/Graph.h>
36 #include <ogdf/basic/basic.h>
37 
38 #include <cmath>
39 #include <functional>
40 #include <random>
41 
42 namespace ogdf {
43 
49 
53 
72 template<typename D>
73 void randomGeographicalThresholdGraph(Graph& G, Array<int>& weights, D& dist, double threshold,
74  std::function<double(double)> h, int dimension = 2) {
75  OGDF_ASSERT(dimension >= 1);
76  OGDF_ASSERT(threshold >= 0.0);
77 
78  G.clear();
79  Array<node> nodes(weights.size());
80 
81  // Randomly distribute nodes in a d-dimensional area
82  NodeArray<int> nodeWeights = NodeArray<int>(G);
83  NodeArray<Array<double>> cord(G, Array<double>(dimension));
84  std::minstd_rand rng(randomSeed());
85  for (int i = 0; i < weights.size(); i++) {
86  nodes[i] = G.newNode();
87  nodeWeights[nodes[i]] = weights[i];
88  for (int j = 0; j < dimension; j++) {
89  cord[nodes[i]][j] = dist(rng);
90  }
91  }
92 
93  for (node v : nodes) {
94  for (node w = v->succ(); w; w = w->succ()) {
95  double distance = 0.0;
96  for (int i = 0; i < dimension; i++) {
97  distance += (cord[v][i] - cord[w][i]) * (cord[v][i] - cord[w][i]);
98  }
99  distance = sqrt(distance);
100 
101  if ((nodeWeights[v] + nodeWeights[w]) * h(distance) > threshold) {
102  G.newEdge(v, w);
103  }
104  }
105  }
106 }
107 
125 template<typename D>
126 void randomGeographicalThresholdGraph(Graph& G, Array<int>& weights, D& dist, double threshold,
127  int alpha = 2, int dimension = 2) {
128  randomGeographicalThresholdGraph<D>(
129  G, weights, dist, threshold, [alpha](double d) { return 1 / pow(d, alpha); }, dimension);
130 }
131 
133 
136 }
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
Graph.h
Includes declaration of graph class.
OGDF_ASSERT
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:66
ogdf::Array< int >
ogdf::internal::GraphRegisteredArray
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition: Graph_d.h:658
ogdf::Graph
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:869
ogdf::randomSeed
long unsigned int randomSeed()
Returns a random value suitable as initial seed for a random number engine.
basic.h
Basic declarations, included by all source files.
ogdf::NodeElement::succ
node succ() const
Returns the successor in the list of all nodes.
Definition: Graph_d.h:292
Array.h
Declaration and implementation of Array class and Array algorithms.
ogdf::randomGeographicalThresholdGraph
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...
Definition: randomGeographicalThresholdGraph.h:73
ogdf::Array::size
INDEX size() const
Returns the size (number of elements) of the array.
Definition: Array.h:302
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:240