-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
288 lines (264 loc) · 8.14 KB
/
main.cpp
File metadata and controls
288 lines (264 loc) · 8.14 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
/************************************************************************************************
* File: main.cpp
* Author: Stephen Thomson & Stephen Carter & Abbey DuBois
* Date: 3/14/2024
* Description: This is the main file for running the project
*************************************************************************************************/
#include <iostream>
#include "Schedule.h"
#include "AlgorithmA.h"
#include "edf_algorithm.h"
#include "ScheduleLLF.h"
string getFileName()
{
string fileName;
cout << "Please enter the name of the file you would like to read in: ";
cin >> fileName;
return fileName;
}
string getWriteFileName()
{
string fileName;
cout << "Please enter the name of the file you would like to write to: ";
cin >> fileName;
return fileName;
}
int main(int argc, char* argv[])
{
// Create objects and variables
Schedule schedule = Schedule();
AlgorithmA algoA = AlgorithmA();
EDF_Algorithm edf = EDF_Algorithm();
ScheduleLLF llf = ScheduleLLF();
int selection;
string fileName;
string writeFileName;
bool invalid = true;
bool exit = false;
int printWrite = 0;
int numRuns = 0;
int chosenTaskSet = 0;
int chosenAlgorithm = 0;
// While not exit:
while(!exit)
{
while(invalid)
{
// Selection of what file to read or enter own text file or exit.
cout << "What File would you like to read in for the Task Sets?" << endl;
cout << "[1] Small task set file\n"
<< "[2] Task sets from class\n"
<< "[3] Large Task Set File\n"
<< "[4] Personal (needs to be added to Resource files)\n"
<< "[5] Exit\n";
cin >> selection;
switch(selection)
{
case 1:
fileName = "TestTaskSet.txt";
invalid = false;
break;
case 2:
fileName = "TaskSets.txt";
invalid = false;
break;
case 3:
fileName = "RTaskSets.txt";
invalid = false;
break;
case 4:
fileName = getFileName();
invalid = false;
break;
case 5:
exit = true;
invalid = false;
break;
default:
cout << "Invalid selection. Please try again." << endl;
break;
}
}
if(exit)
{
break;
}
// Read in the file, if it fails, return to beginning
if(!schedule.readTaskSets(fileName))
{
cout << "File read failed. Please try again." << endl;
invalid = true;
continue;
}
invalid = true;
// Print or Write file
while(invalid)
{
cout << "Would you like to print the Task Sets or write the results to a file?" << endl;
cout << "[1] Print Task Sets\n"
<< "[2] Write Results\n"
<< "[3] Exit\n";
cin >> selection;
switch(selection)
{
case 1:
printWrite = 1;
invalid = false;
break;
case 2:
printWrite = 2;
writeFileName = getWriteFileName();
invalid = false;
break;
case 3:
invalid = false;
exit = true;
break;
default:
cout << "Invalid selection. Please try again." << endl;
break;
}
}
if(exit)
{
break;
}
invalid = true;
// Choose a specific task set or all of them
// Select specific task or set to 0 for all
// Check to make sure the task set exists
while(invalid)
{
cout << "Which Task Set would you like to run?" << endl;
cout << "Enter 0 for all Task Sets" << endl;
cin >> chosenTaskSet;
if(chosenTaskSet < 0 || chosenTaskSet > schedule.getNumTaskSets())
{
cout << "Invalid Task Set. Please try again." << endl;
}
else
{
invalid = false;
}
}
invalid = true;
// Choose a specific Algorithm or all of them
// Select specific algorithm or set to 0 for all
while(invalid)
{
cout << "Which Algorithm would you like to run?" << endl;
cout << "[1] EDF\n"
<< "[2] LLF\n"
<< "[3] Algorithm A\n"
<< "[4] All\n";
cin >> chosenAlgorithm;
if(chosenAlgorithm < 1 || chosenAlgorithm > 4)
{
cout << "Invalid Algorithm. Please try again." << endl;
}
else
{
invalid = false;
}
}
invalid = true;
// Single run or multiple runs with average time
// If average, how many runs
while(invalid)
{
cout << "Would you like to run a single run or multiple runs with average time?" << endl;
cout << "[1] Single Run\n"
<< "[2] Multiple Runs\n";
cin >> selection;
if(selection < 1 || selection > 2)
{
cout << "Invalid selection. Please try again." << endl;
}
else if (selection == 2)
{
cout << "How many runs would you like to run?" << endl;
cin >> numRuns;
invalid = false;
}
else
{
numRuns = 1;
invalid = false;
}
}
// Run Program
if (printWrite == 1)
{
if (chosenTaskSet > 0)
{
if (chosenAlgorithm == 1)
{
schedule.printScheduleEDF(chosenTaskSet-1, numRuns, &edf);
}
else if (chosenAlgorithm == 2)
{
schedule.printScheduleLLF(chosenTaskSet-1, numRuns, &llf);
}
else if (chosenAlgorithm == 3)
{
schedule.printScheduleAlgorithmA(chosenTaskSet-1, numRuns, &algoA);
}
else
{
schedule.printSchedules(chosenTaskSet-1, numRuns, &edf, &llf, &algoA);
}
}
else
{
if (chosenAlgorithm == 1)
{
schedule.printScheduleEDFAll(numRuns, &edf);
}
else if (chosenAlgorithm == 2)
{
schedule.printScheduleLLFAll(numRuns, &llf);
}
else if (chosenAlgorithm == 3)
{
schedule.printScheduleAlgorithmAAll(numRuns, &algoA);
}
else
{
schedule.printSchedulesAll(numRuns, &edf, &llf, &algoA);
}
}
}
else if (printWrite == 2)
{
schedule.writeResults(writeFileName, numRuns, &edf, &llf, &algoA);
}
invalid = true;
// Ask if run again or exit
while (invalid)
{
cout << "Would you like to run the program again?" << endl;
cout << "[1] Yes\n"
<< "[2] No\n";
cin >> selection;
if (selection < 1 || selection > 2)
{
cout << "Invalid selection. Please try again." << endl;
}
else
{
invalid = false;
}
}
if (selection == 2)
{
exit = true;
}
else
{
invalid = true;
schedule.clearTaskSets();
continue;
}
}
return 0;
}