diff options
Diffstat (limited to 'Simulator/include/simulation/schedulers/ShortestRemainingTimeScheduler.h')
| -rw-r--r-- | Simulator/include/simulation/schedulers/ShortestRemainingTimeScheduler.h | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/Simulator/include/simulation/schedulers/ShortestRemainingTimeScheduler.h b/Simulator/include/simulation/schedulers/ShortestRemainingTimeScheduler.h new file mode 100644 index 00000000..15265985 --- /dev/null +++ b/Simulator/include/simulation/schedulers/ShortestRemainingTimeScheduler.h @@ -0,0 +1,46 @@ +#pragma once +#include "Scheduler.h" +#include <algorithm> + +namespace Simulation +{ + class ShortestRemainingTimeScheduler : public Scheduler + { + protected: + ~ShortestRemainingTimeScheduler() + { + } + + public: + /* + Distribute workloads according to the srtf principle + */ + void schedule(std::vector<std::reference_wrapper<Modeling::Machine>>& machines, std::vector<Workload*> workloads) override + { + if (workloads.size() == 0) + return; + + std::sort( + workloads.begin(), + workloads.end(), + [](Workload* a, Workload* b) -> bool { + return a->getRemainingOperations() < b->getRemainingOperations(); + } + ); + + int taskIndex = 0; + + std::for_each( + machines.begin(), + machines.end(), + [&workloads, &taskIndex](Modeling::Machine& machine) { + while (!workloads.at(taskIndex)->dependencyFinished) + taskIndex = (++taskIndex) % workloads.size(); + + machine.giveTask(workloads.at(taskIndex)); + taskIndex = (++taskIndex) % workloads.size(); + } + ); + } + }; +} |
