BUG FIX when there is no usedSettings
[satune.git] / src / Tuner / searchtuner.h
1 #ifndef SEARCHTUNER_H
2 #define SEARCHTUNER_H
3 #include "classlist.h"
4 #include "tunable.h"
5 #include "structs.h"
6 #include <ostream>
7 using namespace std;
8
9 class TunableSetting {
10 public:
11         TunableSetting(VarType type, TunableParam param);
12         TunableSetting(VarType type1, VarType type2, TunableParam param);
13         TunableSetting(TunableParam param);
14         TunableSetting(TunableSetting *ts);
15         void setDecision(int _low, int _high, int _default, int _selection);
16         void print();
17         friend std ::ostream &operator<< (std::ostream &stream, const TunableSetting &matrix);
18         CMEMALLOC;
19 private:
20         bool hasVar;
21         VarType type1;
22         VarType type2;
23         TunableParam param;
24         int lowValue;
25         int highValue;
26         int defaultValue;
27         int selectedValue;
28         friend unsigned int tunableSettingHash(TunableSetting *setting);
29         friend bool tunableSettingEquals(TunableSetting *setting1, TunableSetting *setting2);
30         friend class SearchTuner;
31         friend class SerializeTuner;
32 };
33
34 class SearchTuner : public Tuner {
35 public:
36         SearchTuner();
37         SearchTuner(const char *filename, bool addused = false);
38         ~SearchTuner();
39         virtual int getTunable(TunableParam param, TunableDesc *descriptor);
40         int getVarTunable(VarType vartype, TunableParam param, TunableDesc *descriptor);
41         virtual int getVarTunable(VarType vartype1, VarType vartype2, TunableParam param, TunableDesc *descriptor);
42         void setTunable(TunableParam param, TunableDesc *descriptor, uint value);
43         void setVarTunable(VarType vartype, TunableParam param, TunableDesc *descriptor, uint value);
44         void setVarTunable(VarType vartype1, VarType vartype2, TunableParam param, TunableDesc *descriptor, uint value);
45         SearchTuner *copyUsed();
46         bool isSubTunerof(SearchTuner *newTuner);
47         void randomMutate();
48         uint getSize() { return usedSettings.getSize();}
49         void print();
50         void printUsed();
51         void serialize(const char *file);
52         void serializeUsed(const char *file);
53         void addUsed(const char *file);
54         bool equalUsed(SearchTuner *tuner);
55         CMEMALLOC;
56 protected:
57         /** Used Settings keeps track of settings that were actually used by
58            the example. Mutating settings may cause the Constraint Compiler
59            not to query other settings.*/
60         HashsetTunableSetting usedSettings;
61         /** Settings contains all settings. */
62         HashsetTunableSetting settings;
63 };
64
65 #endif