-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
73 lines (58 loc) · 1.92 KB
/
main.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
#include "sdlgl.h"
#include "geneticalgorithm.h"
#include "simplegene.h"
#include "simplefitness.h"
#include "util.h"
#include "random.h"
/*
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <iostream>
using namespace std;
int main(int argc, char **argv)
{
srand(time(0));
if (argc < 2)
{
cout << "Usage: texgen image.bmp" << endl;
return 0;
}
string imagePath(argv[1]);
cout << imagePath << endl;
SDLGLMain app(imagePath);
Tai::SimpleFitness ff(&app);
Tai::GeneticAlgorithm<Tai::SimpleGene, Tai::SimpleFitness> ga(ff);
int populationSize = 1;
vector<Tai::SimpleGene> pop;
for (int i = 0; i < populationSize; ++i)
{
//pop.push_back(Tai::randomGene(int(1 + drandom()*5 )) );
pop.push_back(Tai::randomGene(1) );
}
ga.setInitialPopulation(pop);
//ga.someValue(4);
//cout << ga.someValue() << endl;
for (int c = 0; !app.quit_issued(); ++c)
{
cout << "iteration " << c << ": ";
ga.iterate();
if (c % 10 == 0)
app.renderGene(ga.bestGene());
//app.drawTargetImage();
cout << "best gene fitness=" << ga.bestGene().fitness() << ", length=" << ga.bestGene().length()/18.0 << endl;
/*cout << "worst gene fitness=" << ga.worstGene().fitness() << ", length=" << ga.worstGene().length() << endl;*/
app.processEvents();
}
//return app.run();
return 0;
}