Commit 3a850410 authored by EYRAUD-DUBOIS Lionel's avatar EYRAUD-DUBOIS Lionel

New algorithms : purely online algorithms where decisions are taken when tasks become ready

parent fcca1a74
......@@ -3,6 +3,7 @@
#include <iostream>
#include <OnlineZhang.h>
#include <TrueHeteroPrio.h>
#include <OnlineQA.h>
#include "algorithm.h"
#include "listAlgorithm.h"
......@@ -295,6 +296,8 @@ Algorithm* createAlg(const string& name, const AlgOptions& options) {
alg = new OnlineZhang(options);
if(name == "rep")
alg = new ReproduceAlgorithm(options);
if(name == "qa")
alg = new OnlineQA(options);
#ifdef WITH_CPLEX
if(name == "lp")
alg = new SchedLPIndep(options);
......
//
// Created by eyraud on 30/08/18.
//
#ifndef PMTOOL_ONLINEGENERIC_H
#define PMTOOL_ONLINEGENERIC_H
#include <queue>
#include "algorithm.h"
typedef std::pair<double, int> taskAndReadyTime;
class OnlineGeneric : public Algorithm {
public:
OnlineGeneric(const AlgOptions &options);
double compute(Instance &instance, SchedAction *action) override;
virtual int assignTask(int task, double now) = 0;
protected:
Instance* ins;
std::priority_queue<taskAndReadyTime, std::vector<taskAndReadyTime>, std::greater<taskAndReadyTime>> readyTasks;
std::vector<double> finishTimes;
std::vector<double> readyTimes;
std::vector<int> nbScheduledPredecessors;
int getEarliestWorker(int type);
int getEarliestWorker();
int verbosity;
};
#endif //PMTOOL_ONLINEGENERIC_H
//
// Created by eyraud on 30/08/18.
//
#ifndef PMTOOL_ONLINEQA_H
#define PMTOOL_ONLINEQA_H
#include "OnlineGeneric.h"
class OnlineQA : public OnlineGeneric {
public:
OnlineQA(const AlgOptions &options);
double compute(Instance &instance, SchedAction *action) override;
int assignTask(int task, double now) override;
protected:
double threshold;
};
#endif //PMTOOL_ONLINEQA_H
......@@ -15,7 +15,7 @@ set(SCHED_SRC
availSequence.cpp
GreedyAlgorithm.cpp
HeftAlgorithm.cpp
OnlineZhang.cpp ../include/OnlineZhang.h GreedyPerType.cpp ../include/GreedyPerType.h TrueHeteroPrio.cpp ../include/TrueHeteroPrio.h)
OnlineZhang.cpp ../include/OnlineZhang.h GreedyPerType.cpp ../include/GreedyPerType.h TrueHeteroPrio.cpp ../include/TrueHeteroPrio.h OnlineGeneric.cpp ../include/OnlineGeneric.h OnlineQA.cpp ../include/OnlineQA.h)
if(CPLEX_FOUND)
set(SCHED_SRC ${SCHED_SRC} SchedLPIndep.cpp ../include/SchedLPIndep.h AreaRound.cpp ../include/AreaRound.h)
......
//
// Created by eyraud on 30/08/18.
//
#include <OnlineGeneric.h>
#include <iostream>
using namespace std;
double OnlineGeneric::compute(Instance &instance, SchedAction *action) {
ins = &instance;
// Make sure that reverse dependencies are computed.
instance.getRevDependencies();
readyTasks = priority_queue<taskAndReadyTime, vector<taskAndReadyTime>, greater<taskAndReadyTime>>();
finishTimes.resize(instance.totalWorkers, 0);
readyTimes.resize(instance.nbTasks, -1);
nbScheduledPredecessors.resize(instance.nbTasks, 0);
for(int t = 0; t < instance.nbTasks; ++t) {
if(instance.dependencies[t].empty()) {
readyTimes[t] = 0;
readyTasks.emplace(0, t);
}
}
while(! readyTasks.empty()) {
taskAndReadyTime next = readyTasks.top();
readyTasks.pop();
int worker = assignTask(next.second, next.first);
double startTime = max(next.first, finishTimes[worker]);
double finishTime = startTime + instance.execWorker(worker, next.second);
if(verbosity >= 4)
cout << "Scheduling task " << next.second << " at time " << startTime << " on worker " << worker << " until time " << finishTime << endl;
if(action)
action->onSchedule(next.second, worker, startTime, finishTime);
finishTimes[worker] = finishTime;
for(int & succ: instance.revDep[next.second]) {
++nbScheduledPredecessors[succ];
readyTimes[succ] = max(readyTimes[succ], finishTime);
if(nbScheduledPredecessors[succ] == instance.dependencies[succ].size()){
readyTasks.emplace(readyTimes[succ], succ);
}
}
}
return getMax(finishTimes);
}
int OnlineGeneric::getEarliestWorker(int type) {
int wIndex = 0;
for(int typeIndex = 0; typeIndex < type; ++typeIndex)
wIndex += ins->nbWorkers[typeIndex];
int res = wIndex;
for(int w = 1; w < ins->nbWorkers[type]; ++w)
if(finishTimes[wIndex + w] < finishTimes[res])
res = wIndex + w;
return res;
}
int OnlineGeneric::getEarliestWorker() {
int res = 0;
for(int w = 1; w < ins->totalWorkers; ++w)
if(finishTimes[w] < finishTimes[res])
res = w;
return res;
}
OnlineGeneric::OnlineGeneric(const AlgOptions &options) {
verbosity = options.asInt("verbosity", 0);
}
//
// Created by eyraud on 30/08/18.
//
#include <cmath>
#include "OnlineQA.h"
using namespace std;
int OnlineQA::assignTask(int task, double now) {
double accel = ins->execType(0, task) / ins->execType(1, task);
return (accel <= threshold) ? getEarliestWorker(0) : getEarliestWorker(1);
}
double OnlineQA::compute(Instance &instance, SchedAction *action) {
threshold = sqrt(instance.nbWorkers[0] / instance.nbWorkers[1]);
return OnlineGeneric::compute(instance, action);
}
OnlineQA::OnlineQA(const AlgOptions &options) : OnlineGeneric(options) {
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment