Commit a0e3eafe authored by EYRAUD-DUBOIS Lionel's avatar EYRAUD-DUBOIS Lionel

Move from chooseType to chooseTask in schedAction

parent 4b12e90d
......@@ -58,7 +58,7 @@ double HeftAlgorithm::compute(Instance& ins, SchedAction *action) {
int bestK = 0; int bestT = 0;
timeSeq::iterator bestPeriod; // Should belond to workerAvailability[bestK]
int targetType = -1;
if((action != NULL) && ((targetType = action->chooseType(i, queue.size())) >= 0)) {
/* if((action != NULL) && ((targetType = action->chooseType(i, queue.size())) >= 0)) {
k = 0;
for(t = 0; t < targetType; t++) k += ins.nbWorkers[t];
for(j = 0; j < ins.nbWorkers[targetType]; j++, k++) {
......@@ -72,7 +72,7 @@ double HeftAlgorithm::compute(Instance& ins, SchedAction *action) {
bestT = targetType;
}
}
} else {
} else { */
for(t = 0; t < (int) ins.nbWorkers.size(); t++) {
for(j = 0; j < ins.nbWorkers[t]; j++, k++) {
// TODO: remove copy-paste ?
......@@ -87,7 +87,7 @@ double HeftAlgorithm::compute(Instance& ins, SchedAction *action) {
}
}
}
}
//}
double startTime = bestStart;
// cout << "HEFT " << i << " " << ins.taskTypes[i] << " " << startTime << " " << bestTime << " " << bestK << " " << bestT << endl;
......
......@@ -43,6 +43,7 @@ int getType(int m, vector<int> nbWorkersPerType, int* index) {
// Rank
//
ListAlgorithm::ListAlgorithm(const AlgOptions & options): ranker(options) {
verbosity = options.asInt("verbosity", 0);
}
static const string listAlgName = "list";
......@@ -56,7 +57,7 @@ double ListAlgorithm::compute(Instance& ins, SchedAction* action) {
// Compute ranks
vector<double> rank = ranker.computeRanks(ins);
int nbWorkers = getSum(ins.nbWorkers);
int nbWorkers = ins.totalWorkers;
rankCompare rc(rank);
rankSet readyTasks(rc);
......@@ -89,23 +90,20 @@ double ListAlgorithm::compute(Instance& ins, SchedAction* action) {
int index = 0;
int t = getType(idle, ins.nbWorkers, &index);
bool found = false;
auto it = readyTasks.begin();
for(; it != readyTasks.end(); it++) {
int choice = (action != NULL) ? action->chooseType(*it, readyTasks.size()) : -1;
if((choice == -1) || (choice == t)) {
found = true;
break;
}
}
if (found == false){
leaveIdle[idle] = true;
int chosenTask;
if((action != NULL) && ((chosenTask = action->chooseTask(t)) != SCHEDACTION_NONE)) {
if(chosenTask < 0)
leaveIdle[idle] = true;
} else {
int chosenTask = *it;
readyTasks.erase(it);
chosenTask = *(readyTasks.begin());
}
if(chosenTask >= 0)
{
readyTasks.erase(chosenTask);
double finishTime = currentTime + ins.execTimes[t][ins.taskTypes[chosenTask]];
// cout << "LIST " << chosenTask << " " << ins.taskTypes[chosenTask] << " " << currentTime << " " << finishTime << " " << idle << " " << t << endl;
if(verbosity >= 1)
cout << "LIST " << chosenTask << " " << ins.taskTypes[chosenTask] << " " << currentTime << " " << finishTime << " " << idle << " " << t << endl;
tasksToSchedule --;
if(action != NULL)
action->onSchedule(chosenTask, idle, currentTime, finishTime);
......@@ -132,32 +130,24 @@ double ListAlgorithm::compute(Instance& ins, SchedAction* action) {
//Finish all tasks with finishTime <= currentTime
for(i = 0; i < n; i++)
if((!finishedTasks[i]) && (endtimesTasks[i] != -1) && (endtimesTasks[i] <= currentTime)) {
// cout << "[" << currentTime << "] Finishing task " << i << endl;
if(verbosity >= 1)
cout << "[" << currentTime << "] Finishing task " << i << endl;
finishedTasks[i] = true;
for(j = 0; j < (int) revDependencies[i].size(); j++) {
int k = revDependencies[i][j];
nbDep[k]--;
// cout << " Dependent task: " << k << " remaining dependencies: " << nbDep[k] << endl;
if(verbosity >= 3)
cout << " Dependent task: " << k << " remaining dependencies: " << nbDep[k] << endl;
if(nbDep[k] == 0){
auto r = readyTasks.insert(k);
if(!r.second) {
cerr << "Task " << k <<" already present in set" << endl;
throw(-1);
}
int choice = -1;
if(action != NULL) {
action->onTaskPush(i);
choice = action->chooseType(k, readyTasks.size());
}
// cout << "[" << currentTime << "] Pushing task " << k << endl;
if(choice == -1)
for(int l = 0; l < nbWorkers; l++)
leaveIdle[l] = false;
else {
int z = 0;
for(t = 0; t < choice; t++) z += ins.nbWorkers[t];
for(int l = 0; l < ins.nbWorkers[choice]; l++, z++)
leaveIdle[z] = false;
}
}
}
......
......@@ -12,6 +12,7 @@ class ListAlgorithm : public Algorithm {
protected:
RankComputer ranker;
int verbosity;
public:
ListAlgorithm(const AlgOptions &options);
double compute(Instance& ins, SchedAction* action);
......
......@@ -15,12 +15,12 @@ void ActionSequence::onTaskPush(int t) {
for (std::vector<SchedAction*>::iterator it = actions.begin() ; it != actions.end(); ++it)
(*it)->onTaskPush(t);
}
int ActionSequence::chooseType(int t, int nr) {
int ActionSequence::chooseTask(int wType) {
int tmp;
for (std::vector<SchedAction*>::iterator it = actions.begin() ; it != actions.end(); ++it)
if( (tmp = (*it)->chooseType(t, nr)) >= 0)
if( (tmp = (*it)->chooseTask(wType)) != SCHEDACTION_NONE)
return tmp;
return -1;
return SCHEDACTION_NONE;
}
ExportToFile::ExportToFile(string filename, Instance* ins, bool header, string name)
......
......@@ -5,10 +5,12 @@
#include <vector>
#include "instance.h"
#define SCHEDACTION_NONE -5
class SchedAction {
public:
virtual void onSchedule(int task, int worker, double startTime, double endTime) { }
virtual int chooseType(int task, int nbReady) {return -1; }
virtual int chooseTask(int wType) {return SCHEDACTION_NONE; }
virtual void onTaskPush(int task) { }
};
......@@ -20,7 +22,7 @@ class ActionSequence : public SchedAction {
void add(SchedAction *a);
void onSchedule(int i, int w, double s, double f);
void onTaskPush(int t);
int chooseType(int t, int nr);
int chooseTask(int wType);
};
class ExportToFile : public SchedAction {
......
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