-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathschedtst_p2.cpp
194 lines (141 loc) · 7.75 KB
/
schedtst_p2.cpp
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#include <iostream>
#include <string>
#include <fstream>
#include "custom_types/ts.h"
#include "p2_key/test_2d_task_p2.h"
#include "p2_key/test_3d_task_p2.h"
#include "p2_key/test_4th_task_p2.h"
#include "p2_key/test_5th_task_p2.h"
#include "p2_key/test_6th_task_p2.h"
#include "p2_key/test_7th_task_p2.h"
#include "p2_key/test_8th_task_p2.h"
#include "p2_key/test_9th_task_p2.h"
#include "p2_key/test_10th_task_p2.h"
#include "p2_key/test_11th_task_p2.h"
#include "p2_key/test_12th_task_p2.h"
#include "p2_key/test_13th_task_p2.h"
#include "p2_key/test_14th_task_p2.h"
using namespace std;
ofstream fileResults;
int main(int argc, char* argv[]) {
TS tsOriginal, ts;
unsigned short m = (unsigned short) strtoul(argv[1], NULL, 0);
unsigned short n = (unsigned short) strtoul(argv[2], NULL, 0);
tsOriginal.n = n;
int C, P;
for (int i = 0; i < n; i++) {
C = (int) strtoul(argv[3+2*i], NULL, 0);
P = (int) strtoul(argv[4+2*i], NULL, 0);
tsOriginal.setTask(i, C, P, P);
}
bool removeDominatedStatesFromMap = (bool) strtoul(argv[3+2*n], NULL, 0);
bool verbose = (bool) strtoul(argv[4+2*n], NULL, 0);
for (int i = 0; i < m; i++) ts.setTask(i, tsOriginal.C[i], tsOriginal.D[i], tsOriginal.T[i]);
unsigned long int savedStatesNum = 0;
unsigned long int visitedStatesNum = 0;
unsigned long int savedStatesNumIncr = 0;
unsigned long int visitedStatesNumIncr = 0;
bool sched = true;
unsigned long int t0;
unsigned long int tExecution_p2;
unsigned long int tExecutionTotal_p2 = 0;
for (int N = m + 1; N <= tsOriginal.n; N++) {
ts.n = N;
ts.setTask(N-1, tsOriginal.C[N-1], tsOriginal.D[N-1], tsOriginal.T[N-1]);
if (verbose) {
cout << endl << "===================" << endl;
cout << "Checking task " << ts.n << endl;
}
switch (N) {
case 2:
t0 = clock();
sched = test_2d_task_p2(verbose, m, ts, removeDominatedStatesFromMap, savedStatesNumIncr, visitedStatesNumIncr);
tExecution_p2 = clock() - t0; tExecutionTotal_p2 += tExecution_p2;
savedStatesNum += savedStatesNumIncr; visitedStatesNum += visitedStatesNumIncr;
break;
case 3:
t0 = clock();
sched = test_3d_task_p2(verbose, m, ts, removeDominatedStatesFromMap, savedStatesNumIncr, visitedStatesNumIncr);
tExecution_p2 = clock() - t0; tExecutionTotal_p2 += tExecution_p2;
savedStatesNum += savedStatesNumIncr; visitedStatesNum += visitedStatesNumIncr;
break;
case 4:
t0 = clock();
sched = test_4th_task_p2(verbose, m, ts, removeDominatedStatesFromMap, savedStatesNumIncr, visitedStatesNumIncr);
tExecution_p2 = clock() - t0; tExecutionTotal_p2 += tExecution_p2;
savedStatesNum += savedStatesNumIncr; visitedStatesNum += visitedStatesNumIncr;
break;
case 5:
t0 = clock();
sched = test_5th_task_p2(verbose, m, ts, removeDominatedStatesFromMap, savedStatesNumIncr, visitedStatesNumIncr);
tExecution_p2 = clock() - t0; tExecutionTotal_p2 += tExecution_p2;
savedStatesNum += savedStatesNumIncr; visitedStatesNum += visitedStatesNumIncr;
break;
case 6:
t0 = clock();
sched = test_6th_task_p2(verbose, m, ts, removeDominatedStatesFromMap, savedStatesNumIncr, visitedStatesNumIncr);
tExecution_p2 = clock() - t0; tExecutionTotal_p2 += tExecution_p2;
savedStatesNum += savedStatesNumIncr; visitedStatesNum += visitedStatesNumIncr;
break;
case 7:
t0 = clock();
sched = test_7th_task_p2(verbose, m, ts, removeDominatedStatesFromMap, savedStatesNumIncr, visitedStatesNumIncr);
tExecution_p2 = clock() - t0; tExecutionTotal_p2 += tExecution_p2;
savedStatesNum += savedStatesNumIncr; visitedStatesNum += visitedStatesNumIncr;
break;
case 8:
t0 = clock();
sched = test_8th_task_p2(verbose, m, ts, removeDominatedStatesFromMap, savedStatesNumIncr, visitedStatesNumIncr);
tExecution_p2 = clock() - t0; tExecutionTotal_p2 += tExecution_p2;
savedStatesNum += savedStatesNumIncr; visitedStatesNum += visitedStatesNumIncr;
break;
case 9:
t0 = clock();
sched = test_9th_task_p2(verbose, m, ts, removeDominatedStatesFromMap, savedStatesNumIncr, visitedStatesNumIncr);
tExecution_p2 = clock() - t0; tExecutionTotal_p2 += tExecution_p2;
savedStatesNum += savedStatesNumIncr; visitedStatesNum += visitedStatesNumIncr;
break;
case 10:
t0 = clock();
sched = test_10th_task_p2(verbose, m, ts, removeDominatedStatesFromMap, savedStatesNumIncr, visitedStatesNumIncr);
tExecution_p2 = clock() - t0; tExecutionTotal_p2 += tExecution_p2;
savedStatesNum += savedStatesNumIncr; visitedStatesNum += visitedStatesNumIncr;
break;
case 11:
t0 = clock();
sched = test_11th_task_p2(verbose, m, ts, removeDominatedStatesFromMap, savedStatesNumIncr, visitedStatesNumIncr);
tExecution_p2 = clock() - t0; tExecutionTotal_p2 += tExecution_p2;
savedStatesNum += savedStatesNumIncr; visitedStatesNum += visitedStatesNumIncr;
break;
case 12:
t0 = clock();
sched = test_12th_task_p2(verbose, m, ts, removeDominatedStatesFromMap, savedStatesNumIncr, visitedStatesNumIncr);
tExecution_p2 = clock() - t0; tExecutionTotal_p2 += tExecution_p2;
savedStatesNum += savedStatesNumIncr; visitedStatesNum += visitedStatesNumIncr;
break;
case 13:
t0 = clock();
sched = test_13th_task_p2(verbose, m, ts, removeDominatedStatesFromMap, savedStatesNumIncr, visitedStatesNumIncr);
tExecution_p2 = clock() - t0; tExecutionTotal_p2 += tExecution_p2;
savedStatesNum += savedStatesNumIncr; visitedStatesNum += visitedStatesNumIncr;
break;
case 14:
t0 = clock();
sched = test_14th_task_p2(verbose, m, ts, removeDominatedStatesFromMap, savedStatesNumIncr, visitedStatesNumIncr);
tExecution_p2 = clock() - t0; tExecutionTotal_p2 += tExecution_p2;
savedStatesNum += savedStatesNumIncr; visitedStatesNum += visitedStatesNumIncr;
break;
default: cout << "No function defined to test " << N << " tasks!" << endl;
}
if (!sched) break;
}
const char* fileName = (argv[2*(tsOriginal.n)+5]);
fileResults.open(fileName, ios::app);
fileResults << "\t" << sched << "\t" << tExecutionTotal_p2 << "\t" << savedStatesNum;
fileResults.close();
if (!removeDominatedStatesFromMap) cout << "Sporadic burm2018 p2 (no r.):\t" << (float)(tExecutionTotal_p2*100/CLOCKS_PER_SEC)/100 << " sec, \t / " << savedStatesNum << " saved states" << " \t / " << visitedStatesNum << " visited states";
else cout << "Sporadic burm2018 p2:\t\t" << (float)(tExecutionTotal_p2*100/CLOCKS_PER_SEC)/100 << " sec, \t / " << savedStatesNum << " saved states" << " \t / " << visitedStatesNum << " visited states";
if (sched) cout << " \t / SCHED" << endl;
else cout << " \t / UNSCHED" << endl;
return sched;
}