Integrate Command Library.
authorRafał Długołęcki <rafal@dlugolecki.net.pl>
Sun, 3 May 2015 20:35:19 +0000 (22:35 +0200)
committerRafał Długołęcki <rafal@dlugolecki.net.pl>
Sun, 3 May 2015 20:35:19 +0000 (22:35 +0200)
Makefile.am
src/main.cpp

index a46ee8d7b87eb5ec4e3a8b6f7bde1b04c42f0976..5dedfeaa88ac77ce2cd84472c5001160694fbdcc 100644 (file)
@@ -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)
index a208bbf863505071fd5af846174d223d045840c2..fc396cd8557df09f734016cbf52b69808542281c 100644 (file)
@@ -1,3 +1,6 @@
+#include <command/command.h>
+#include <command/option.h>
+
 #include "gene.h"
 #include "chromosome.h"
 #include "generation.h"
 
 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<bool> _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<int>("--chromosome-size", "Chromosome size", [](int value)->void { chromosomeSize = value; }),
+        new command::Option<int>("--generation-size", "Generation size", [](int value)->void { generationSize = value; }),
+        new command::Option<float>("--crossover", "Crossover chance", [](float value)->void { crossoverChance = value; }),
+        new command::Option<float>("--mutation", "Mutation chance", [](float value)->void { mutationChance = value; }),
+        new command::Option<float>("--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);