-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntervalTypes.cpp
More file actions
179 lines (170 loc) · 4.15 KB
/
Copy pathIntervalTypes.cpp
File metadata and controls
179 lines (170 loc) · 4.15 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# include "IntervalTypes.h"
// A constructor
Rintervals :: Rintervals()
{
a = b = 0;
generator.seed(system_clock :: now().time_since_epoch().count());
}
// A function that generates a random interval
void Rintervals :: generate(int l, int r)
{
uniform_int_distribution <int> d1(l, r - 1);
a = d1(generator);
uniform_int_distribution <int> d2(a, r);
b = d2(generator);
}
// A function that generates interval test case files
void Rintervals :: setCase(string &s, int T, int t, int n, int l, int r, int sz, string &folder_name)
{
int pt = FileOp :: printT(t);
cout << "Generating interval 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);
if(pt)
fout << times.size() << '\n';
int tcnt = 0;
for(int j = 0; j < (int)times.size(); j++)
tcnt += times[j];
Timer t1(2 * tcnt);
for(int j = 0; j < (int)times.size(); j++)
{
fout << times[j] << '\n';
for(int k = 0; k < times[j]; k++)
{
generate(l, r);
fout << a << ' ' << b << '\n';
t1.time(2);
}
}
fout.close();
}
cout << "interval generation completed." << '\n';
}
// A constructor
Ruintervals :: Ruintervals()
{
N = 0;
generator.seed(system_clock :: now().time_since_epoch().count());
}
// A function that generates a random unique interval set
void Ruintervals :: generate(int n, Timer &t1, int l, int r)
{
g.clear();
uniform_int_distribution <int> d1(l, r);
while((int)g.size() < 2 * n)
{
int t = g.size();
int rn = d1(generator);
g.insert(rn);
if((int)g.size() > t)
t1.time(1);
}
vector <int> gg;
for(auto i : g)
{
gg.push_back(i);
t1.time(1);
}
shuffle(gg.begin(), gg.end(), default_random_engine(system_clock :: now().time_since_epoch().count()));
for(int i = 0; i < (int)gg.size(); i += 2)
{
int x = gg[i], y = gg[i + 1];
fout << min(x, y) << ' ' << max(x, y) << '\n';
t1.time(2);
}
}
// A function that generates unique interval test case files
void Ruintervals :: setCase(string &s, int T, int t, int n, int l, int r, int sz, string &folder_name)
{
int pt = FileOp :: printT(t);
cout << "Generating uintervals 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];
Timer t1(6 * tcnt);
for(int j = 0; j < N; j++)
{
fout << times[j] << '\n';
generate(times[j], t1, l, r);
}
fout.close();
}
cout << "uintervals generation completed." << '\n';
}
// A constructor
Rpartition :: Rpartition()
{
N = 0;
generator.seed(system_clock :: now().time_since_epoch().count());
}
// A function that generates a random partition
void Rpartition :: generate(int n, Timer &t1, int l, int r)
{
g.clear();
uniform_int_distribution <int> d1(l, r - 1);
while((int)g.size() < n - 1)
{
int t = g.size();
int rn = d1(generator);
g.insert(rn);
if((int)g.size() > t)
t1.time(2);
}
vector <int> gg;
gg.push_back(l);
t1.time(4);
for(auto i : g)
{
gg.push_back(i);
gg.push_back(i + 1);
t1.time(2);
}
gg.push_back(r);
vector <pair <int, int> > ggg;
for(int i = 0; i < (int)gg.size(); i += 2)
{
int x = gg[i], y = gg[i + 1];
ggg.push_back(make_pair(x, y));
t1.time(2);
}
shuffle(ggg.begin(), ggg.end(), default_random_engine(system_clock :: now().time_since_epoch().count()));
for(auto i : ggg)
{
t1.time(1);
fout << i.first << ' ' << i.second << '\n';
}
}
// A function that generates partition test case files
void Rpartition :: setCase(string &s, int T, int t, int l, int r, int sz, string &folder_name)
{
int pt = FileOp :: printT(t);
cout << "Generating partition test files: " << '\n';
for(int i = 0; i < T; i++)
{
FileOp :: setFile(folder_name, s, i, fout);
vector <int> times = numOp :: giveRints(t, (r - l) / 11, sz);
N = times.size();
if(pt)
fout << N << '\n';
int tcnt = 0;
for(int j = 0; j < N; j++)
tcnt += times[j];
Timer t1(7 * tcnt);
for(int j = 0; j < N; j++)
{
fout << times[j] << '\n';
generate(times[j], t1, l, r);
}
fout.close();
}
cout << "partition generation completed." << '\n';
}