From 070ce923574dcc57435cb3fb2dfe86b6a38cd249 Mon Sep 17 00:00:00 2001 From: MDBijman Date: Tue, 24 Jan 2017 12:15:26 +0100 Subject: Initial code commit with organized dependencies --- .../schedulers/ShortestRemainingTimeScheduler.h | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 Simulator/include/simulation/schedulers/ShortestRemainingTimeScheduler.h (limited to 'Simulator/include/simulation/schedulers/ShortestRemainingTimeScheduler.h') 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 + +namespace Simulation +{ + class ShortestRemainingTimeScheduler : public Scheduler + { + protected: + ~ShortestRemainingTimeScheduler() + { + } + + public: + /* + Distribute workloads according to the srtf principle + */ + void schedule(std::vector>& machines, std::vector 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(); + } + ); + } + }; +} -- cgit v1.2.3