-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDenseGraph.cpp
More file actions
162 lines (156 loc) · 3.54 KB
/
Copy pathDenseGraph.cpp
File metadata and controls
162 lines (156 loc) · 3.54 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# include "DenseGraph.h"
// A constructor
Rdensegraph :: Rdensegraph()
{
N = 0;
generator.seed(system_clock :: now().time_since_epoch().count());
}
//////
// A function that generates a random dense graph
void Rdensegraph :: generate(int n, Timer &t1, int d, float ro)
{
bool a[n][n];
if(ro == -1)
{
array <float, 3> intervals {0.0, 0.7, 1.0};
array <float, 3> weights {0.2, 10.0, 0.2};
piecewise_linear_distribution <float> roset(intervals.begin(), intervals.end(), weights.begin());
ro = roset(generator);
}
discrete_distribution <int> edge {(double)(1 - ro), (double)(ro)};
for(int i = 0; i < n; i++)
for(int j = i + 1; j < n; j++)
{
a[i][j] = a[j][i] = edge(generator);
t1.time(2);
}
for(int i = 0; i < n; i++)
{
a[i][i] = 0;
t1.time(1);
}
if(d)
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
{
fout << a[i][j] << " \n"[j == n - 1];
t1.time(1);
}
}
else
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
{
fout << a[i][j];
t1.time(1);
}
fout << '\n';
}
}
// A function that generates random dense graph test case files
void Rdensegraph :: setCase(string &s, int T, int t, int n, float ro, int d, int sz, string &folder_name)
{
int pt = FileOp :: printT(t);
cout << "Generating dense_graph test files: " << '\n';
for(int i = 0; i < T; i++)
{
FileOp :: setFile(folder_name, s, i, fout);
vector <int> times = numOp :: giveRints(t, n, sz);
N = times.size();
if(pt)
fout << N << '\n';
int tcnt = 0;
for(int j = 0; j < N; j++)
tcnt += times[j] * times[j];
Timer t1(2 * tcnt);
for(int j = 0; j < N; j++)
{
fout << times[j] << '\n';
generate(times[j], t1, d, ro);
}
fout.close();
}
cout << "dense_graph generation completed." << '\n';
}
// A constructor
Rdensedgraph :: Rdensedgraph()
{
N = 0;
generator.seed(system_clock :: now().time_since_epoch().count());
}
// A function that generates a random dense digraph
void Rdensedgraph :: generate(int n, Timer &t1, int d, float ro)
{
bool a[n][n];
if(ro == -1)
{
array <float, 3> intervals {0.0, 0.7, 1.0};
array <float, 3> weights {0.2, 10.0, 0.2};
piecewise_linear_distribution <float> roset(intervals.begin(), intervals.end(), weights.begin());
ro = roset(generator);
}
discrete_distribution <int> edge {(double)(1 - ro), (double)(ro)};
for(int i = 0; i < n; i++)
for(int j = i + 1; j < n; j++)
{
a[i][j] = edge(generator);
t1.time(1);
}
for(int i = 1; i < n; i++)
for(int j = 0; j < i; j++)
{
a[i][j] = rand() % 2;
t1.time(1);
}
for(int i = 0; i < n; i++)
{
a[i][i] = 0;
t1.time(1);
}
if(d)
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
{
fout << a[i][j] << " \n"[j == n - 1];
t1.time(1);
}
}
else
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
{
fout << a[i][j];
t1.time(1);
}
fout << '\n';
}
}
// A function that generates random dense digraph test case files
void Rdensedgraph :: setCase(string &s, int T, int t, int n, float ro, int d, int sz, string &folder_name)
{
int pt = FileOp :: printT(t);
cout << "Generating dense_dgraph test files: " << '\n';
for(int i = 0; i < T; i++)
{
FileOp :: setFile(folder_name, s, i, fout);
vector <int> times = numOp :: giveRints(t, n, sz);
N = times.size();
if(pt)
fout << N << '\n';
int tcnt = 0;
for(int j = 0; j < N; j++)
tcnt += times[j] * times[j];
Timer t1(2 * tcnt);
for(int j = 0; j < N; j++)
{
fout << times[j] << '\n';
generate(times[j], t1, d, ro);
}
fout.close();
}
cout << "dense_dgraph generation completed." << '\n';
}