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/FirstInFirstOutScheduler.h | 37 +++++++++++++++++ .../include/simulation/schedulers/Scheduler.h | 25 ++++++++++++ .../schedulers/ShortestRemainingTimeScheduler.h | 46 ++++++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 Simulator/include/simulation/schedulers/FirstInFirstOutScheduler.h create mode 100644 Simulator/include/simulation/schedulers/Scheduler.h create mode 100644 Simulator/include/simulation/schedulers/ShortestRemainingTimeScheduler.h (limited to 'Simulator/include/simulation/schedulers') diff --git a/Simulator/include/simulation/schedulers/FirstInFirstOutScheduler.h b/Simulator/include/simulation/schedulers/FirstInFirstOutScheduler.h new file mode 100644 index 00000000..0cac0dfa --- /dev/null +++ b/Simulator/include/simulation/schedulers/FirstInFirstOutScheduler.h @@ -0,0 +1,37 @@ +#pragma once +#include "Scheduler.h" +#include + +namespace Simulation +{ + class FirstInFirstOutScheduler : public Scheduler + { + protected: + ~FirstInFirstOutScheduler() + { + } + + public: + /* + Distribute workloads according to the FIFO principle + */ + void schedule(std::vector>& machines, std::vector workloads) override + { + if (workloads.size() == 0) + return; + + // Find the first workload with dependencies finished + int index = 0; + while(!workloads.at(index)->dependencyFinished) + index = (++index) % workloads.size(); + + std::for_each( + machines.begin(), + machines.end(), + [index, &workloads](std::reference_wrapper& machine) { + machine.get().giveTask(workloads.at(index)); + } + ); + } + }; +} diff --git a/Simulator/include/simulation/schedulers/Scheduler.h b/Simulator/include/simulation/schedulers/Scheduler.h new file mode 100644 index 00000000..b084e8f6 --- /dev/null +++ b/Simulator/include/simulation/schedulers/Scheduler.h @@ -0,0 +1,25 @@ +#pragma once +#include "simulation/workloads/Workload.h" +#include "modeling/machine/Machine.h" + +#include + +namespace Simulation +{ + /* + Provides a strategy for load balancing. + */ + class Scheduler + { + public: + virtual ~Scheduler() + { + + } + + /* + Divides the workloads over the given machines. + */ + virtual void schedule(std::vector>& machines, std::vector workloads) = 0; + }; +} 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