-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSchedule.cpp
More file actions
705 lines (635 loc) · 30.8 KB
/
Schedule.cpp
File metadata and controls
705 lines (635 loc) · 30.8 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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
/************************************************************************************************
* File: Schedule.h
* Author: Stephen Thomson & Stephen Carter & Abbey DuBois
* Date: 3/14/2024
* Description: This is the file for Schedule class.
* This class is used to store a list of tasksets and perform operations on them.
*************************************************************************************************/
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <chrono>
#include <thread>
#include "TaskSet.h"
#include "Task.h"
#include "Schedule.h"
using timer = std::chrono::system_clock;
using namespace std;
Schedule::Schedule()
{
m_tasksets = vector<TaskSet>();
m_processors = 0;
m_lcm = 0;
}
Schedule::~Schedule()
{
m_tasksets.clear();
}
Schedule& Schedule::operator=(const Schedule& schedule)
{
if (this == &schedule)
{
return *this;
}
m_tasksets = schedule.m_tasksets;
return *this;
}
void Schedule::addTaskSet(TaskSet taskset)
{
m_tasksets.push_back(taskset);
}
void Schedule::removeTaskSet(int index)
{
m_tasksets.erase(m_tasksets.begin() + index);
}
void Schedule::printTaskSets()
{
for (int i = 0; i < m_tasksets.size(); i++)
{
cout << "Task Set " << i << endl;
m_tasksets[i].printTasks();
}
}
void Schedule::printTaskSet(int index)
{
m_tasksets[index].printTasks();
}
// Reads in the task sets from a file
bool Schedule::readTaskSets(string filename)
{
vector<TaskSet> taskSets;
ifstream file(filename);
if (!file)
{
cerr << "Error: Unable to open file " << filename << endl;
return false;
}
string line;
while (getline(file, line))
{
if (line == "Begin")
{
int num_tasks;
int num_processors;
bool is_real_time;
file >> num_tasks >> num_processors;
char is_real_time_char;
file >> is_real_time_char;
if (is_real_time_char == 'Y')
{
is_real_time = true;
}
else
{
is_real_time = false;
}
file.ignore(); // Ignore the newline character
TaskSet taskSet;
taskSet.setNumProcessors(num_processors);
taskSet.setNumTasks(num_tasks);
taskSet.setPreemptive(is_real_time);
for (int i = 0; i < num_tasks; ++i) {
int count = 0;
int start_time, computation, soft_deadline, hard_deadline, period;
char comma;
std::string taskName = "T" + std::to_string(i + 1);
file >> start_time >> comma >> computation >> comma >> soft_deadline >> comma >> hard_deadline >> comma >> period;
Task task(taskName, start_time, computation, soft_deadline, hard_deadline, period);
taskSet.addTask(task);
}
taskSets.push_back(taskSet);
}
}
file.close();
m_tasksets = taskSets;
return true;
}
// Writes the results of the algorithms to a file
void Schedule::writeResults(string filename, int numruns, Schedule* EDF, Schedule* LLF, Schedule* AlgorithmA)
{
string schedule = "";
// Open the file for writing
ofstream outFile(filename);
if (!outFile.is_open()) {
cerr << "Error: Unable to open file " << filename << endl;
return;
}
for (int i = 0; i < m_tasksets.size(); i++)
{
m_processors = m_tasksets[i].getNumProcessors();
m_lcm = m_tasksets[i].getLCM();
setAlgorithmsMemberVariables(EDF);
setAlgorithmsMemberVariables(LLF);
setAlgorithmsMemberVariables(AlgorithmA);
EDF->setTaskSet(0, m_tasksets[i]);
LLF->setTaskSet(0, m_tasksets[i]);
AlgorithmA->setTaskSet(0, m_tasksets[i]);
outFile << "* Task Set " << i+1 << endl;
outFile << "****************************************************************************************************" << endl;
outFile << "* Tasks: " << m_tasksets[i].getNumTasks() << endl;
outFile << "* Processors: " << m_tasksets[i].getNumProcessors() << endl;
outFile << "* Utilization Rate: " << m_tasksets[i].calculateTotalUtilizationRate() << endl;
outFile << "* USI: " << m_tasksets[i].USI() << endl;
outFile << "* EUSI: " << m_tasksets[i].EUSI() << endl;
outFile << "* LCM: " << m_tasksets[i].getLCM() << endl;
outFile << "* Preemptive: " << (m_tasksets[i].getPreemptive() ? "True" : "False") << endl;
for (int j = 0; j < m_tasksets[i].getNumTasks(); j++)
{
outFile << "* " << m_tasksets[i].getTask(j).getName() << ", S: " << m_tasksets[i].getTask(j).getStartTime() << ", C: " << m_tasksets[i].getTask(j).getComputationTime() << ", HD: " << m_tasksets[i].getTask(j).getHardDeadline() << ", SD: " << m_tasksets[i].getTask(j).getSoftDeadline() << ", P: " << m_tasksets[i].getTask(j).getPeriod() << endl;
}
outFile << "* \n" << "*---------------------------------------------------------------------------------------------------" << endl;
outFile << "* EDF: " << endl;
schedule = EDF->runEDF_Algorithm();
outFile << "* " << schedule << endl;
outFile << "* " << endl;
double timeE = getAverageTimeEDF(i, numruns, EDF);
outFile << "* Number of runs: " << numruns << endl;
outFile << "* Average Time: " << timeE << " Microseconds" << endl;
outFile << "* \n" << "*---------------------------------------------------------------------------------------------------" << endl;
outFile << "* LLF: " << endl;
// Instantiate LLF object
schedule = LLF->CheckLLFSchedule();
outFile << "* " << schedule << endl;
double timeL = getAverageTimeLLF(i, numruns, LLF);
outFile << "* Number of runs: " << numruns << endl;
outFile << "* Average Time: " << timeL << " Microseconds" << endl;
outFile << "* \n" << "*---------------------------------------------------------------------------------------------------" << endl;
outFile << "* Algorithm-A: " << endl;
schedule = AlgorithmA->algorithmASchedule();
outFile << "* " << schedule << endl;
double timeA = getAverageTimeAlgorithmA(i, numruns, AlgorithmA);
outFile << "* Number of runs: " << numruns << endl;
outFile << "* Average Time: " << timeA << " Microseconds" << endl;
outFile << "* \n" << "****************************************************************************************************" << endl;
outFile << "\n\n" << endl;
}
// Close the file
outFile.close();
}
void Schedule::clearTaskSets()
{
m_tasksets.clear();
}
int Schedule::getNumTaskSets()
{
return m_tasksets.size();
}
TaskSet Schedule::getTaskSet(int index)
{
return m_tasksets[index];
}
vector<TaskSet> Schedule::getTaskSets()
{
return m_tasksets;
}
void Schedule::setTaskSet(int index, TaskSet taskset)
{
m_tasksets[index] = taskset;
}
void Schedule::setTaskSets(vector<TaskSet> tasksets)
{
m_tasksets = tasksets;
}
// getTimeEDF
// This functions runs the EDF algorithm on the taskset indicated, starts a timer before, and stops it after the algorithm is done
// It returns the time it took to run the algorithm
double Schedule::getTimeEDF(int index, Schedule* EDF)
{
EDF->m_processors = m_tasksets[index].getNumProcessors();
EDF->m_lcm = m_tasksets[index].getLCM();
EDF->setTaskSet(0, m_tasksets[index]);
auto start = timer::now();
EDF->runEDF_Algorithm();
auto end = timer::now();
return std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
}
//getTimeLLF
//This functions runs the LLF algorithm on the taskset indicated, starts a timer before, and stops it after the algorithm is done
//It returns the time it took to run the algorithm
double Schedule::getTimeLLF(int index, Schedule* LLF)
{
LLF->m_processors = m_tasksets[index].getNumProcessors();
LLF->m_lcm = m_tasksets[index].getLCM();
;
auto start = timer::now();
LLF->CheckLLFSchedule();
auto end = timer::now();
return std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
}
//getTimeAlgorithmA
//This functions runs the Algorithm A on the taskset indicated, starts a timer before, and stops it after the algorithm is done
//It returns the time it took to run the algorithm
double Schedule::getTimeAlgorithmA(int index, Schedule* AlgorithmA)
{
AlgorithmA->m_processors = m_tasksets[index].getNumProcessors();
AlgorithmA->m_lcm = m_tasksets[index].getLCM();
AlgorithmA->setTaskSet(0, m_tasksets[index]);
auto start = timer::now();
AlgorithmA->algorithmASchedule();
auto end = timer::now();
return std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
}
//getAverageTimeEDF(int numruns) Runs numruns and averages times
//This function runs the EDF algorithm on the taskset indicated numruns times, and averages the time it took to run the algorithm
//It returns the average time it took to run the algorithm
double Schedule::getAverageTimeEDF(int index, int numruns, Schedule* EDF)
{
int sum = 0;
for (int i = 0; i < numruns; i++)
{
sum += getTimeEDF(index, EDF);
}
return sum / numruns;
}
//getAverageTimeLLF
//This function runs the LLF algorithm on the taskset indicated numruns times, and averages the time it took to run the algorithm
//It returns the average time it took to run the algorithm
double Schedule::getAverageTimeLLF(int index, int numruns, Schedule* LLF)
{
int sum = 0;
for (int i = 0; i < numruns; i++)
{
sum += getTimeLLF(index, LLF);
}
return sum / numruns;
}
//getAverageTimeAlgorithmA
//This function runs the Algorithm A on the taskset indicated numruns times, and averages the time it took to run the algorithm
//It returns the average time it took to run the algorithm
double Schedule::getAverageTimeAlgorithmA(int index, int numruns, Schedule* AlgorithmA)
{
int sum = 0;
for (int i = 0; i < numruns; i++)
{
sum += getTimeAlgorithmA(index, AlgorithmA);
}
return sum / numruns;
}
//printScheduleEDF prints one edf schedule of index
void Schedule::printScheduleEDF(int index, int numruns, Schedule* EDF)
{
m_processors = m_tasksets[index].getNumProcessors();
m_lcm = m_tasksets[index].getLCM();
setAlgorithmsMemberVariables(EDF);
EDF->setTaskSet(0, m_tasksets[index]);
cout << "* EDF Schedule for Task Set " << index+1 << endl;
cout << "****************************************************************************************************" << endl;
cout << "* Tasks: " << m_tasksets[index].getNumTasks() << endl;
cout << "* Processors: " << m_processors << endl;
cout << "* Utilization Rate: " << m_tasksets[index].calculateTotalUtilizationRate() << endl;
cout << "* USI: " << m_tasksets[index].USI() << endl;
cout << "* EUSI: " << m_tasksets[index].EUSI() << endl;
cout << "* LCM: " << m_lcm << endl;
cout << "* Preemptive: " << (m_tasksets[index].getPreemptive() ? "True" : "False") << endl;
for (int i = 0; i < m_tasksets[index].getNumTasks(); i++)
{
cout << "* " << m_tasksets[index].getTask(i).getName() << ", S: " << m_tasksets[index].getTask(i).getStartTime() << ", C: " << m_tasksets[index].getTask(i).getComputationTime() << ", HD: " << m_tasksets[index].getTask(i).getHardDeadline() << ", SD: " << m_tasksets[index].getTask(i).getSoftDeadline() << ", P: " << m_tasksets[index].getTask(i).getPeriod() << endl;
}
cout << "* \n" << "*---------------------------------------------------------------------------------------------------" << endl;
cout << "* EDF: " << endl;
string schedule = EDF->runEDF_Algorithm();
cout << "* " << schedule << endl;
cout << "* " << endl;
int time = getAverageTimeEDF(index, numruns, EDF);
cout << "* Average Time: " << time << " Microseconds" << endl;
cout << "* \n" << "****************************************************************************************************" << endl;
cout << "\n\n" << endl;
}
//printScheduleLLF
//This function prints one LLF schedule of index
void Schedule::printScheduleLLF(int index, int numruns, Schedule* LLF)
{
m_processors = m_tasksets[index].getNumProcessors();
m_lcm = m_tasksets[index].getLCM();
setAlgorithmsMemberVariables(LLF);
LLF->setTaskSet(0, m_tasksets[index]);
cout << "* LLF Schedule for Task Set " << index+1 << endl;
cout << "****************************************************************************************************" << endl;
cout << "* Tasks: " << m_tasksets[index].getNumTasks() << endl;
cout << "* Processors: " << m_processors<< endl;
cout << "* Utilization Rate: " << m_tasksets[index].calculateTotalUtilizationRate() << endl;
cout << "* USI: " << m_tasksets[index].USI() << endl;
cout << "* EUSI: " << m_tasksets[index].EUSI() << endl;
cout << "* LCM: " << m_lcm << endl;
cout << "* Preemptive: " << (m_tasksets[index].getPreemptive() ? "True" : "False") << endl;
for (int i = 0; i < m_tasksets[index].getNumTasks(); i++)
{
cout << "* " << m_tasksets[index].getTask(i).getName() << ", S: " << m_tasksets[index].getTask(i).getStartTime() << ", C: " << m_tasksets[index].getTask(i).getComputationTime() << ", HD: " << m_tasksets[index].getTask(i).getHardDeadline() << ", SD: " << m_tasksets[index].getTask(i).getSoftDeadline() << ", P: " << m_tasksets[index].getTask(i).getPeriod() << endl;
}
cout << "* \n" << "*---------------------------------------------------------------------------------------------------" << endl;
cout << "* LLF: " << endl;
string schedule = LLF->CheckLLFSchedule();
cout << "* " << schedule << endl;
cout << "* " << endl;
int time = getAverageTimeLLF(index, numruns, LLF);
cout << "* Average Time: " << time << " Microseconds" << endl;
cout << "* \n" << "****************************************************************************************************" << endl;
cout << "\n\n" << endl;
}
//printScheduleAlgorithmA
//This function prints one Algorithm A schedule of index
void Schedule::printScheduleAlgorithmA(int index, int numruns, Schedule* AlgorithmA)
{
m_processors = m_tasksets[index].getNumProcessors();
m_lcm = m_tasksets[index].getLCM();
setAlgorithmsMemberVariables(AlgorithmA);
AlgorithmA->setTaskSet(0, m_tasksets[index]);
cout << "* Algorithm-A Schedule for Task Set " << index+1 << endl;
cout << "****************************************************************************************************" << endl;
cout << "* Tasks: " << m_tasksets[index].getNumTasks() << endl;
cout << "* Processors: " << m_processors << endl;
cout << "* Utilization Rate: " << m_tasksets[index].calculateTotalUtilizationRate() << endl;
cout << "* USI: " << m_tasksets[index].USI() << endl;
cout << "* EUSI: " << m_tasksets[index].EUSI() << endl;
cout << "* LCM: " << m_lcm << endl;
cout << "* Preemptive: " << (m_tasksets[index].getPreemptive() ? "True" : "False") << endl;
for (int i = 0; i < m_tasksets[index].getNumTasks(); i++)
{
cout << "* " << m_tasksets[index].getTask(i).getName() << ", S: " << m_tasksets[index].getTask(i).getStartTime() << ", C: " << m_tasksets[index].getTask(i).getComputationTime() << ", HD: " << m_tasksets[index].getTask(i).getHardDeadline() << ", SD: " << m_tasksets[index].getTask(i).getSoftDeadline() << ", P: " << m_tasksets[index].getTask(i).getPeriod() << endl;
}
cout << "* \n" << "*---------------------------------------------------------------------------------------------------" << endl;
cout << "* Algorithm-A: " << endl;
cout << "* " << AlgorithmA->algorithmASchedule() << endl;
cout << "* " << endl;
int time = getAverageTimeAlgorithmA(index, numruns, AlgorithmA);
cout << "* Average Time: " << time << " Microseconds" << endl;
cout << "* \n" << "****************************************************************************************************" << endl;
cout << "\n\n" << endl;
}
//printSchedules prints schedules of all three algorithms for index
void Schedule::printSchedules(int index, int numruns, Schedule* EDF, Schedule* LLF, Schedule* AlgorithmA)
{
m_processors = m_tasksets[index].getNumProcessors();
m_lcm = m_tasksets[index].getLCM();
setAlgorithmsMemberVariables(EDF);
setAlgorithmsMemberVariables(LLF);
setAlgorithmsMemberVariables(AlgorithmA);
EDF->setTaskSet(0, m_tasksets[index]);
LLF->setTaskSet(0, m_tasksets[index]);
AlgorithmA->setTaskSet(0, m_tasksets[index]);
cout << "* Task Set " << index+1 << endl;
cout << "****************************************************************************************************" << endl;
cout << "* Tasks: " << m_tasksets[index].getNumTasks() << endl;
cout << "* Processors: " << m_processors << endl;
cout << "* Utilization Rate: " << m_tasksets[index].calculateTotalUtilizationRate() << endl;
cout << "* USI: " << m_tasksets[index].USI() << endl;
cout << "* EUSI: " << m_tasksets[index].EUSI() << endl;
cout << "* LCM: " << m_lcm << endl;
cout << "* Preemptive: " << (m_tasksets[index].getPreemptive() ? "True" : "False") << endl;
for (int i = 0; i < m_tasksets[index].getNumTasks(); i++)
{
cout << "* " << m_tasksets[index].getTask(i).getName() << ", S: " << m_tasksets[index].getTask(i).getStartTime() << ", C: " << m_tasksets[index].getTask(i).getComputationTime() << ", HD: " << m_tasksets[index].getTask(i).getHardDeadline() << ", SD: " << m_tasksets[index].getTask(i).getSoftDeadline() << ", P: " << m_tasksets[index].getTask(i).getPeriod() << endl;
}
cout << "* \n" << "*---------------------------------------------------------------------------------------------------" << endl;
cout << "* EDF: " << endl;
string schedule = EDF->runEDF_Algorithm();
cout << "* " << schedule << endl;
cout << "* " << endl;
int timeE = getAverageTimeEDF(index, numruns, EDF);
cout << "* Time: " << timeE << " Microseconds" << endl;
cout << "* \n" << "*---------------------------------------------------------------------------------------------------" << endl;
cout << "* LLF: " << endl;
schedule = LLF->CheckLLFSchedule();
cout << "* " << schedule << endl;
cout << "* " << endl;
int timeL = getAverageTimeLLF(index, numruns, LLF);
cout << "* Time: " << timeL << " Microseconds" << endl;
cout << "* \n" << "*---------------------------------------------------------------------------------------------------" << endl;
cout << "* Algorithm-A: " << endl;
cout << "* " << AlgorithmA->algorithmASchedule() << endl;
cout << "* " << endl;
int timeA = getAverageTimeAlgorithmA(index, numruns, AlgorithmA);
cout << "* Time: " << timeA << " Microseconds" << endl;
cout << "* \n" << "****************************************************************************************************" << endl;
cout << "\n\n" << endl;
}
//printScheduleEDF prints edf schedule of all tasksets
void Schedule::printScheduleEDFAll(int numruns, Schedule * EDF)
{
for (int i = 0; i < m_tasksets.size(); i++)
{
m_processors = m_tasksets[i].getNumProcessors();
m_lcm = m_tasksets[i].getLCM();
setAlgorithmsMemberVariables(EDF);
EDF->setTaskSet(0, m_tasksets[i]);
cout << "* EDF Schedule for Task Set " << i+1 << endl;
cout << "****************************************************************************************************" << endl;
cout << "* Tasks: " << m_tasksets[i].getNumTasks() << endl;
cout << "* Processors: " << m_processors << endl;
cout << "* Utilization Rate: " << m_tasksets[i].calculateTotalUtilizationRate() << endl;
cout << "* USI: " << m_tasksets[i].USI() << endl;
cout << "* EUSI: " << m_tasksets[i].EUSI() << endl;
cout << "* LCM: " << m_lcm << endl;
cout << "* Preemptive: " << (m_tasksets[i].getPreemptive() ? "True" : "False") << endl;
for (int j = 0; j < m_tasksets[i].getNumTasks(); j++)
{
cout << "* " << m_tasksets[i].getTask(j).getName() << ", S: " << m_tasksets[i].getTask(j).getStartTime() << ", C: " << m_tasksets[i].getTask(j).getComputationTime() << ", HD: " << m_tasksets[i].getTask(j).getHardDeadline() << ", SD: " << m_tasksets[i].getTask(j).getSoftDeadline() << ", P: " << m_tasksets[i].getTask(j).getPeriod() << endl;
}
cout << "* \n" << "*---------------------------------------------------------------------------------------------------" << endl;
cout << "* EDF: " << endl;
string schedule = EDF->runEDF_Algorithm();
cout << "* " << schedule << endl;
cout << "* " << endl;
int time = getAverageTimeEDF(i, numruns, EDF);
cout << "* Average Time: " << time << " Microseconds" << endl;
cout << "* \n" << "****************************************************************************************************" << endl;
cout << "\n\n" << endl;
}
}
//printScheduleLLF
//This function prints LLF schedule of all tasksets
void Schedule::printScheduleLLFAll(int numruns, Schedule* LLF)
{
for (int i = 0; i < m_tasksets.size(); i++)
{
m_processors = m_tasksets[i].getNumProcessors();
m_lcm = m_tasksets[i].getLCM();
setAlgorithmsMemberVariables(LLF);
LLF->setTaskSet(0, m_tasksets[i]);
cout << "* LLF Schedule for Task Set " << i+1 << endl;
cout << "****************************************************************************************************" << endl;
cout << "* Tasks: " << m_tasksets[i].getNumTasks() << endl;
cout << "* Processors: " << m_processors << endl;
cout << "* Utilization Rate: " << m_tasksets[i].calculateTotalUtilizationRate() << endl;
cout << "* USI: " << m_tasksets[i].USI() << endl;
cout << "* EUSI: " << m_tasksets[i].EUSI() << endl;
cout << "* LCM: " << m_lcm << endl;
cout << "* Preemptive: " << (m_tasksets[i].getPreemptive() ? "True" : "False") << endl;
for (int j = 0; j < m_tasksets[i].getNumTasks(); j++)
{
cout << "* " << m_tasksets[i].getTask(j).getName() << ", S: " << m_tasksets[i].getTask(j).getStartTime() << ", C: " << m_tasksets[i].getTask(j).getComputationTime() << ", HD: " << m_tasksets[i].getTask(j).getHardDeadline() << ", SD: " << m_tasksets[i].getTask(j).getSoftDeadline() << ", P: " << m_tasksets[i].getTask(j).getPeriod() << endl;
}
cout << "* \n" << "*---------------------------------------------------------------------------------------------------" << endl;
cout << "* LLF: " << endl;
string schedule = LLF->CheckLLFSchedule();
cout << "* " << schedule << endl;
cout << "* " << endl;
int time = getAverageTimeLLF(i, numruns, LLF);
cout << "* Average Time: " << time << " Microseconds" << endl;
cout << "* \n" << "****************************************************************************************************" << endl;
cout << "\n\n" << endl;
}
}
//printScheduleAlgorithmA
//This function prints Algorithm A schedule of all tasksets
void Schedule::printScheduleAlgorithmAAll(int numruns, Schedule * AlgorithmA)
{
for (int i = 0; i < m_tasksets.size(); i++)
{
m_processors = m_tasksets[i].getNumProcessors();
m_lcm = m_tasksets[i].getLCM();
setAlgorithmsMemberVariables(AlgorithmA);
AlgorithmA->setTaskSet(0, m_tasksets[i]);
cout << "* Algorithm-A Schedule for Task Set " << i+1 << endl;
cout << "****************************************************************************************************" << endl;
cout << "* Tasks: " << m_tasksets[i].getNumTasks() << endl;
cout << "* Processors: " << m_processors << endl;
cout << "* Utilization Rate: " << m_tasksets[i].calculateTotalUtilizationRate() << endl;
cout << "* USI: " << m_tasksets[i].USI() << endl;
cout << "* EUSI: " << m_tasksets[i].EUSI() << endl;
cout << "* LCM: " << m_lcm << endl;
cout << "* Preemptive: " << (m_tasksets[i].getPreemptive() ? "True" : "False") << endl;
for (int j = 0; j < m_tasksets[i].getNumTasks(); j++)
{
cout << "* " << m_tasksets[i].getTask(j).getName() << ", S: " << m_tasksets[i].getTask(j).getStartTime() << ", C: " << m_tasksets[i].getTask(j).getComputationTime() << ", HD: " << m_tasksets[i].getTask(j).getHardDeadline() << ", SD: " << m_tasksets[i].getTask(j).getSoftDeadline() << ", P: " << m_tasksets[i].getTask(j).getPeriod() << endl;
}
cout << "* \n" << "*---------------------------------------------------------------------------------------------------" << endl;
cout << "* Algorithm-A: " << endl;
cout << "* " << AlgorithmA->algorithmASchedule() << endl;
cout << "* " << endl;
int time = getAverageTimeAlgorithmA(i, numruns, AlgorithmA);
cout << "* Average Time: " << time << " Microseconds" << endl;
cout << "* \n" << "****************************************************************************************************" << endl;
cout << "\n\n" << endl;
}
}
//printSchedules prints schedules of all three algorithms for all tasksets
void Schedule::printSchedulesAll(int numruns, Schedule* EDF, Schedule* LLF, Schedule* AlgorithmA)
{
for (int i = 0; i < m_tasksets.size(); i++)
{
m_processors = m_tasksets[i].getNumProcessors();
m_lcm = m_tasksets[i].getLCM();
setAlgorithmsMemberVariables(EDF);
setAlgorithmsMemberVariables(LLF);
setAlgorithmsMemberVariables(AlgorithmA);
EDF->setTaskSet(0, m_tasksets[i]);
LLF->setTaskSet(0, m_tasksets[i]);
AlgorithmA->setTaskSet(0, m_tasksets[i]);
cout << "* Task Set " << i+1 << endl;
cout << "****************************************************************************************************" << endl;
cout << "* Tasks: " << m_tasksets[i].getNumTasks() << endl;
cout << "* Processors: " << m_processors << endl;
cout << "* Utilization Rate: " << m_tasksets[i].calculateTotalUtilizationRate() << endl;
cout << "* USI: " << m_tasksets[i].USI() << endl;
cout << "* EUSI: " << m_tasksets[i].EUSI() << endl;
cout << "* LCM: " << m_lcm << endl;
cout << "* Preemptive: " << (m_tasksets[i].getPreemptive() ? "True" : "False") << endl;
for (int j = 0; j < m_tasksets[i].getNumTasks(); j++)
{
cout << "* " << m_tasksets[i].getTask(j).getName() << ", S: " << m_tasksets[i].getTask(j).getStartTime() << ", C: " << m_tasksets[i].getTask(j).getComputationTime() << ", HD: " << m_tasksets[i].getTask(j).getHardDeadline() << ", SD: " << m_tasksets[i].getTask(j).getSoftDeadline() << ", P: " << m_tasksets[i].getTask(j).getPeriod() << endl;
}
cout << "* \n" << "*---------------------------------------------------------------------------------------------------" << endl;
cout << "* EDF: " << endl;
string schedule = EDF->runEDF_Algorithm();
cout << "* " << schedule << endl;
cout << "* " << endl;
int timeE = getAverageTimeEDF(i, numruns, EDF);
cout << "* Average Time: " << timeE << " Microseconds" << endl;
cout << "* \n" << "*---------------------------------------------------------------------------------------------------" << endl;
cout << "* LLF: " << endl;
schedule = LLF->CheckLLFSchedule();
cout << "* " << schedule << endl;
cout << "* " << endl;
int timeL = getAverageTimeLLF(i, numruns, LLF);
cout << "* Average Time: " << timeL << " Microseconds" << endl;
cout << "* \n" << "*---------------------------------------------------------------------------------------------------" << endl;
cout << "* Algorithm-A: " << endl;
cout << "* " << AlgorithmA->algorithmASchedule() << endl;
cout << "* " << endl;
int timeA = getAverageTimeAlgorithmA(i, numruns, AlgorithmA);
cout << "* Average Time: " << timeA << " Microseconds" << endl;
cout << "* \n" << "****************************************************************************************************" << endl;
cout << "\n\n" << endl;
}
}
//This adds in all of the instances of each task inside of the LCM
vector<Task> Schedule::addInAdditionalTasks(vector<Task> set) {
int newStart = 0;
int computation;
int hardDeadline;
int softDeadline;
int period;
string name;
//Create new set with old tasks inside of it
vector<Task> newSet = set;
//For each task add the repeat tasks up until the lcm
for (int i = 0; i < set.size(); i++) {
computation = set[i].getComputationTime();
hardDeadline = set[i].getHardDeadline();
softDeadline = set[i].getSoftDeadline();
period = set[i].getPeriod();
name = set[i].getName();
newStart = set[i].getStartTime();
//If next instance of task fits in the lcm
while (newStart + period < m_lcm) {
//New start time is next period instance
newStart += period;
//increase both deadlines to next deadline
softDeadline += period;
hardDeadline += period;
//Add next instance of task
newSet.push_back(Task(name, newStart, computation, softDeadline, hardDeadline, period));
}
}
return newSet;
}
//Configuring the vector<vector<Task>> to a readable string of task times.
//Should print out either task schedule or not feasible
/*
EX:
P1:T1[0,2) T3[2,6)
P2:T2[0,4)
*/
string Schedule::configureSetToOutput(vector<vector<Task>> schedule, bool feasible) {
string output = "";
string task = "";
int totalComputation = 0;
int endOfTask = 0;
if (feasible) {
//For each chain/processor
for (int i = 0; i < m_processors; i++) {
output.append("P" + to_string(i+1) + ":");
//For each element in the chain
for (int j = 0; j < schedule[i].size(); j++) {
endOfTask = totalComputation + schedule[i][j].getComputationTime();
//Creates string of task interval. Ex) T1[0,3)
if (schedule[i][j].getName() != "G") {
task = schedule[i][j].getName() + '[' + to_string(totalComputation) + ',' + to_string(endOfTask) + ") ";
}
else {
task = "-- ";
}
output.append(task);
totalComputation = endOfTask;
}
totalComputation = 0;
endOfTask = 0;
//Adding new line for next processor
output.append("\n");
}
}
else {
output.append("Not Feasible");
}
return output;
}
string Schedule::algorithmASchedule() { return ""; }
string Schedule::runEDF_Algorithm() { return ""; }
string Schedule::CheckLLFSchedule() { return ""; }
void Schedule::setAlgorithmsMemberVariables(Schedule* Algorithm)
{
Algorithm->m_processors = m_processors;
Algorithm->m_lcm = m_lcm;
}