From 77bd6d7ee48fc7c9c287103d6626cdbf5e4b7828 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20D=C5=82ugo=C5=82=C4=99cki?= Date: Sun, 3 May 2015 22:35:19 +0200 Subject: [PATCH] Integrate Command Library. --- Makefile.am | 3 +-- src/main.cpp | 24 ++++++++++++++++++------ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/Makefile.am b/Makefile.am index a46ee8d..5dedfea 100644 --- a/Makefile.am +++ b/Makefile.am @@ -34,8 +34,7 @@ nodist_bin_genetic_SOURCES = \ bin_genetic_CPPFLAGS = \ $(bin_genetic_CFLAGS) \ -I$(top_srcdir)/include \ - -Wall -pedantic -Wextra \ - -Wl,--export-dynamic + -Wall -pedantic -Wextra bin_genetic_LDADD = \ $(bin_genetic_LIBS) diff --git a/src/main.cpp b/src/main.cpp index a208bbf..fc396cd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,3 +1,6 @@ +#include +#include + #include "gene.h" #include "chromosome.h" #include "generation.h" @@ -15,7 +18,13 @@ using namespace genetic; -int main() { +int chromosomeSize = 10; +int generationSize = 10; +int generationLimit = 100; +double crossoverChance = 0.75; +double mutationChance = 0.01; + +int main(int argc, char* argv[]) { typedef Gene _Gene; typedef Chromosome<_Gene> _Chromosome; @@ -28,16 +37,19 @@ int main() { typedef Algorithm<_Chromosome, _Selection, _Crossover, _Mutation, _Fitness> _Algorithm; typedef GenerationLimitCondition<_Chromosome> _Condition; - const int chromosomeSize = 10; - const int generationSize = 500; - const double crossoverChance = 0.75; - const double mutationChance = 0.01; + command::Command command(argc, argv, { + new command::Option("--chromosome-size", "Chromosome size", [](int value)->void { chromosomeSize = value; }), + new command::Option("--generation-size", "Generation size", [](int value)->void { generationSize = value; }), + new command::Option("--crossover", "Crossover chance", [](float value)->void { crossoverChance = value; }), + new command::Option("--mutation", "Mutation chance", [](float value)->void { mutationChance = value; }), + new command::Option("--generation-limit", "Limit of generations", [](float value)->void { mutationChance = value; }), + }); _Fitness fitness(0.5, 2.5); _Generator generationGenerator(generationSize, chromosomeSize); _Algorithm algorithm(generationGenerator, fitness, crossoverChance, mutationChance); - _Condition condition(10000); + _Condition condition(generationLimit); algorithm.searchForResult(condition); -- 2.30.2