+++ /dev/null
-#include "csolver.h"
-#include "staticautotuner.h"
-
-int main(int argc, char **argv) {
- if (argc < 2) {
- printf("You should specify file names ...");
- exit(-1);
- }
- CSolver *solvers[argc - 1];
- StaticAutoTuner *autotuner = new StaticAutoTuner(300);
- for (int i = 1; i < argc; i++) {
- solvers[i - 1] = CSolver::deserialize(argv[i]);
- autotuner->addProblem(solvers[i - 1]);
- }
-
- autotuner->tune();
- delete autotuner;
-
- for (int i = 1; i < argc; i++) {
- delete solvers[i - 1];
- }
-
- return 1;
-}
tuner->serializeUsed(buffer);
delete solver;
+ delete tuner;
return 0;
}
--- /dev/null
+#include "csolver.h"
+#include "serializetuner.h"
+#include <stdlib.h>
+#include <iostream>
+#include <fstream>
+
+int main(int argc, char **argv) {
+ if (argc != 5) {
+ printf("You only specify the name of the file ...");
+ exit(-1);
+ }
+ char buffer[512];
+ CSolver *solver = CSolver::deserialize(argv[1]);
+ uint timeout;
+ sscanf(argv[2], "%u", &timeout);
+ SerializeTuner *tuner = new SerializeTuner(argv[3]);
+ solver->setTuner(tuner);
+ solver->setSatSolverTimeout(timeout);
+ int sat = solver->solve();
+ long long metric = solver->getElapsedTime();
+ ofstream myfile;
+ myfile.open (argv[4], ios::out | ios::trunc);
+ myfile << metric << endl;
+ myfile << sat << endl;
+ myfile.close();
+ //serialize out the tuner we used
+ snprintf(buffer, sizeof(buffer), "%sused", argv[3]);
+ tuner->serializeUsed(buffer);
+
+ delete solver;
+ delete tuner;
+ return 0;
+}
friend unsigned int tunableSettingHash(TunableSetting *setting);
friend bool tunableSettingEquals(TunableSetting *setting1, TunableSetting *setting2);
friend class SearchTuner;
- friend class StaticSearchTuner;
+ friend class SerializeTuner;
};
unsigned int tunableSettingHash(TunableSetting *setting);
SearchTuner();
SearchTuner(const char *filename);
~SearchTuner();
- int getTunable(TunableParam param, TunableDesc *descriptor);
+ virtual int getTunable(TunableParam param, TunableDesc *descriptor);
int getVarTunable(VarType vartype, TunableParam param, TunableDesc *descriptor);
- int getVarTunable(VarType vartype1, VarType vartype2, TunableParam param, TunableDesc *descriptor);
+ virtual int getVarTunable(VarType vartype1, VarType vartype2, TunableParam param, TunableDesc *descriptor);
void setTunable(TunableParam param, TunableDesc *descriptor, uint value);
void setVarTunable(VarType vartype, TunableParam param, TunableDesc *descriptor, uint value);
void setVarTunable(VarType vartype1, VarType vartype2, TunableParam param, TunableDesc *descriptor, uint value);
--- /dev/null
+#include "serializetuner.h"
+#include <iostream>
+#include <fstream>
+using namespace std;
+
+SerializeTuner::SerializeTuner(const char *filename) {
+ ifstream myfile;
+ myfile.open (filename, ios::in);
+ if (myfile.is_open()) {
+ bool hasVar;
+ VarType type1;
+ VarType type2;
+ TunableParam param;
+ int lowValue;
+ int highValue;
+ int defaultValue;
+ int selectedValue;
+ while (myfile >> hasVar >> type1 >> type2 >> param >> lowValue >> highValue >> defaultValue >> selectedValue) {
+ TunableSetting *setting;
+
+ if (hasVar) {
+ setting = new TunableSetting(type1, type2, param);
+ } else {
+ setting = new TunableSetting(param);
+ }
+ setting->setDecision(lowValue, highValue, defaultValue, selectedValue);
+ settings.add(setting);
+ usedSettings.add(setting);
+ }
+ myfile.close();
+ } else {
+ model_print("Warning: Tuner %s couldn't be loaded ... Using default tuner instead ....\n", filename);
+ }
+}
+
+/*SearchTuner::~SearchTuner() {
+ SetIteratorTunableSetting *iterator = settings.iterator();
+ while (iterator->hasNext()) {
+ TunableSetting *setting = iterator->next();
+ delete setting;
+ }
+ delete iterator;
+ }*/
+
+
+int SerializeTuner::getTunable(TunableParam param, TunableDesc *descriptor) {
+ TunableSetting setting(param);
+ TunableSetting *result = usedSettings.get(&setting);
+ if (result == NULL) {
+ result = settings.get(&setting);
+ if ( result == NULL) {
+ return descriptor->defaultValue;
+ }
+ usedSettings.add(result);
+ }
+ return result->selectedValue;
+}
+
+int SerializeTuner::getVarTunable(VarType vartype1, VarType vartype2, TunableParam param, TunableDesc *descriptor) {
+ TunableSetting setting(vartype1, vartype2, param);
+ TunableSetting *result = usedSettings.get(&setting);
+ if (result == NULL) {
+ result = settings.get(&setting);
+ if ( result == NULL) {
+ return descriptor->defaultValue;
+ }
+ usedSettings.add(result);
+ }
+ return result->selectedValue;
+}
--- /dev/null
+#ifndef SERIALIZETUNER_H
+#define SERIALIZETUNER_H
+#include "searchtuner.h"
+
+class SerializeTuner : public SearchTuner {
+public:
+ SerializeTuner(const char *filename);
+ int getTunable(TunableParam param, TunableDesc *descriptor);
+ int getVarTunable(VarType vartype, TunableParam param, TunableDesc *descriptor);
+ int getVarTunable(VarType vartype1, VarType vartype2, TunableParam param, TunableDesc *descriptor);
+ CMEMALLOC;
+};
+
+#endif
+++ /dev/null
-#include "staticautotuner.h"
-#include "csolver.h"
-#include "staticsearchtuner.h"
-#include <math.h>
-#include <stdlib.h>
-#include <float.h>
-
-#define UNSETVALUE -1
-#define TIMEOUTSEC 5000
-StaticAutoTuner::StaticAutoTuner(uint _budget) : AutoTuner(_budget) {
-}
-
-StaticSearchTuner *StaticAutoTuner::mutateTuner(StaticSearchTuner *oldTuner) {
- StaticSearchTuner *newTuner = oldTuner->copyUsed();
- result = newTuner->nextStaticTuner();
- if ( result == EXIT_FAILURE) {
- return newTuner;
- } else {
- delete newTuner;
- return NULL;
- }
-}
-
-void StaticAutoTuner::tune() {
- StaticSearchTuner *oldTuner = new StaticSearchTuner();
- evaluateAll(oldTuner);
- while (true) {
- StaticSearchTuner *newTuner = mutateTuner(oldTuner);
- if (newTuner == NULL) {
- break;
- }
- double newScore = evaluateAll(newTuner);
- newTuner->printUsed();
- model_print("Received score %f\n", newScore);
- delete oldTuner;
- oldTuner = newTuner;
- }
- delete oldTuner;
-}
+++ /dev/null
-#ifndef STATICAUTOTUNER_H
-#define STATICAUTOTUNER_H
-#include "autotuner.h"
-
-
-class StaticAutoTuner : public AutoTuner {
-public:
- StaticAutoTuner(uint budget);
- virtual void tune();
- CMEMALLOC;
-private:
- StaticSearchTuner *mutateTuner(StaticSearchTuner *oldTuner);
-};
-#endif
+++ /dev/null
-#include "staticsearchtuner.h"
-#include <iostream>
-#include <fstream>
-using namespace std;
-
-StaticSearchTuner::StaticSearchTuner() {
- graphEncoding = false;
- naiveEncoding = ELEM_UNASSIGNED;
- ifstream myfile;
- myfile.open (TUNEFILE, ios::in);
- if (myfile.is_open()) {
- bool hasVar;
- VarType type1;
- VarType type2;
- TunableParam param;
- int lowValue;
- int highValue;
- int defaultValue;
- int selectedValue;
- while (myfile >> hasVar >> type1 >> type2 >> param >> lowValue >> highValue >> defaultValue >> selectedValue) {
- TunableSetting *setting;
-
- if (hasVar) {
- setting = new TunableSetting(type1, type2, param);
- } else {
- setting = new TunableSetting(param);
- }
- setting->setDecision(lowValue, highValue, defaultValue, selectedValue);
- usedSettings.add(setting);
- }
- myfile.close();
- }
-}
-
-StaticSearchTuner *StaticSearchTuner::copyUsed() {
- StaticSearchTuner *tuner = new StaticSearchTuner();
- SetIteratorTunableSetting *iterator = usedSettings.iterator();
- while (iterator->hasNext()) {
- TunableSetting *setting = iterator->next();
- TunableSetting *copy = new TunableSetting(setting);
- tuner->settings.add(copy);
- }
- if (naiveEncoding != ELEM_UNASSIGNED) {
- tuner->graphEncoding = graphEncoding;
- tuner->naiveEncoding = naiveEncoding;
- }
- delete iterator;
- return tuner;
-}
-
-StaticSearchTuner::~StaticSearchTuner() {
- SetIteratorTunableSetting *iterator = settings.iterator();
- while (iterator->hasNext()) {
- TunableSetting *setting = iterator->next();
- delete setting;
- }
- delete iterator;
-}
-
-int StaticSearchTuner::nextStaticTuner() {
- if (naiveEncoding == ELEM_UNASSIGNED) {
- naiveEncoding = ONEHOT;
- SetIteratorTunableSetting *iter = settings.iterator();
- while (iter->hasNext()) {
- TunableSetting *setting = iter->next();
- if (setting->param == NAIVEENCODER) {
- setting->selectedValue = ONEHOT;
- } else if (setting->param == ENCODINGGRAPHOPT) {
- setting->selectedValue = false;
- }
- }
- delete iter;
- return EXIT_FAILURE;
- }
- int result = EXIT_FAILURE;
- if (naiveEncoding == BINARYINDEX && graphEncoding) {
- model_print("Best tuner\n");
- return EXIT_SUCCESS;
- } else if (naiveEncoding == BINARYINDEX && !graphEncoding) {
- naiveEncoding = ONEHOT;
- graphEncoding = true;
- } else {
- naiveEncoding = (ElementEncodingType)((int)naiveEncoding + 1);
- }
- SetIteratorTunableSetting *iter = settings.iterator();
- uint count = 0;
- while (iter->hasNext()) {
- TunableSetting *setting = iter->next();
- if (setting->param == NAIVEENCODER) {
- setting->selectedValue = naiveEncoding;
- count++;
- } else if (setting->param == ENCODINGGRAPHOPT) {
- setting->selectedValue = graphEncoding;
- count++;
- }
- }
- model_print("Mutating %u settings\n", count);
- delete iter;
- return result;
-}
+++ /dev/null
-#ifndef STATICSEARCHTUNER_H
-#define STATICSEARCHTUNER_H
-#include "searchtuner.h"
-#define TUNEFILE "tune.conf"
-
-class StaticSearchTuner : public SearchTuner {
-public:
- StaticSearchTuner();
- ~StaticSearchTuner();
- int nextStaticTuner();
- StaticSearchTuner *copyUsed();
-
- CMEMALLOC;
-private:
- bool graphEncoding;
- ElementEncodingType naiveEncoding;
-};
-
-#endif
class SearchTuner;
class TunableSetting;
-class StaticAutoTuner;
-class StaticSearchTuner;
+class SerializeTuner;
class TunableDesc;