-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraphcreation.h
More file actions
57 lines (47 loc) · 1.6 KB
/
graphcreation.h
File metadata and controls
57 lines (47 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef GRAPHCREATION_H
#define GRAPHCREATION_H
#include <NetworKit/graph/Graph.h>
#include <memory>
#include <algorithm>
#include <cmath>
using namespace NetworKit;
using namespace std;
unsigned int randint(unsigned int min, unsigned int max) {
return rand()%(max-min + 1) + min;
}
unique_ptr<Graph> createConnectedGraph(unsigned int nodes, unsigned int degreeConnection) {
srand(time(0));
unique_ptr<Graph> g = make_unique<Graph>(nodes, true, false);
for(unsigned int i = 1; i < nodes; ++i) {
auto connectTo = randint(0u, i - 1);
g->addEdge(connectTo, i, static_cast<edgeweight>(rand() % 100 + 1));
for(unsigned int j; j < randint(0u, degreeConnection); ++j) {
auto connectTo = randint(0u, i - 1);
g->addEdge(connectTo, i, static_cast<edgeweight>(rand() % 100 + 1));
}
}
return g;
}
unique_ptr<Graph> createCompleteGraph(size_t nodes) {
srand(time(0));
unique_ptr<Graph> g = make_unique<Graph>(nodes, true, false);
for(size_t i = 0; i < nodes - 1; ++i) {
for(size_t j = i + 1; j < nodes; ++j) {
g->addEdge(i,j, static_cast<edgeweight>(rand() % 100 + 1));
}
}
return g;
}
unique_ptr<Graph> createSquareMeshGraph(size_t width) {
unique_ptr<Graph> g = make_unique<Graph>(width * width, true, false);
for(size_t i = 0; i < (width * width)- 1; ++i) {
auto i_x = i % width;
auto i_y = i / width;
for(size_t j = i + 1; j < width * width; ++j) {
auto j_x = j % width;
auto j_y = j / width;
}
}
return g;
}
#endif // GRAPHCREATION_H