-
Notifications
You must be signed in to change notification settings - Fork 0
/
Population.h
104 lines (80 loc) · 2.24 KB
/
Population.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
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
#pragma once
#include <OB/CORBA.h>
#include "Timetable.h"
#include "GeneticTT.h"
#include <vector>
typedef std::vector<Timetable*> Timetables;
#define MIN_POP_SIZE 10
class Population
{
public:
Population(const Population& population);
Population(const Timetables& timetables);
Population(){};
~Population();
const Population& operator=(const Population& population);
const Population& operator=(const Timetables& timetables);
const Timetables& getPopulation() { return _timetables; }
void addIndividual(Timetable* individual);
bool hasExtincted() { return _timetables.size() < MIN_POP_SIZE; }
void clear();
Genetic::IndividualSeq* pack();
void unpack(const Genetic::IndividualSeq* dest);
void append(const Genetic::IndividualSeq* dest);
private:
Timetables _timetables;
};
inline Population::Population(const Population& population)
{
*this = population;
}
inline Population::Population(const Timetables& timetables)
{
*this = timetables;
}
inline Population::~Population()
{
clear();
}
inline const Population&
Population::operator=(const Population& population)
{
clear();
const Timetables& timetables = population._timetables;
Timetables::const_iterator it;
for (it = timetables.begin(); it != timetables.end(); ++it) {
_timetables.push_back(new Timetable(**it));
}
return *this;
}
inline const Population&
Population::operator=(const Timetables& timetables)
{
clear();
_timetables = timetables;
return *this;
}
inline void
Population::clear()
{
Timetables::iterator it;
for (it = _timetables.begin(); it != _timetables.end(); ++it)
delete *it;
_timetables.clear();
}
inline void
Population::addIndividual(Timetable* individual)
{
_timetables.push_back(individual);
}
inline std::ostream&
operator<<(std::ostream& out, Population& population)
{
const Timetables& tts = population.getPopulation();
out << "[";
for (auto it = tts.begin(); it != tts.end(); ++it) {
Timetable* tt = *it;
out << *tt;
}
out << "]";
}