Skip to main content
deleted 2 characters in body; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

genetic Genetic algorithm c++ final stage

genetic Genetic algorithm c++ final stage

I have written the code for a genetic algorithm and have the crossover function, mutation function, parent selector function and a function to transfer genes. Now I want to put it all together and would like to know if the following code is good programming practice or not.

Species Parents[popSize];
Species Children[popSize];

for(int gen = 0 ; gen < 100 ; gen++){
for(int i = 0; i < popSize ; i ++)
{
    int parentA = chooseParent(Parents);
    int parentB = chooseParent(Parents);
    crossOver(Parents[parentA] , Parent[ParentB] , Children[i]);
    Children[i].mutate();
}
for(int i = 0; i < popSize ; i ++)
{
    transfereGenes(Children[i], Parents[i]);
}
}

genetic algorithm c++ final stage

I have written the code for a genetic algorithm and have the crossover function, mutation function, parent selector function and a function to transfer genes. Now I want to put it all together and would like to know if the following code is good programming practice or not.

Species Parents[popSize];
Species Children[popSize];

for(int gen = 0 ; gen < 100 ; gen++){
for(int i = 0; i < popSize ; i ++)
{
    int parentA = chooseParent(Parents);
    int parentB = chooseParent(Parents);
    crossOver(Parents[parentA] , Parent[ParentB] , Children[i]);
    Children[i].mutate();
}
for(int i = 0; i < popSize ; i ++)
{
    transfereGenes(Children[i], Parents[i]);
}
}

Genetic algorithm final stage

I have written the code for a genetic algorithm and have the crossover function, mutation function, parent selector function and a function to transfer genes. Now I want to put it all together and would like to know if the following code is good programming practice or not.

Species Parents[popSize];
Species Children[popSize];

for(int gen = 0 ; gen < 100 ; gen++){
for(int i = 0; i < popSize ; i ++)
{
    int parentA = chooseParent(Parents);
    int parentB = chooseParent(Parents);
    crossOver(Parents[parentA] , Parent[ParentB] , Children[i]);
    Children[i].mutate();
}
for(int i = 0; i < popSize ; i ++)
{
    transfereGenes(Children[i], Parents[i]);
}
}
Rollback to Revision 1
Source Link
mdfst13
  • 22.4k
  • 6
  • 34
  • 70

I have written the code for a genetic algorithm and have the crossover function, mutation function, parent selector function and a function to transfer genes. Now I want to put it all together and would like to know if the following code is good programming practice or not.

Species Parents[popSize];
Species Children[popSize];

for(int gen = 0 ; gen < 100 ; gen++)
 {
    for(int i = 0; i < popSize ; i ++)
    {
        int parentA = chooseParent(Parents);
        int parentB = chooseParent(Parents);
        crossOver(Parents[parentA] , Parent[ParentB] , Children[i]);
        Children[i].mutate();
    }
    for(int i = 0; i < popSize ; i ++)
    {
        transfereGenes(Children[i], Parents[i]);
    }
}

I have written the code for a genetic algorithm and have the crossover function, mutation function, parent selector function and a function to transfer genes. Now I want to put it all together and would like to know if the following code is good programming practice or not.

Species Parents[popSize];
Species Children[popSize];

for(int gen = 0 ; gen < 100 ; gen++)
 {
    for(int i = 0; i < popSize ; i ++)
    {
        int parentA = chooseParent(Parents);
        int parentB = chooseParent(Parents);
        crossOver(Parents[parentA] , Parent[ParentB] , Children[i]);
        Children[i].mutate();
    }
    for(int i = 0; i < popSize ; i ++)
    {
        transfereGenes(Children[i], Parents[i]);
    }
}

I have written the code for a genetic algorithm and have the crossover function, mutation function, parent selector function and a function to transfer genes. Now I want to put it all together and would like to know if the following code is good programming practice or not.

Species Parents[popSize];
Species Children[popSize];

for(int gen = 0 ; gen < 100 ; gen++){
for(int i = 0; i < popSize ; i ++)
{
    int parentA = chooseParent(Parents);
    int parentB = chooseParent(Parents);
    crossOver(Parents[parentA] , Parent[ParentB] , Children[i]);
    Children[i].mutate();
}
for(int i = 0; i < popSize ; i ++)
{
    transfereGenes(Children[i], Parents[i]);
}
}

I have written the code for a genetic algorithm and have the crossover function, mutation function, parent selector function and a function to transfer genes. Now I want to put it all together and would like to know if the following code is good programming practice or not.

Species Parents[popSize];
Species Children[popSize];

for(int gen = 0 ; gen < 100 ; gen++) 
{
    for(int i = 0; i < popSize ; i ++)
    {
        int parentA = chooseParent(Parents);
        int parentB = chooseParent(Parents);
        crossOver(Parents[parentA] , Parent[ParentB] , Children[i]);
        Children[i].mutate();
    }
    for(int i = 0; i < popSize ; i ++)
    {
        transfereGenes(Children[i], Parents[i]);
    }
}

I have written the code for a genetic algorithm and have the crossover function, mutation function, parent selector function and a function to transfer genes. Now I want to put it all together and would like to know if the following code is good programming practice or not.

Species Parents[popSize];
Species Children[popSize];

for(int gen = 0 ; gen < 100 ; gen++){
for(int i = 0; i < popSize ; i ++)
{
    int parentA = chooseParent(Parents);
    int parentB = chooseParent(Parents);
    crossOver(Parents[parentA] , Parent[ParentB] , Children[i]);
    Children[i].mutate();
}
for(int i = 0; i < popSize ; i ++)
{
    transfereGenes(Children[i], Parents[i]);
}
}

I have written the code for a genetic algorithm and have the crossover function, mutation function, parent selector function and a function to transfer genes. Now I want to put it all together and would like to know if the following code is good programming practice or not.

Species Parents[popSize];
Species Children[popSize];

for(int gen = 0 ; gen < 100 ; gen++) 
{
    for(int i = 0; i < popSize ; i ++)
    {
        int parentA = chooseParent(Parents);
        int parentB = chooseParent(Parents);
        crossOver(Parents[parentA] , Parent[ParentB] , Children[i]);
        Children[i].mutate();
    }
    for(int i = 0; i < popSize ; i ++)
    {
        transfereGenes(Children[i], Parents[i]);
    }
}
Source Link
Loading