Commit 0ab732b2 authored by EYRAUD-DUBOIS Lionel's avatar EYRAUD-DUBOIS Lionel

Sorting task types per length for each resource is now done in instance

Allows many schedulers to use this information
parent f58d2b6b
......@@ -502,6 +502,22 @@ void Instance::computeRevDependencies() {
revDep[dependencies[i][j]].push_back(i);
}
std::vector<std::vector<int> > *Instance::getSortedByLength() {
if(sortedByLength == NULL) {
sortedByLength= new vector<vector<int> >(nbWorkerTypes);
auto & result = *sortedByLength;
for (unsigned int i = 0; i < nbWorkerTypes; i++) {
for (int j = 0; j < nbTaskTypes; j++)
result[i].push_back(j);
sort(result[i].begin(), result[i].end(),
[&](int a, int b) {
return execTimes[i][a] > execTimes[i][b];
});
}
}
return sortedByLength;
}
#define TOTALOP(n, i) ((3*n*n + 6*n -3*n*(i) -3*(i) + (i)*(i) +2)*(i)/6)
......
......@@ -78,7 +78,10 @@ public:
std::vector<double> computeMinRank();
std::vector<double> computePreAllocRank(std::vector<int> alloc);
std::vector<double> computeLongestPath(const std::vector<double> &weights, bool display=false, std::vector<int>* storeCP=NULL, int to = -1, int from = -1);
std::vector<double> computeCriticalPath(bool display, std::vector<int>* storeCP);
std::vector<double> computeCriticalPath(bool display, std::vector<int>* storeCP);
// result[i] contains task types sorted by their execution time on resource type i, longest first
std::vector<std::vector<int> >* sortedByLength;
std::vector<std::vector<int> >* getSortedByLength();
void removeDependencies();
void revertDependencies();
......
......@@ -69,35 +69,13 @@ double computeLambda(vector<double> & w, vector<double> &m) {
return max(getMax(w), getMax(m));
}
// Storing in instance extraData allows to avoid sorting each time I need it
// result[i] contains task types sorted by their execution time on resource type i, longest first
vector<vector<int> >* getSortedByLength(Instance & ins) {
string key = "IB-length";
if(ins.extraData.hasValue(key))
return (vector<vector<int> >*) ins.extraData.get(key);
auto result = new vector<vector<int> >(2);
for(unsigned int i = 0; i < 2; i++) {
for(int j = 0; j < ins.nbTaskTypes; j++)
(*result)[i].push_back(j);
sort((*result)[i].begin(), (*result)[i].end(),
[&] (int a, int b) {
return ins.execTimes[i][a] > ins.execTimes[i][b];
});
}
ins.extraData.insert(key, (void*) result);
return result;
}
/* Sort tasks in LPT order: largest first */
IndepResult allocToResultAndSort(vector<int>& allocation, vector<int> & taskSet, Instance & ins) {
IndepResult res(2);
vector<vector<int> >* sortedTaskTypes = getSortedByLength(ins);
vector<vector<int> >* sortedTaskTypes = ins.getSortedByLength();
vector< vector< vector<int> > > allocByTaskType(2, vector<vector<int> >(ins.nbTaskTypes));
for(unsigned int i = 0; i < allocation.size(); i++)
......
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