#include "orderelement.h"
#include "structs.h"
#include "decomposeorderresolver.h"
+#include "searchtuner.h"
#define HASHNEXT(hash, newval) {hash += newval; hash += hash << 10; hash ^= hash >> 6;}
#define HASHFINAL(hash) {hash += hash << 3; hash ^= hash >> 11; hash += hash << 15;}
return key1->newfirst == key2->newfirst &&
key1->newsecond == key2->newsecond;
}
+
+unsigned int tunableSettingHash(TunableSetting *setting) {
+ return setting->hasVar ^ setting->type1 ^ setting->type2 ^ setting->param;
+}
+
+bool tunableSettingEquals(TunableSetting *setting1, TunableSetting *setting2) {
+ return setting1->hasVar == setting2->hasVar &&
+ setting1->type1 == setting2->type1 &&
+ setting1->type2 == setting2->type2 &&
+ setting1->param == setting2->param;
+}
bool order_element_equals(OrderElement *key1, OrderElement *key2);
unsigned int order_pair_hash_function(OrderPair *This);
bool order_pair_equals(OrderPair *key1, OrderPair *key2);
-
+unsigned int tunableSettingHash(TunableSetting *setting);
+bool tunableSettingEquals(TunableSetting *setting1, TunableSetting *setting2);
unsigned int doredge_hash_function(DOREdge *key);
bool doredge_equals(DOREdge *key1, DOREdge *key2);
typedef Hashset<DOREdge *, uintptr_t, PTRSHIFT, doredge_hash_function, doredge_equals> HashsetDOREdge;
typedef Hashset<Boolean *, uintptr_t, PTRSHIFT> HashsetBoolean;
typedef Hashset<Element *, uintptr_t, PTRSHIFT> HashsetElement;
-typedef SetIterator<Boolean *, uintptr_t, PTRSHIFT> SetIteratorBoolean;
typedef Hashset<uint64_t, uint64_t, 0> Hashset64Int;
-typedef SetIterator<uint64_t, uint64_t, 0> SetIterator64Int;
+typedef Hashset<TunableSetting *, uintptr_t, 4, tunableSettingHash, tunableSettingEquals> HashsetTunableSetting;
typedef Hashtable<OrderNodeKey *, HashsetOrderNode *, uintptr_t, PTRSHIFT> HashtableNodeToNodeSet;
typedef Hashtable<OrderPair *, OrderPair *, uintptr_t, PTRSHIFT, order_pair_hash_function, order_pair_equals> HashtableOrderPair;
typedef Hashtable<void *, void *, uintptr_t, PTRSHIFT> CloneMap;
-
-
typedef Hashtable<Set *, EncodingNode *, uintptr_t, PTRSHIFT> HashtableEncoding;
typedef SetIterator<OrderNodeKey *, uintptr_t, PTRSHIFT, order_node_hash_function, order_node_equals> SetIteratorOrderNode;
typedef SetIterator<OrderElement *, uintptr_t, PTRSHIFT, order_element_hash_function, order_element_equals> SetIteratorOrderElement;
typedef SetIterator<DOREdge *, uintptr_t, PTRSHIFT, doredge_hash_function, doredge_equals> SetIteratorDOREdge;
+typedef SetIterator<Boolean *, uintptr_t, PTRSHIFT> SetIteratorBoolean;
+typedef SetIterator<uint64_t, uint64_t, 0> SetIterator64Int;
+typedef SetIterator<TunableSetting *, uintptr_t, 4, tunableSettingHash, tunableSettingEquals> SetIteratorTunableSetting;
#endif
timetaken.put(problem, time);
}
+void TunerRecord::print(){
+ model_print("*************TUNER NUMBER=%d***********\n", tunernumber);
+ tuner->print();
+ model_print("&&&&&&&&&&&&&USED SETTINGS &&&&&&&&&&&&\n");
+ tuner->printUsed();
+ model_print("\n");
+}
+
long long TunerRecord::getTime(Problem *problem) {
if (timetaken.contains(problem))
return timetaken.get(problem);
updateTimeout(problem, metric);
snprintf(buffer, sizeof(buffer), "tuner%uused", execnum);
tuner->getTuner()->addUsed(buffer);
+ explored.push(tuner);
}
//Increment execution count
execnum++;
model_print("Mutating %u settings\n", settingsToMutate);
while (settingsToMutate-- != 0) {
newTuner->randomMutate();
+ if(hasExplored(newTuner)){
+ model_print("Note:A repetitive tuner has found\n");
+ settingsToMutate++;
+ }
}
return newTuner;
}
+bool MultiTuner::hasExplored(SearchTuner *newTuner){
+ for (uint i=0; i< explored.getSize(); i++){
+ SearchTuner *tuner = explored.get(i)->getTuner();
+ if(tuner->isSubTunerof(newTuner)){
+ return true;
+ }
+ }
+ return false;
+}
+
TunerRecord *MultiTuner::tune(TunerRecord *tuner) {
TunerRecord *bestTuner = NULL;
double bestScore = DBL_MAX;
void updateTuner(SearchTuner *_newtuner) {tuner = _newtuner;}
long long getTime(Problem *problem);
void setTime(Problem *problem, long long time);
+ void print();
private:
SearchTuner *tuner;
Vector<Problem *> problems;
long long evaluate(Problem *problem, TunerRecord *tuner);
double evaluateAll(TunerRecord *tuner);
SearchTuner *mutateTuner(SearchTuner *oldTuner, uint k);
+ bool hasExplored(SearchTuner *newTuner);
void mapProblemsToTuners(Vector<TunerRecord *> *tunerV);
void improveTuners(Vector<TunerRecord *> *tunerV);
TunerRecord *tune(TunerRecord *tuner);
Vector<TunerRecord *> allTuners;
+ Vector<TunerRecord *> explored;
Vector<Problem *> problems;
Vector<TunerRecord *> tuners;
uint budget;
model_print("\n");
}
-unsigned int tunableSettingHash(TunableSetting *setting) {
- return setting->hasVar ^ setting->type1 ^ setting->type2 ^ setting->param;
-}
-
-bool tunableSettingEquals(TunableSetting *setting1, TunableSetting *setting2) {
- return setting1->hasVar == setting2->hasVar &&
- setting1->type1 == setting2->type1 &&
- setting1->type2 == setting2->type2 &&
- setting1->param == setting2->param;
-}
ostream &operator<<(ostream &os, const TunableSetting &ts)
{
}
}
+bool SearchTuner::isSubTunerof(SearchTuner *newTuner){
+ SetIteratorTunableSetting *iterator = usedSettings.iterator();
+ while (iterator->hasNext()) {
+ TunableSetting *setting = iterator->next();
+ if(!newTuner->settings.contains(setting)){
+ return false;
+ } else{
+ TunableSetting *newSetting = newTuner->settings.get(setting);
+ if(newSetting->selectedValue != setting->selectedValue){
+ return false;
+ }
+ }
+ }
+ delete iterator;
+ return true;
+}
+
SearchTuner *SearchTuner::copyUsed() {
SearchTuner *tuner = new SearchTuner();
SetIteratorTunableSetting *iterator = usedSettings.iterator();
friend class SerializeTuner;
};
-unsigned int tunableSettingHash(TunableSetting *setting);
-bool tunableSettingEquals(TunableSetting *setting1, TunableSetting *setting2);
-
-typedef Hashset<TunableSetting *, uintptr_t, 4, tunableSettingHash, tunableSettingEquals> HashsetTunableSetting;
-typedef SetIterator<TunableSetting *, uintptr_t, 4, tunableSettingHash, tunableSettingEquals> SetIteratorTunableSetting;
-
class SearchTuner : public Tuner {
public:
SearchTuner();
void setVarTunable(VarType vartype, TunableParam param, TunableDesc *descriptor, uint value);
void setVarTunable(VarType vartype1, VarType vartype2, TunableParam param, TunableDesc *descriptor, uint value);
SearchTuner *copyUsed();
+ bool isSubTunerof(SearchTuner *newTuner);
void randomMutate();
uint getSize() { return usedSettings.getSize();}
void print();
TUNABLEHEADER = ["DECOMPOSEORDER", "MUSTREACHGLOBAL", "MUSTREACHLOCAL", "MUSTREACHPRUNE", "OPTIMIZEORDERSTRUCTURE",
"ORDERINTEGERENCODING", "PREPROCESS", "NODEENCODING", "EDGEENCODING", "MUSTEDGEPRUNE", "ELEMENTOPT",
"ENCODINGGRAPHOPT", "ELEMENTOPTSETS", "PROXYVARIABLE", "MUSTVALUE", "NAIVEENCODER", "VARIABLEORDER",
- "PROBLEM","SATTIME", "EXECTIME"]
+ "PROBLEM","SATTIME", "EXECTIME","TUNERNUMBER"]
configs = {"EXECTIME": "-",
"SATTIME":"-",
def loadProblemName(row,filename):
with open(filename) as f:
row["PROBLEM"] = f.readline().replace("\n","")
-
-def main():
+def loadTunerNumber(row, filename):
+ with open(filename) as f:
+ row["TUNERNUMBER"] = f.readline().replace("\n","")
+def analyzeLogs(file):
global configs
argprocess = AutoTunerArgParser()
- file = open("tuner.csv", "w")
printHeader(file)
+ rows = []
for i in range(argprocess.getRunNumber()):
row = {"DECOMPOSEORDER" : "",
"MUSTREACHGLOBAL" : "",
"VARIABLEORDER" : "",
"PROBLEM":"",
"SATTIME":"",
- "EXECTIME": ""
+ "EXECTIME": "",
+ "TUNERNUMBER":""
}
+ loadTunerNumber(row, argprocess.getFolder() + "/tunernum" + str(i))
loadTunerInfo(row, argprocess.getFolder()+"/tuner"+str(i)+"used")
loadSolverTime(row, argprocess.getFolder()+"/log"+str(i))
loadProblemName(row, argprocess.getFolder()+"/problem"+str(i))
dump(file, row)
+ rows.append(row)
+ return rows
+
+def tunerNumberAnalysis(file, rows):
+ global TUNABLEHEADER
+ tunercount = {}
+ tunernumber = {}
+ for row in rows:
+ mystr=""
+ for i in range(18):
+ mystr+=row[TUNABLEHEADER[i]]
+ if mystr not in tunercount:
+ tunercount.update({mystr : 1})
+ tunernumber.update({mystr : str(row["TUNERNUMBER"])})
+ else :
+ tunercount[mystr] += 1
+ tunernumber[mystr] += "-" + str(row["TUNERNUMBER"])
+
+ problems = set(map(lambda x: x["PROBLEM"], rows))
+ print "Number of repititive tuners"
+ for key in tunercount:
+ if tunercount[key] > 1:
+ print key + "(ids:" + tunernumber[key] + ") = #" + str(tunercount[key])
+
+
+def main():
+ file = open("tuner.csv", "w")
+ rows = analyzeLogs(file)
+ tunerNumberAnalysis(file, rows)
file.close()
return
for d in $DUMP; do
if [[ $d = *$1* ]]; then
echo $d
- ./run.sh deserializerun "."$d $2 "../"$3 out.out
+ ./run.sh tunerrun "."$d $2 "../"$3 out.out
echo "Best tuner"
fi
done