Bug fix: typos
[satune.git] / src / Tuner / basictuner.h
1 /*
2  * To change this license header, choose License Headers in Project Properties.
3  * To change this template file, choose Tools | Templates
4  * and open the template in the editor.
5  */
6
7 /*
8  * File:   basictuner.h
9  * Author: hamed
10  *
11  * Created on December 17, 2018, 2:02 PM
12  */
13
14 #ifndef BASICTUNER_H
15 #define BASICTUNER_H
16 #include "mymemory.h"
17 #include "classlist.h"
18 #include "cppvector.h"
19 #include "hashtable.h"
20
21 #define TUNERUNSETVALUE -1
22 #define AUTOTUNERFACTOR 0.3
23
24 class Problem {
25 public:
26         Problem(const char *problem);
27         char *getProblem() {return problem;}
28         inline int getResult() {return result;}
29         inline int getProblemNumber() {return problemnumber;}
30         inline void setResult(int res) {result = res;}
31         inline void setProblemNumber(int probNum) {problemnumber = probNum;}
32         inline long long getBestTime() {return besttime ;}
33         inline void setBestTime(long long time) {besttime = time;}
34         ~Problem();
35         CMEMALLOC;
36 private:
37         int problemnumber;
38         int result;
39         char *problem;
40         long long besttime;
41 };
42
43 class TunerRecord {
44 public:
45         TunerRecord(SearchTuner *_tuner) : tuner(_tuner), tunernumber(-1), isduplicate(false) {}
46         TunerRecord(SearchTuner *_tuner, int _tunernumber) : tuner(_tuner), tunernumber(_tunernumber), isduplicate(false) {}
47         SearchTuner *getTuner() {return tuner;}
48         void inline addProblem(Problem *problem) {problems.push(problem);}
49         TunerRecord *changeTuner(SearchTuner *_newtuner);
50         void updateTuner(SearchTuner *_newtuner) {tuner = _newtuner;}
51         long long getTime(Problem *problem);
52         void setTime(Problem *problem, long long time);
53         inline void setTunerNumber(int numb) {tunernumber = numb;}
54         inline int getTunerNumber() {return tunernumber;}
55         inline uint problemsSize() {return problems.getSize();}
56         inline void setDuplicate(bool _duplicate) { isduplicate = _duplicate;}
57         inline bool isDuplicate() {return isduplicate;}
58         inline Problem *getProblem(uint index) {return problems.get(index);}
59         void print();
60         void printProblemsInfo();
61         CMEMALLOC;
62 private:
63         SearchTuner *tuner;
64         Vector<Problem *> problems;
65         Hashtable<Problem *, long long, uint64_t> timetaken;
66         int tunernumber;
67         friend void clearVector(Vector<TunerRecord *> *tunerV);
68         bool isduplicate;
69 };
70
71 class BasicTuner {
72 public:
73         BasicTuner(uint _budget, uint _timeout);
74         void addProblem(const char *filename);
75         void addTuner(SearchTuner *tuner);
76         void printData();
77         virtual ~BasicTuner();
78         virtual void tune() = 0;
79         CMEMALLOC;
80 protected:
81         long long evaluate(Problem *problem, TunerRecord *tuner);
82         /**
83          * returns the index of the tuner which is subtune of
84          * the newTuner
85          * @param newTuner
86          * @return
87          */
88         int subTunerIndex(SearchTuner *newTuner);
89         bool tunerExists(TunerRecord *tunerRec);
90         SearchTuner *mutateTuner(SearchTuner *oldTuner, uint k);
91         void updateTimeout(Problem *problem, long long metric);
92         Vector<TunerRecord *> allTuners;
93         Vector<TunerRecord *> explored;
94         Vector<Problem *> problems;
95         Vector<TunerRecord *> tuners;
96         uint budget;
97         uint timeout;
98         int execnum;
99 };
100
101 #endif/* BASICTUNER_H */
102