forked from sanshar/Block
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCell.h
76 lines (61 loc) · 1.61 KB
/
Cell.h
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
#ifndef CELL_H
#define CELL_H
#include <iostream>
#include <boost/function.hpp>
#include <boost/serialization/serialization.hpp>
#include "Gene.h"
using namespace std;
namespace genetic
{
// GA Individual defined by class Cell
class Cell
{
private:
friend class boost::serialization::access;
template <class Archive>
void serialize(Archive& ar, const unsigned int version)
{
ar & m_gen;
ar & m_fit;
}
private:
Gene m_gen;
double m_fit;
public:
static boost::function<double(const Gene&)> Evaluate;
Cell(void) { }
~Cell(void) { }
Cell(const Gene& gen) { Create(gen); }
Cell(const Cell& other)
{
m_gen = other.m_gen;
m_fit = other.m_fit;
}
Cell& operator= (const Cell& other)
{
m_gen = other.m_gen;
m_fit = other.m_fit;
return *this;
}
void Create(const Gene& gen)
{
m_gen = gen;
m_fit = Evaluate(gen);
}
inline bool operator== (const Cell& other) const { return m_fit == other.m_fit; }
inline bool operator!= (const Cell& other) const { return m_fit != other.m_fit; }
inline bool operator< (const Cell& other) const { return m_fit < other.m_fit; }
inline bool operator> (const Cell& other) const { return m_fit > other.m_fit; }
const Gene& Gen(void) const { return m_gen; }
const double& Fitness(void) const { return m_fit; }
friend ostream& operator<< (ostream& ost, const Cell& cell)
{
ost << cell.m_gen << " / f = " << scientific << cell.m_fit << flush;
return ost;
}
};
};
//#ifndef EVALUATE_H
//#include "Evaluate.h"
//#endif
#endif