blob: 5a828b216a92b392d0cc86a98ddc45e0affc23aa (
plain)
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
|
#include "BlackboardStrategy.h"
/*
* DO NOT ADAPT THIS FILE!!!
*/
#include <climits>
#include <ctime>
#include <random>
BlackboardStrategy::BlackboardStrategy()
{
initialize();
}
BlackboardStrategy::~BlackboardStrategy()
{
}
unsigned BlackboardStrategy::fitnessStrategy1() const { return fitnessStrategy(1); }
unsigned BlackboardStrategy::fitnessStrategy2() const { return fitnessStrategy(2); }
unsigned BlackboardStrategy::fitnessStrategy3() const { return fitnessStrategy(3); }
unsigned BlackboardStrategy::fitnessStrategy4() const { return fitnessStrategy(4); }
unsigned BlackboardStrategy::fitnessStrategy5() const { return fitnessStrategy(5); }
unsigned BlackboardStrategy::fitnessStrategy6() const { return fitnessStrategy(6); }
unsigned BlackboardStrategy::resultStrategy1() const { return resultStrategy(1); }
unsigned BlackboardStrategy::resultStrategy2() const { return resultStrategy(2); }
unsigned BlackboardStrategy::resultStrategy3() const { return resultStrategy(3); }
unsigned BlackboardStrategy::resultStrategy4() const { return resultStrategy(4); }
unsigned BlackboardStrategy::resultStrategy5() const { return resultStrategy(5); }
unsigned BlackboardStrategy::resultStrategy6() const { return resultStrategy(6); }
void BlackboardStrategy::initialize()
{
m_uBestStrategy = 0;
m_uBestResult = 0;
}
void BlackboardStrategy::setBestStrategy( unsigned uBestStrategy )
{
m_uBestStrategy = uBestStrategy;
}
void BlackboardStrategy::setBestResult( unsigned uBestResult )
{
m_uBestResult = uBestResult;
}
unsigned BlackboardStrategy::getBestStrategy() const
{
return m_uBestStrategy;
}
unsigned BlackboardStrategy::getBestResult() const
{
return m_uBestResult;
}
unsigned BlackboardStrategy::fitnessStrategy( unsigned uStrategy ) const
{
return value( uStrategy, 10000 );
}
unsigned BlackboardStrategy::resultStrategy( unsigned uStrategy ) const
{
return value( uStrategy, 1000000 );
}
unsigned BlackboardStrategy::value( unsigned uStrategy, unsigned uTotal ) const
{
std::default_random_engine cRandomEngine( unsigned(time(nullptr))+uStrategy );
std::uniform_real_distribution<double> cDistribution( 0, 10 );
unsigned nResult = 0;
double dStep = double(0xffffffffUL) / ( uTotal+uStrategy );
for ( unsigned n = 0; n < uTotal; n++ )
nResult += unsigned( dStep * cDistribution( cRandomEngine ) );
return nResult;
}
|