Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation fault #2

Open
thewoz opened this issue Jan 22, 2018 · 2 comments
Open

Segmentation fault #2

thewoz opened this issue Jan 22, 2018 · 2 comments

Comments

@thewoz
Copy link

thewoz commented Jan 22, 2018

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?

@thewoz
Copy link
Author

thewoz commented Jan 23, 2018

Some time the error is here:

    // moving new population into current population for next generation
    curpop = std::move(newpop);

others time here:

  // encoding parameter random value
  std::string str = x->encode();

However seem that the real error comes from the line:

  // decoding chromosome: converting chromosome string into a real value
  param[i] = x->decode(chr.substr(ptr->idx[i++], x->size()));

I.e. the line that generate the warning in the first place

@thewoz
Copy link
Author

thewoz commented Jan 23, 2018

I solve in this way:

  param[i] = x->decode(chr.substr(ptr->idx[i], x->size()));
  i++;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant