Commit 420fb015 authored by EYRAUD-DUBOIS Lionel's avatar EYRAUD-DUBOIS Lionel

Remove names from algorithms, store names as special options in algOptions

parent 9830f87d
......@@ -187,20 +187,17 @@ void ProgramOptions::parse(int argc, char** argv) {
}
string buildNameRaw(string name, AlgOptions opts) {
return name.append(":").append(opts.serialize());
}
string ProgramOptions::buildName(string name, AlgOptions opts, bool forceRaw) {
if(forceRaw || outputNamesRaw) {
name = buildNameRaw(name, opts);
} else {
for(string s: optionKeys) {
name = name.append(" ").append(opts.asString(s, "NA"));
string ProgramOptions::buildName(AlgOptions opts, bool forceRaw) {
string result;
if(forceRaw || outputNamesRaw) {
result = opts.serialize();
} else {
result = opts.asString("name");
for(string s: optionKeys) {
result = result.append(" ").append(opts.asString(s, "NA"));
}
}
}
return name;
return result;
}
void ProgramOptions::usage() {
......@@ -322,8 +319,9 @@ void ProgramOptions::insertComputable(vector< pair<A, AlgOptions> > & elems, str
if(!additionalOptions.empty())
options.parse(additionalOptions);
elems.push_back(make_pair(func(name, options), options));
for(auto & s: options)
optionKeys.insert(s.first);
for(auto & s: options)
if(s.first != "name")
optionKeys.insert(s.first);
}
}
......
......@@ -30,7 +30,8 @@ void AlgOptions::include(const string& opt) {
string AlgOptions::parseWithName(const string &line) {
vector<string> opts = split(line, ':');
auto it = opts.begin();
string name = *it;
string name = *it;
insert("name", name);
for(it++; it < opts.end(); it++) {
include(*it);
}
......@@ -50,7 +51,9 @@ vector<AlgOptions> AlgOptions::multiParseWithName(const std::string & line, stri
int start = 1;
for(string s: opts) {
if(start == 1) {
name = s; start = 0; continue;
name = s; start = 0;
result[0].insert("name", name);
continue;
}
vector<string> vals = split(s, '=');
if(vals.size() == 0) {
......@@ -79,10 +82,13 @@ vector<AlgOptions> AlgOptions::multiParseWithName(const std::string & line, stri
}
string AlgOptions::serialize () const {
string result;
string result;
result.append(asString("name"));
for(auto pair = begin(); pair != end(); pair++) {
if(pair != begin()) result.append(":");
result.append(pair->first).append("=").append(pair->second);
if(pair->first != "name") {
if (pair != begin()) result.append(":");
result.append(pair->first).append("=").append(pair->second);
}
}
return result;
}
......
......@@ -14,8 +14,7 @@ class Dmdas : public Algorithm {
public:
Dmdas(const AlgOptions& options);
double compute(Instance &ins, SchedAction* action);
std::string name();
double compute(Instance &ins, SchedAction* action);
};
......
......@@ -22,8 +22,7 @@ class GreedyAlgorithm : public Algorithm {
public:
GreedyAlgorithm(const AlgOptions &options);
double compute(Instance& ins, SchedAction* action);
virtual std::string name() = 0;
double compute(Instance& ins, SchedAction* action);
};
#endif
......@@ -19,8 +19,7 @@ class HeftAlgorithm : public Algorithm {
// Rank
//
HeftAlgorithm(const AlgOptions &options);
double compute(Instance& ins, SchedAction* action);
std::string name();
double compute(Instance& ins, SchedAction* action);
};
#endif
......@@ -81,8 +81,7 @@ class HeteroPrio : public Algorithm {
public:
HeteroPrio(const AlgOptions & options);
double compute(Instance& ins, SchedAction* action);
std::string name();
double compute(Instance& ins, SchedAction* action);
};
#endif
......@@ -10,13 +10,6 @@
typedef std::pair<Algorithm*, AlgOptions> fullAlg;
typedef std::pair<Bound*, AlgOptions> fullBound;
std::string buildNameRaw(std::string name, AlgOptions opts);
template <class T>
std::string buildNameRawLocal(T* t) {
return buildNameRaw(t->first->name(), t->second);
}
class ProgramOptions {
private:
void displayAlgList();
......@@ -32,7 +25,7 @@ class ProgramOptions {
ProgramOptions();
void parse(int argc, char** argv);
void usage();
std::string buildName(std::string name, AlgOptions opts, bool forceRaw = false);
std::string buildName(AlgOptions opts, bool forceRaw);
std::vector<std::string> inputFiles;
std::vector<std::string> platformFiles;
......
......@@ -10,11 +10,8 @@ class ReproduceAlgorithm : public Algorithm {
public:
ReproduceAlgorithm(const AlgOptions& options);
double compute(Instance& ins, SchedAction* action);
std::string name() {
return "rep";
}
double compute(Instance& ins, SchedAction* action);
};
......
......@@ -11,8 +11,7 @@
class Algorithm {
public:
virtual double compute(Instance& instance, SchedAction* action) = 0;
virtual std::string name() = 0 ;
virtual double compute(Instance& instance, SchedAction* action) = 0;
};
class TaskSet {
......
......@@ -15,8 +15,7 @@ class ListAlgorithm : public Algorithm {
int verbosity;
public:
ListAlgorithm(const AlgOptions &options);
double compute(Instance& ins, SchedAction* action);
std::string name();
double compute(Instance& ins, SchedAction* action);
};
#endif
......@@ -32,8 +32,8 @@ void computeAlg(ProgramOptions& progOpt, Instance* ins,
auto opts = algAndOpt.second;
ActionSequence seq;
result->key = progOpt.buildName(alg->name(), opts, true);
result->name = progOpt.buildName(alg->name(), opts);
result->key = progOpt.buildName(opts, true);
result->name = progOpt.buildName(opts, false);
InternalShare saveResult(result->key, ins);
seq.add(&saveResult);
......@@ -280,7 +280,7 @@ int main(int argc, char** argv) {
// Iterate through bound list, execute all
for(auto it = progOpt.bounds.begin(); it < progOpt.bounds.end(); it++) {
auto opts = it->second;
string name = progOpt.buildName(it->first->name(), opts);
string name = progOpt.buildName(opts, false);
auto start = chrono::steady_clock::now();
try {
......@@ -343,9 +343,10 @@ int main(int argc, char** argv) {
}
if(bestBound != NULL)
cerr << "Best bound: " << bestBoundValue << " with " << buildNameRawLocal(bestBound) << endl;
cerr << "Best bound: " << bestBoundValue << " with " << progOpt.buildName(bestBound->second, true) << endl;
if(bestAlgIdx > 0)
cerr << "Best schedule: " << bestAlgorithmValue << " with " << buildNameRawLocal(&progOpt.algs[bestAlgIdx]) << endl;
cerr << "Best schedule: " << bestAlgorithmValue << " with " << progOpt.buildName(progOpt.algs[bestAlgIdx].second,
true) << endl;
if(bestBound != NULL && bestAlgIdx > 0)
cerr << "Gap: " << (bestAlgorithmValue - bestBoundValue) / bestBoundValue << endl;
......
......@@ -16,11 +16,6 @@ Dmdas::Dmdas(const AlgOptions& options):
}
string Dmdas::name() {
static const string n = "dmdas";
return n;
}
double Dmdas::compute(Instance &ins, SchedAction* action) {
// Compute ranks
TaskSet* readyTasks = ranker.makeSet(ins);
......
......@@ -11,11 +11,7 @@ HeftAlgorithm::HeftAlgorithm(const AlgOptions &options): ranker(options) {
}
static const string heftAlgName = "heft";
string HeftAlgorithm::name() {
return heftAlgName;
}
static const string heftAlgName = "heft";
double HeftAlgorithm::compute(Instance& ins, SchedAction *action) {
......
......@@ -22,10 +22,6 @@ HeteroPrio::HeteroPrio(const AlgOptions & options): ranker(options) {
stealIfIdle = (options.asString("stealidle", "yes") == "yes");
}
string HeteroPrio::name() {
return "HetPrio";
}
void HeteroPrio::init(Instance& ins) {
readyQueues.clear();
......
......@@ -33,11 +33,7 @@ ListAlgorithm::ListAlgorithm(const AlgOptions & options): ranker(options) {
verbosity = options.asInt("verbosity", 0);
}
static const string listAlgName = "list";
string ListAlgorithm::name() {
return listAlgName;
}
static const string listAlgName = "list";
double ListAlgorithm::compute(Instance& ins, SchedAction* action) {
......
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