Giter Site home page Giter Site logo

olmallet81 / galgo-2.0 Goto Github PK

View Code? Open in Web Editor NEW
212.0 212.0 53.0 148 KB

Genetic Algorithm in C++ with template metaprogramming and abstraction for constrained optimization

License: MIT License

C++ 100.00%
chromosome cpp11 cross evolutionary-algorithm genetic-algorithm metaprogramming mutations

galgo-2.0's People

Contributors

olmallet81 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

galgo-2.0's Issues

Integer parameter

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?

Segmentation fault

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?

The problems of crossover (maybe big bug)

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!

bug with differing endcoding sizes

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

run-time number of parameters

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!

ga.tolerance

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;
 }

Specific representations

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!

Objective function defined within main

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

ga.run()

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!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.