From 5e2638f65a14a4fea3b9c99d55850d798c47bc63 Mon Sep 17 00:00:00 2001 From: Karol Piotrowski Date: Sat, 6 Jun 2020 16:21:06 +0000 Subject: [PATCH] =?UTF-8?q?Usu=C5=84=20'gmo.cpp'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gmo.cpp | 293 -------------------------------------------------------- 1 file changed, 293 deletions(-) delete mode 100644 gmo.cpp diff --git a/gmo.cpp b/gmo.cpp deleted file mode 100644 index 59cac17..0000000 --- a/gmo.cpp +++ /dev/null @@ -1,293 +0,0 @@ -#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 ranking(string * population,string * parents, int populationSize, int parentsNumber) { - - int i; - pair fitnessTable[populationSize]; - for(i=0;i fitnessTable[populationSize]; - for(i=0;i=0;j--) { - if(not exists(parentsNumber,taken,j)) { - sum += fitnessTable[j].first; - fitnessTable[j].first = sum; - } - - } - roulette = rand() % fitnessTable[0].first; - j = 0; - while(exists(parentsNumber,taken,j)) { - j += 1; - } - while(roulette > fitnessTable[j].first and j= nextGenSize) { - break; - } - else { - nextGen[counter] = parents[i]; - counter +=1; - } - } - while(counter < nextGenSize) { - 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; - } - } - } - } - } -} - - -void genetic_algorithm(string * population, int populationSize, int parentsNumber,string * outcome, int outcomeSize) { - - int iteration,i; - for(iteration=0;iteration<5;iteration++) { - string * parents = new string[parentsNumber]; - selection(population,parents,populationSize,parentsNumber); - - string * nextGen = new string[populationSize]; - crossover(parents,nextGen,parentsNumber,populationSize); - - delete[] population; - - population = new string[populationSize]; - for(i=0;i