#include #include #include #include #include #include #include #include #include using namespace std; string generateValue() { char trash[100]; string x = itoa(rand() % 1000,trash,10); if (x.size() == 2) { x = "0" + x; } else if (x.size() == 1) { x = "00" + x; } return x; } string generateVegetable() { string taste = generateValue(); string colour = generateValue(); string size = generateValue(); return taste + colour + size; } void generatePopulation(string * population,int length) { int i; for(i=0;i&i, const pair&j) { return i.first > j.first; } void selection(string * population,string * parents, int populationSize, int parentsNumber) { int i; pair fitnessTable[populationSize]; for(i=0;i= nextGenSize) { break; } else { nextGen[counter] = parents[i]; counter +=1; } } for(i=0;i= nextGenSize) { break; } else { for(j=i;j= nextGenSize) { break; } else { string couple[2]; couple[0] = parents[i]; couple[1] = parents[j]; nextGen[counter] = cross(couple); counter += 1; } } } } } int main() { srand(time(0)); int i; int populationSize = 50; int parentsNumber = 5; int maxPopulationSize = 1000; string population[populationSize]; int nextGenSize; generatePopulation(population,populationSize); cout << "Wstepna populacja:" << endl; for(i=0;i