-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtesthappyfaces.cpp
More file actions
64 lines (51 loc) · 2.64 KB
/
testhappyfaces.cpp
File metadata and controls
64 lines (51 loc) · 2.64 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
56
57
58
59
60
61
62
63
64
/***************************************************************************
testhappyfaces.cpp -
for solving the happy faces puzzle
-------------------
begin : Wed Mar 03 2004
copyright : (C) 2004 by Craig Nicol
email : craig.nicol@gmail.com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include "GAhappyfaces.h"
//#include "GApopulation.h"
int main(int argc, char **argv)
{
HappyFaces test;
int rseed;
for (int i=0; i < 25; ++i)
std::cout << i << ":\n" << test.to_string(test.moves[i]);
std::cout << "==============\n";
std::cout << test.to_string() << "==" << test.count_happy() << std::endl;;
test.make_move(2,3);
std::cout << "==============\n";
std::cout << test.to_string() << "==" << test.count_happy() << std::endl;;
std::cout << "========================\nGA test\n========================\n";
double mutationrate = 0.7; // was 0, 0.7
double chrommutationrate = 0.6; // was 0.8, 0.6
mg_GA::population<mg_GA::chrom_cached_lazy<int, 50, 25> > happy_pop(mutationrate,chrommutationrate,0.1,1000,mg_GA::PC_RANK,mg_GA::SM_RANK);
happy_pop.setverbose(1,50);
std::cout << "Enter Seed Value: ";
std::cin >> rseed;
srand(rseed);
HappyFaces happy_func;
mg_GA::twopointx<int, 50> happy_xover;
mg_GA::random_mutate<int, 50> mut_func;
happy_pop.initialise((mg_GA::fitness_base<int,50> *)&happy_func, (mg_GA::crossover_base<int,50> *)&happy_xover, &mut_func);
std::cout << "Range before: " << happy_pop.min() << " - " << happy_pop.max() << std::endl;
happy_pop.run_once();
std::cout << "Range after: " << happy_pop.min() << " - " << happy_pop.max() << std::endl;
happy_pop.run(1000);
std::cout << "Range final: " << happy_pop.min() << " - " << happy_pop.max() << std::endl;
std::cout << "Chromosome range: " << happy_pop.min_chrom().showchrom() << " < " << happy_pop.max_chrom().showchrom() << std::endl;
return EXIT_SUCCESS;
};