-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathstrategyStore.cpp
97 lines (77 loc) · 2.35 KB
/
strategyStore.cpp
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
#include <iostream>
#include "strategyStore.h"
using namespace std;
void StrategyStore::sortStrategies ( Strategy strArray [], int size ) {
Strategy tempStrategy;
for (int i = 0; i < size - 1; i++ ) {
for (int j = i + 1; j < size; j++) {
if (strArray [ j ].getScore ( ) > strArray [ i ].getScore ( ) ){
tempStrategy = strArray [ j ];
strArray [ j ] = strArray [ i ];
strArray [ i ] = tempStrategy;
}
}
}
}
void StrategyStore::addStrategy ( Strategy& s ) {
Strategy old;
int position = 0;
bool done = false;
sortStrategies ( strategies , NR_AGENTS );
for ( int i = 0; i < NR_AGENTS; i++ ) {
if ( s.getScore ( ) > strategies [ i ].getScore( ) ) {
position = i;
old = strategies [ position ];
strategies [ position ] = s;
for ( int j = NR_AGENTS - 1; j > position + 1; j-- ) {
strategies [ j ] = strategies [ j - 1];
}
strategies [ position + 1 ] = old;
break;
}
}
}
void StrategyStore::printStore ( void ) {
for ( int i = 0; i < NR_AGENTS; i++ ) {
//cout << endl << " position: " << i << " " << strategies [ i ].getScore ( ) << " birthGen: " << strategies [ i ].getBirthGeneration ( );
//cout << " mutationCount: " << strategies [ i ].getMutationCount ( ) ;
// strategies [ i ].printStrategy ( );
}
cout << endl << " PrintStore::generation top session score: " << strategies [ 0 ].getScore ( ) << endl;
}
void StrategyStore::getOne ( Strategy& str, int rank ) {
str = strategies [ rank ];
}
void StrategyStore::resetRanks ( void ) {
for ( int i = 0; i < NR_AGENTS; i++ )
{
strategies [ i ].updateScore ( -5555555 );
}
}
int StrategyStore::calculateGenerationAverage ( ) {
int sum = 0;
for ( int i = 0; i < NR_AGENTS; i++) {
sum += strategies [ i ].getScore ( );
}
return ( sum / NR_AGENTS );
}
int StrategyStore::averageSimilarity () {
int simiCount = 0;
int comparisons = 0;
for ( int i = 0; i < NR_AGENTS - 1; i++ ) {
for ( int j = i + 1; j < NR_AGENTS; j++ ){
simiCount += similarityCount ( strategies [ i ], strategies [ j ] );
comparisons++;
}
}
return simiCount / comparisons;
}
bool StrategyStore::exists (Strategy& str) {
bool diffFound;
int diffPos;
for (int j = 0; j < NR_AGENTS; j++) {
if ( identical (str, strategies [ j ], diffPos ) )
return true;
}
return false;
}