Repository navigation
Expand file tree
/
Copy pathFitness.cpp
More file actions
58 lines (44 loc) · 1.65 KB
/
Copy pathFitness.cpp
File metadata and controls
58 lines (44 loc) · 1.65 KB
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
#include <iostream>
#include <limits>
#include "Fitness.h"
#include "Individual.h"
using namespace std;
double ClassicFitnessFunction::evaluate(const Individual& individual, shared_ptr<Connection> & conn, string dbName, string tableName, string targetVarName, string primaryKeyName) const
{
vector<pair<int,double>> targetVarNames = conn->getTargetVarValues(targetVarName, primaryKeyName, tableName);
return this->evaluate(individual, conn, dbName, tableName, targetVarNames);
}
double ClassicFitnessFunction::evaluate(const Individual& individual, shared_ptr<Connection> & conn, string dbName, string tableName, const vector<pair<int, double>>& targetVarValues) const
{
double acc = 0.0;
int rowCnt = 0;
for (const auto& x : targetVarValues) {
rowCnt += 1;
int rowIdx = x.first;
double target = x.second;
double result = individual.evaluate(conn, dbName, tableName, rowIdx);
acc += abs(target - result);
}
double score = ( - (acc / rowCnt)) * (1 + (individual.getMaxDepth() * 0.01));
if (isnan(score)) {
return - numeric_limits<double>::infinity();
}
return score;
}
double ClassicFitnessFunction::evaluate(const Individual& individual, shared_ptr<map<int, map<string, double>>> dbMapPtr, const vector<pair<int, double>>& targetVarValues) const
{
double acc = 0.0;
int rowCnt = 0;
for (const auto& x : targetVarValues) {
rowCnt += 1;
int rowIdx = x.first;
double target = x.second;
double result = individual.evaluate(dbMapPtr->at(rowIdx));
acc += abs(target - result);
}
double score = (-(acc / rowCnt)) * (1 + (individual.getMaxDepth() * 0.01));
if (isnan(score)) {
return -numeric_limits<double>::infinity();
}
return score;
}