forked from venkatarun95/genericCC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
whisker.hh
116 lines (84 loc) · 3.68 KB
/
whisker.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#ifndef WHISKER_HH
#define WHISKER_HH
#include <string>
#include <vector>
#include "memoryrange.hh"
#include "dna.pb.h"
class Whisker {
private:
unsigned int _generation;
int _window_increment;
double _window_multiple;
double _intersend;
MemoryRange _domain;
public:
Whisker( const Whisker & other );
Whisker( const unsigned int s_window_increment, const double s_window_multiple, const double s_intersend, const MemoryRange & s_domain );
Whisker( const MemoryRange & s_domain ) : Whisker( get_optimizer().window_increment.default_value,
get_optimizer().window_multiple.default_value,
get_optimizer().intersend.default_value, s_domain ) {}
void use( void ) const { _domain.use(); }
void reset_count( void ) const { _domain.reset_count(); }
unsigned int count( void ) const { return _domain.count(); }
const unsigned int & generation( void ) const { return _generation; }
unsigned int window( const unsigned int previous_window ) const { return std::min( std::max( 0, int( previous_window * _window_multiple + _window_increment ) ), 1000000 ); }
const double & intersend( void ) const { return _intersend; }
const MemoryRange & domain( void ) const { return _domain; }
std::vector< Whisker > next_generation( void ) const;
void promote( const unsigned int generation );
std::string str( const unsigned int total=1 ) const;
std::vector< Whisker > bisect( void ) const;
void demote( const unsigned int generation ) { _generation = generation; }
RemyBuffers::Whisker DNA( void ) const;
Whisker( const RemyBuffers::Whisker & dna );
void round( void );
bool operator==( const Whisker & other ) const { return (_window_increment == other._window_increment) && (_window_multiple == other._window_multiple) && (_intersend == other._intersend) && (_domain == other._domain); }
friend size_t hash_value( const Whisker & whisker );
template < typename T >
struct OptimizationSetting
{
T min_value; /* the smallest the value can be */
T max_value; /* the biggest */
T min_change; /* the smallest change to the value in an optimization exploration step */
T max_change; /* the biggest change */
T multiplier; /* we will explore multiples of the min_change until we hit the max_change */
/* the multiplier defines which multiple (e.g. 1, 2, 4, 8... or 1, 3, 9, 27... ) */
T default_value;
std::vector< T > alternatives( const T & value ) const;
bool eligible_value( const T & value ) const;
RemyBuffers::OptimizationSetting DNA( void ) const
{
RemyBuffers::OptimizationSetting ret;
ret.set_min_value( min_value );
ret.set_max_value( max_value );
ret.set_min_change( min_change );
ret.set_max_change( max_change );
ret.set_multiplier( multiplier );
ret.set_default_value( default_value );
return ret;
}
};
struct OptimizationSettings
{
OptimizationSetting< unsigned int > window_increment;
OptimizationSetting< double > window_multiple;
OptimizationSetting< double > intersend;
RemyBuffers::OptimizationSettings DNA( void ) const
{
RemyBuffers::OptimizationSettings ret;
ret.mutable_window_increment()->CopyFrom( window_increment.DNA() );
ret.mutable_window_multiple()->CopyFrom( window_multiple.DNA() );
ret.mutable_intersend()->CopyFrom( intersend.DNA() );
return ret;
}
};
static const OptimizationSettings & get_optimizer( void ) {
static OptimizationSettings default_settings {
{ 0, 256, 1, 32, 4, 1 }, /* window increment */
{ 0, 1, 0.01, 0.5, 4, 1 }, /* window multiple */
{ 0.25, 3, 0.05, 1, 4, 3 } /* intersend */
};
return default_settings;
}
};
#endif