olmallet81 / galgo-2.0 Goto Github PK
View Code? Open in Web Editor NEWGenetic Algorithm in C++ with template metaprogramming and abstraction for constrained optimization
License: MIT License
Genetic Algorithm in C++ with template metaprogramming and abstraction for constrained optimization
License: MIT License
what is the reason why GALGO only supports double and float parameters? In my case the parameters are either 0 or 1 int values. Is it enough to use an int-random function or are there any other problems coming up in the mutation and crossover functions with an Integer GA problem?
Hi,
I compiled the code with:
g++ -std=c++11 -O3 -Wall example.cpp -o run
the compiler give me back the following message:
In file included from example.cpp:5:
In file included from ./Galgo.hpp:77:
./Chromosome.hpp:149:49: warning: unsequenced modification and access to 'i' [-Wunsequenced]
param[i] = x->decode(chr.substr(ptr->idx[i++], x->size()));
~ ^
./Population.hpp:107:18: note: in instantiation of member function 'galgo::Chromosome<double>::evaluate' requested here
curpop[0]->evaluate();
^
./GeneticAlgorithm.hpp:195:8: note: in instantiation of member function 'galgo::Population<double>::creation' requested here
pop.creation();
^
example.cpp:49:7: note: in instantiation of member function 'galgo::GeneticAlgorithm<double>::run' requested here
ga.run();
^
1 warning generated.
then I try ./run
This is the output:
Running Genetic Algorithm...
----------------------------
Generation = 0 | X1 = 0.00000 | X2 = 0.99405 | F(x) = -99.81334
Segmentation fault: 11
What I'm missing?
hi, I am so confused and doubt the code about the following.
I printed the chromosome as following.
pos: 28
-------1-------
x.chr_before: 11100101111010110010110011000011
x.chr_after : 11100101111010110010110011000011
chr_after : 11100101111010110010110011000
-------2-------
x.chr_before: 11100111011010100010110011010001
x.chr_after : 11100111011010100010110011010001
chr_after : 11100111011010100010110011010
-------3-------
start: 29 x.chrsize: 32
x.chr_before: 11100111011010100010110011010001
x.chr_after : 11100111011010100010110011010001
chr_after : 11100101111010110010110011000001
-------4-------
start: 29 x.chrsize: 32
x.chr_before: 11100101111010110010110011000011
x.chr_after : 11100101111010110010110011000011
chr_after : 11100111011010100010110011010011
-------5-------
Nu_evaluation_re: 5 s: 1110010111111011 GetValue: 58875 param[0]: 0.89837 s: 0010110011000001 GetValue: 11457 param[1]: 0.17482 fitness: -5.09955
Nu_evaluation_re- 6 s: 1110011101101110 GetValue: 59246 param[0]: 0.90404 s: 0010110011010011 GetValue: 11475 param[1]: 0.17510 fitness: -4.38073
we could see, the 32 bits strings are divided to two 16 bits strings as the chromosomes of two params of a two dimesions function (in my example). But you do crossover for 32 bits before divided it to two 16 bits strings. This is not make sense. In EA, we need to do crossover for each chromosome, not do the crossover for a long string and then divided the long string into many short chromosomes for many individuals. Maybe this is why your code is not learning fast as the EA expected in my example.
Please let me know am I right?
Because I already integrated your code into my project. But the performance is not good, thus I checked everything and found the doubt points.
Looking forward your reply.
Thanks!
If I use
galgo::Parameter<float,16> a(0,1)
galgo::Parameter<float,4> b(0,1)
then ptr->idx == {0,4} which is wrong and should be {0,16}
(at least the way idx is currently used)
In the consequence decoding the chromosome delivers wrong values
Thanks for sharing!
It would be useful to pass the parameters to the GeneticAlgorithm constructor in a std::vector to add flexibility, or to have an addParameter method in the class
Hello, you are welcome, well GALGO 1.0 was written as such, the constructor was taking vectors for lower and upper bounds but as I'm a big fan of TMP I wrote a second version using parameter pack just for fun
Ok thanks!
In the function ga.run(), the 'bestResult' and 'prevBestResult' was equal before iterations.
T bestResult = pop(0)->getTotal();
T prevBestResult = bestResult;
So, if i set ga.tolerance to a user-define value, the program will exit with the code below, because the reason i noted:
// checking convergence
if (tolerance != 0.0) {
if (fabs(bestResult - prevBestResult) < fabs(tolerance)) {
break;
}
prevBestResult = bestResult;
}
May be you can add nogen > 1
to fix this problem:
// checking convergence
if (tolerance != 0.0 && nogen > 1) {
if (fabs(bestResult - prevBestResult) < fabs(tolerance)) {
break;
}
prevBestResult = bestResult;
}
hi,
I saw the representation in GALGO is Bit string representation. And then, GALGO converts the bit string into the real-value. Does the GALGO support Real-valued representation? if yes, how can I set up in the GALGO?
Thanks!
Hi,
I was wondering if it's possible to define the objective function within the main() function. I've been trying to do this with lambda functions, but I haven't had any luck.
The reason I want to do this is because I'm trying to incorporate GALGO into a larger OpenFoam code, where for a variety of reasons, I can only really access certain things from within my main() function.
I'd really appreciate any help anyone could offer.
All the best,
Tom
hi,
// running genetic algorithm
ga.run();
here ga.run()
run the iterations inside until the termination. But I want to take the iteration out of ga.run()
. That means ga.run()
only feedback the populations, fitnesses, and best for a generation. For instance, I would like the code like
for (int generation = 0; generation < maxGenerations; generation++)
{
ga.run(); //feedback the populations, fitnesses, and best for a generation
}
How can I do this?
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.