Prześlij pliki do ''

This commit is contained in:
Karol Piotrowski 2020-05-26 22:05:43 +00:00
parent 4856536a29
commit ffb1c10a03

11
gmo.cpp
View File

@ -251,7 +251,7 @@ void crossover(string * parents,string * nextGen,int parentsNumber,int nextGenSi
} }
string * genetic_algorithm(string * population, int populationSize, int parentsNumber) { void genetic_algorithm(string * population, int populationSize, int parentsNumber,string * outcome, int outcomeSize) {
int iteration,i; int iteration,i;
for(iteration=0;iteration<5;iteration++) { for(iteration=0;iteration<5;iteration++) {
@ -269,23 +269,22 @@ string * genetic_algorithm(string * population, int populationSize, int parentsN
} }
delete[] nextGen; delete[] nextGen;
} }
string vegetablesForPlanting[20]; ranking(population,outcome,populationSize,outcomeSize);
ranking(population,vegetablesForPlanting,populationSize,20);
return vegetablesForPlanting;
} }
int main() { int main() {
srand(time(0)); srand(time(0));
int i;
int populationSize = 500; int populationSize = 500;
int parentsNumber = populationSize - 5; int parentsNumber = populationSize - 5;
string * population = new string[populationSize]; string * population = new string[populationSize];
generatePopulation(population,populationSize); generatePopulation(population,populationSize);
string * vegetablesForPlanting = genetic_algorithm(population, populationSize, parentsNumber); string vegetablesForPlanting[20];
genetic_algorithm(population, populationSize, parentsNumber,vegetablesForPlanting, 20);