The part where I get an error (more specifically, where I get a popup saying Debug error! Abort () has been called) is the part where I try to do a crossover.
for (int i = 0; i < number_of_variables; i++)
{
int gene1 = gene_selection(rng);
std::cout << gene1 << " ";
if (gene1 == 0)
{
std::cout << "test 0";
new_individuals[k].chromosomes[0].at(i) = individuals[father].chromosomes[0].at(i);
}
else if (gene1 == 1)
{
std::cout << "test 1";
new_individuals[k].chromosomes[0].at(i) = individuals[mother].chromosomes[0].at(i);
}
}
It gets far enough to display "test 0" or "test 1" but it won't actually assign the genes from the father/mother to the new_individual.
I've tried changing up the line where it assigns the old genes to the new individual, but regardless of what I try I can't get it working.
If anyone could show me where (or how) I'm messing up, I'd be very thankful :)
Edit: Stepping through the debugger, I get the following
http://prnt.sc/b0iprq Unhandled exception at .... in LearnCPP.exe: Microsoft C++ exception: std::out_of_range at memory location .....
Another edit: Just to be clear, it's this exact line where the abort occurs:
new_individuals[k].chromosomes[0].at(i) = individuals[father].chromosomes[0].at(i);