Prześlij pliki do ''
This commit is contained in:
parent
5698874420
commit
d8889d05d8
388
Main.cpp
388
Main.cpp
@ -1,4 +1,4 @@
|
||||
#include<iostream>
|
||||
#include<iostream>
|
||||
#include<stdlib.h>
|
||||
#include<windows.h>
|
||||
#include<conio.h>
|
||||
@ -8,13 +8,25 @@
|
||||
#include<math.h>
|
||||
#include<stack>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include<bits/stdc++.h>
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
|
||||
using namespace std;
|
||||
|
||||
const float maxFloat=FLT_MAX;
|
||||
int score = 0;
|
||||
int rozmiarPopulacji = 50;
|
||||
string * zebrane = new string[rozmiarPopulacji];
|
||||
string * doSadzenia = new string[20];
|
||||
|
||||
const float maxFloat=100000000000;
|
||||
const int ROW = 27;
|
||||
const int COL = 27;
|
||||
typedef pair<int, int> Pair;
|
||||
typedef pair<double, pair<int, int>> pPair;
|
||||
typedef pair<double, pair<int, int> > pPair;
|
||||
struct cell
|
||||
{
|
||||
int parent_i, parent_j;
|
||||
@ -25,6 +37,290 @@ char pole[27][27][2];
|
||||
int pozycjaTraktoraX = 1, pozycjaTraktoraY = 1;
|
||||
char currentWay = 'S';
|
||||
|
||||
string kod_genetyczny[27][27];
|
||||
|
||||
|
||||
//algorytm genetyczny
|
||||
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<length;i++) {
|
||||
population[i] = generateVegetable();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int power(int x, int y) {
|
||||
|
||||
if (y == 0) return 1;
|
||||
if (y == 1) return x;
|
||||
|
||||
int temp = power(x, y/2);
|
||||
if (y%2 == 0) return temp * temp;
|
||||
else return x * temp * temp;
|
||||
}
|
||||
|
||||
|
||||
int stringToInt(string str,int size) {
|
||||
|
||||
int x = 0;
|
||||
int i;
|
||||
reverse(str.begin(),str.end());
|
||||
|
||||
for(i=0;i<size;i++) {
|
||||
x += (str[i] - '0') * power(10,i);
|
||||
}
|
||||
|
||||
reverse(str.begin(),str.end());
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
int fitness(string vegetable) {
|
||||
|
||||
int taste = stringToInt(vegetable.substr(0,3),3);
|
||||
int colour = stringToInt(vegetable.substr(3,3),3);
|
||||
int size = stringToInt(vegetable.substr(6,3),3);
|
||||
|
||||
return (taste+colour+size)/3;
|
||||
}
|
||||
|
||||
|
||||
bool comparePair(const pair<int, string>&i, const pair<int, string>&j)
|
||||
{
|
||||
return i.first > j.first;
|
||||
}
|
||||
|
||||
|
||||
void ranking(string * population,string * parents, int populationSize, int parentsNumber) {
|
||||
|
||||
int i;
|
||||
pair <int,string> fitnessTable[populationSize];
|
||||
for(i=0;i<populationSize;i++) {
|
||||
fitnessTable[i] = make_pair(fitness(population[i]),population[i]);
|
||||
}
|
||||
|
||||
sort(fitnessTable,fitnessTable+populationSize,comparePair);
|
||||
|
||||
for(i=0;i<parentsNumber;i++) {
|
||||
parents[i] = fitnessTable[i].second;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool exists(int len, int * array, int element) {
|
||||
|
||||
int i;
|
||||
for(i=0;i<len;i++) {
|
||||
if (array[i] == element) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void selection(string * population,string * parents, int populationSize, int parentsNumber) {
|
||||
|
||||
int i,j,k;
|
||||
pair <int,string> fitnessTable[populationSize];
|
||||
for(i=0;i<populationSize;i++) {
|
||||
fitnessTable[i] = make_pair(fitness(population[i]),population[i]);
|
||||
}
|
||||
|
||||
sort(fitnessTable,fitnessTable+populationSize,comparePair);
|
||||
|
||||
int roulette;
|
||||
int taken[parentsNumber];
|
||||
int sum = 0;
|
||||
for(i=0;i<parentsNumber;i++) {
|
||||
for(j = populationSize - 1;j>=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<populationSize) {
|
||||
if(not exists(parentsNumber,taken,j)) {
|
||||
roulette -= fitnessTable[j].first;
|
||||
}
|
||||
j+=1;
|
||||
}
|
||||
parents[i] = fitnessTable[j].second;
|
||||
taken[i] = j;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
int newton(int n,int k) {
|
||||
|
||||
if (k==0 or n==k) return 1;
|
||||
else return newton(n-1,k-1) + newton(n-1,k);
|
||||
}
|
||||
|
||||
|
||||
string mutate(string child) {
|
||||
|
||||
int d3 = rand() % 3;
|
||||
string mutation = generateValue();
|
||||
switch(d3) {
|
||||
case 0:
|
||||
child = mutation + child.substr(3,6);
|
||||
break;
|
||||
case 1:
|
||||
child = child.substr(0,3) + mutation + child.substr(6,3);
|
||||
break;
|
||||
case 2:
|
||||
child = child.substr(0,6) + mutation;
|
||||
break;
|
||||
}
|
||||
|
||||
return child;
|
||||
}
|
||||
|
||||
|
||||
string cross(string parent[2]) {
|
||||
|
||||
int i;
|
||||
string child = "";
|
||||
for(i=0;i<3;i++) {
|
||||
child += parent[rand() % 2].substr(i*3,3);
|
||||
}
|
||||
if (child == parent[0] or child == parent[1]) {
|
||||
string other;
|
||||
if (child == parent[0]) other = parent[1];
|
||||
else other = parent[0];
|
||||
int d3 = rand() % 3;
|
||||
switch(d3) {
|
||||
case 0:
|
||||
child = other.substr((rand() % 3)*3,3) + child.substr(3,6);
|
||||
break;
|
||||
case 1:
|
||||
child = child.substr(0,3) + other.substr((rand() % 3)*3,3) + child.substr(6,3);
|
||||
break;
|
||||
case 2:
|
||||
child = child.substr(0,6) + other.substr((rand() % 3)*3,3);
|
||||
break;
|
||||
}
|
||||
}
|
||||
int d1000 = rand() % 1000;
|
||||
if (rand() % 100 == 0) {
|
||||
child = mutate(child);
|
||||
}
|
||||
return child;
|
||||
}
|
||||
|
||||
|
||||
void crossover(string * parents,string * nextGen,int parentsNumber,int nextGenSize) {
|
||||
|
||||
int counter = 0;
|
||||
int i,j;
|
||||
for(i=0;i<parentsNumber;i++) {
|
||||
if (counter >= nextGenSize) {
|
||||
break;
|
||||
}
|
||||
else {
|
||||
nextGen[counter] = parents[i];
|
||||
counter +=1;
|
||||
}
|
||||
}
|
||||
while(counter < nextGenSize) {
|
||||
for(i=0;i<parentsNumber;i++) {
|
||||
if (counter >= nextGenSize) {
|
||||
break;
|
||||
}
|
||||
else {
|
||||
for(j=i;j<parentsNumber;j++) {
|
||||
if (counter >= 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<populationSize;i++) {
|
||||
population[i] = nextGen[i];
|
||||
}
|
||||
delete[] nextGen;
|
||||
}
|
||||
ranking(population,outcome,populationSize,outcomeSize);
|
||||
}
|
||||
|
||||
|
||||
string przypiszKod() {
|
||||
if (doSadzenia[0] > "000000000" and doSadzenia[0] <= "999999999") {
|
||||
int i = 0;
|
||||
while(i<19, doSadzenia[i+1] >= "000000000" and doSadzenia[i+1] <= "999999999") {
|
||||
i+=1;
|
||||
}
|
||||
string temp = doSadzenia[i];
|
||||
doSadzenia[i] = "000000000";
|
||||
return temp;
|
||||
}
|
||||
else {
|
||||
return generateVegetable();
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
void color(string foregroundColor, string backgroundColor)
|
||||
{
|
||||
HANDLE hOut;
|
||||
@ -201,8 +497,21 @@ void Move(char kierunek)
|
||||
{
|
||||
if (pole[pozycjaTraktoraY - 1][pozycjaTraktoraX][0] != '#')
|
||||
{
|
||||
if (pole[pozycjaTraktoraY - 1][pozycjaTraktoraX][0] == 'B') {
|
||||
zebrane[score] = kod_genetyczny[pozycjaTraktoraY - 1][pozycjaTraktoraX];
|
||||
score+=1;
|
||||
kod_genetyczny[pozycjaTraktoraY - 1][pozycjaTraktoraX] = "000000000";
|
||||
|
||||
correctMovement('N');
|
||||
pole[pozycjaTraktoraY][pozycjaTraktoraX][0] = '.';
|
||||
}
|
||||
|
||||
else {
|
||||
correctMovement('N');
|
||||
pole[pozycjaTraktoraY][pozycjaTraktoraX][0] = 'B';
|
||||
kod_genetyczny[pozycjaTraktoraY][pozycjaTraktoraX] = przypiszKod();
|
||||
}
|
||||
|
||||
pozycjaTraktoraY--;
|
||||
pole[pozycjaTraktoraY][pozycjaTraktoraX][0] = 'T';
|
||||
}
|
||||
@ -213,8 +522,20 @@ void Move(char kierunek)
|
||||
{
|
||||
if (pole[pozycjaTraktoraY + 1][pozycjaTraktoraX][0] != '#')
|
||||
{
|
||||
correctMovement('S');
|
||||
if (pole[pozycjaTraktoraY +1][pozycjaTraktoraX][0] == 'B') {
|
||||
zebrane[score] = kod_genetyczny[pozycjaTraktoraY + 1][pozycjaTraktoraX];
|
||||
score+=1;
|
||||
kod_genetyczny[pozycjaTraktoraY + 1][pozycjaTraktoraX] = "000000000";
|
||||
correctMovement('N');
|
||||
pole[pozycjaTraktoraY][pozycjaTraktoraX][0] = '.';
|
||||
}
|
||||
|
||||
else {
|
||||
correctMovement('N');
|
||||
pole[pozycjaTraktoraY][pozycjaTraktoraX][0] = 'B';
|
||||
kod_genetyczny[pozycjaTraktoraY][pozycjaTraktoraX] = przypiszKod();
|
||||
}
|
||||
|
||||
pozycjaTraktoraY++;
|
||||
pole[pozycjaTraktoraY][pozycjaTraktoraX][0] = 'T';
|
||||
}
|
||||
@ -225,8 +546,20 @@ void Move(char kierunek)
|
||||
{
|
||||
if (pole[pozycjaTraktoraY][pozycjaTraktoraX - 1][0] != '#')
|
||||
{
|
||||
correctMovement('W');
|
||||
if (pole[pozycjaTraktoraY][pozycjaTraktoraX - 1][0] == 'B') {
|
||||
zebrane[score] = kod_genetyczny[pozycjaTraktoraY][pozycjaTraktoraX - 1];
|
||||
score+=1;
|
||||
kod_genetyczny[pozycjaTraktoraY][pozycjaTraktoraX - 1] = "000000000";
|
||||
correctMovement('N');
|
||||
pole[pozycjaTraktoraY][pozycjaTraktoraX][0] = '.';
|
||||
}
|
||||
|
||||
else {
|
||||
correctMovement('N');
|
||||
pole[pozycjaTraktoraY][pozycjaTraktoraX][0] = 'B';
|
||||
kod_genetyczny[pozycjaTraktoraY][pozycjaTraktoraX] = przypiszKod();
|
||||
}
|
||||
|
||||
pozycjaTraktoraX--;
|
||||
pole[pozycjaTraktoraY][pozycjaTraktoraX][0] = 'T';
|
||||
}
|
||||
@ -237,8 +570,20 @@ void Move(char kierunek)
|
||||
{
|
||||
if (pole[pozycjaTraktoraY][pozycjaTraktoraX + 1][0] != '#')
|
||||
{
|
||||
correctMovement('E');
|
||||
if (pole[pozycjaTraktoraY][pozycjaTraktoraX + 1][0] == 'B') {
|
||||
zebrane[score] = kod_genetyczny[pozycjaTraktoraY][pozycjaTraktoraX + 1];
|
||||
score+=1;
|
||||
kod_genetyczny[pozycjaTraktoraY ][pozycjaTraktoraX + 1] = "000000000";
|
||||
correctMovement('N');
|
||||
pole[pozycjaTraktoraY][pozycjaTraktoraX][0] = '.';
|
||||
}
|
||||
|
||||
else {
|
||||
correctMovement('N');
|
||||
pole[pozycjaTraktoraY][pozycjaTraktoraX][0] = 'B';
|
||||
kod_genetyczny[pozycjaTraktoraY][pozycjaTraktoraX] = przypiszKod();
|
||||
}
|
||||
|
||||
pozycjaTraktoraX++;
|
||||
pole[pozycjaTraktoraY][pozycjaTraktoraX][0] = 'T';
|
||||
}
|
||||
@ -516,6 +861,14 @@ void test2()
|
||||
}
|
||||
test1();
|
||||
updatePola();
|
||||
//generowanie kodów dla buraków
|
||||
for(int i=0;i<27;i++) {
|
||||
for(int j=0;j<27;j++) {
|
||||
if (pole[i][j][0] == 'B') {
|
||||
kod_genetyczny[i][j] = przypiszKod();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void start1()
|
||||
@ -549,8 +902,13 @@ void start3()
|
||||
gogo(goalX, goalY);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
srand(time(0));
|
||||
|
||||
SetWindow(50, 30);
|
||||
//create pola//
|
||||
for (int i = 0; i < 27; i++)
|
||||
@ -581,6 +939,8 @@ int main()
|
||||
|
||||
updatePola();
|
||||
|
||||
//UWAGA - generowanie kodow dla burakow jest w test2!
|
||||
|
||||
start3(); // testy start 1-3
|
||||
|
||||
//---------start---------//
|
||||
@ -599,6 +959,22 @@ int main()
|
||||
{
|
||||
traktorDziala = false;
|
||||
}
|
||||
|
||||
cout << "Zebrane buraki: " << score << endl;
|
||||
if(score>=rozmiarPopulacji) {
|
||||
score = 0;
|
||||
delete[] doSadzenia;
|
||||
string * doSadzenia = new string[20];
|
||||
for(int i = 0;i<20;i++) {
|
||||
doSadzenia[i] = "000000000";
|
||||
}
|
||||
genetic_algorithm(zebrane, rozmiarPopulacji, rozmiarPopulacji - 5, doSadzenia, 20);
|
||||
delete[] zebrane;
|
||||
string * zebrane = new string[rozmiarPopulacji];
|
||||
for(int i=0;i<20;i++) {
|
||||
cout << doSadzenia[i] << endl;
|
||||
}
|
||||
}
|
||||
} while (traktorDziala);
|
||||
//---------end---------//
|
||||
|
||||
|
138
gmo.cpp
138
gmo.cpp
@ -88,7 +88,7 @@ bool comparePair(const pair<int, string>&i, const pair<int, string>&j)
|
||||
}
|
||||
|
||||
|
||||
void selection(string * population,string * parents, int populationSize, int parentsNumber) {
|
||||
void ranking(string * population,string * parents, int populationSize, int parentsNumber) {
|
||||
|
||||
int i;
|
||||
pair <int,string> fitnessTable[populationSize];
|
||||
@ -98,17 +98,63 @@ void selection(string * population,string * parents, int populationSize, int par
|
||||
|
||||
sort(fitnessTable,fitnessTable+populationSize,comparePair);
|
||||
|
||||
cout << "fitnessTable:" << endl;
|
||||
for(i=0;i<populationSize;i++) {
|
||||
cout << fitnessTable[i].first << " " << fitnessTable[i].second << endl;
|
||||
}
|
||||
|
||||
for(i=0;i<parentsNumber;i++) {
|
||||
parents[i] = fitnessTable[i].second;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool exists(int len, int * array, int element) {
|
||||
|
||||
int i;
|
||||
for(i=0;i<len;i++) {
|
||||
if (array[i] == element) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void selection(string * population,string * parents, int populationSize, int parentsNumber) {
|
||||
|
||||
int i,j,k;
|
||||
pair <int,string> fitnessTable[populationSize];
|
||||
for(i=0;i<populationSize;i++) {
|
||||
fitnessTable[i] = make_pair(fitness(population[i]),population[i]);
|
||||
}
|
||||
|
||||
sort(fitnessTable,fitnessTable+populationSize,comparePair);
|
||||
|
||||
int roulette;
|
||||
int taken[parentsNumber];
|
||||
int sum = 0;
|
||||
for(i=0;i<parentsNumber;i++) {
|
||||
for(j = populationSize - 1;j>=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<populationSize) {
|
||||
if(not exists(parentsNumber,taken,j)) {
|
||||
roulette -= fitnessTable[j].first;
|
||||
}
|
||||
j+=1;
|
||||
}
|
||||
parents[i] = fitnessTable[j].second;
|
||||
taken[i] = j;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
int newton(int n,int k) {
|
||||
|
||||
if (k==0 or n==k) return 1;
|
||||
@ -131,6 +177,8 @@ string mutate(string child) {
|
||||
child = child.substr(0,6) + mutation;
|
||||
break;
|
||||
}
|
||||
|
||||
return child;
|
||||
}
|
||||
|
||||
|
||||
@ -141,9 +189,25 @@ string cross(string parent[2]) {
|
||||
for(i=0;i<3;i++) {
|
||||
child += parent[rand() % 2].substr(i*3,3);
|
||||
}
|
||||
if (child == parent[0] or child == parent[1]) {
|
||||
string other;
|
||||
if (child == parent[0]) other = parent[1];
|
||||
else other = parent[0];
|
||||
int d3 = rand() % 3;
|
||||
switch(d3) {
|
||||
case 0:
|
||||
child = other.substr((rand() % 3)*3,3) + child.substr(3,6);
|
||||
break;
|
||||
case 1:
|
||||
child = child.substr(0,3) + other.substr((rand() % 3)*3,3) + child.substr(6,3);
|
||||
break;
|
||||
case 2:
|
||||
child = child.substr(0,6) + other.substr((rand() % 3)*3,3);
|
||||
break;
|
||||
}
|
||||
}
|
||||
int d1000 = rand() % 1000;
|
||||
if (d1000 == 0) {
|
||||
cout << "MUTACJA!";
|
||||
if (rand() % 100 == 0) {
|
||||
child = mutate(child);
|
||||
}
|
||||
return child;
|
||||
@ -163,7 +227,7 @@ void crossover(string * parents,string * nextGen,int parentsNumber,int nextGenSi
|
||||
counter +=1;
|
||||
}
|
||||
}
|
||||
|
||||
while(counter < nextGenSize) {
|
||||
for(i=0;i<parentsNumber;i++) {
|
||||
if (counter >= nextGenSize) {
|
||||
break;
|
||||
@ -183,50 +247,46 @@ void crossover(string * parents,string * nextGen,int parentsNumber,int nextGenSi
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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<populationSize;i++) {
|
||||
population[i] = nextGen[i];
|
||||
}
|
||||
delete[] nextGen;
|
||||
}
|
||||
ranking(population,outcome,populationSize,outcomeSize);
|
||||
}
|
||||
int main() {
|
||||
|
||||
|
||||
srand(time(0));
|
||||
|
||||
int i;
|
||||
int populationSize = 50;
|
||||
int parentsNumber = 5;
|
||||
int maxPopulationSize = 1000;
|
||||
string population[populationSize];
|
||||
int nextGenSize;
|
||||
int populationSize = 500;
|
||||
int parentsNumber = populationSize - 5;
|
||||
string * population = new string[populationSize];
|
||||
|
||||
generatePopulation(population,populationSize);
|
||||
|
||||
cout << "Wstepna populacja:" << endl;
|
||||
for(i=0;i<populationSize;i++) {
|
||||
cout << population[i] << endl;
|
||||
}
|
||||
|
||||
string parents[parentsNumber];
|
||||
selection(population,parents,populationSize,parentsNumber);
|
||||
|
||||
cout << "Wybrane do rozrodu:" << endl;
|
||||
for(i=0;i<parentsNumber;i++) {
|
||||
cout << parents[i] << endl;
|
||||
}
|
||||
|
||||
int ffa = newton(parentsNumber,2);
|
||||
if (ffa + parentsNumber <= maxPopulationSize) nextGenSize = ffa + parentsNumber;
|
||||
else nextGenSize = maxPopulationSize;
|
||||
string nextGen[nextGenSize];
|
||||
crossover(parents,nextGen,parentsNumber,nextGenSize);
|
||||
|
||||
cout << "Nowe pokolenie:" << endl;
|
||||
for(i=0;i<nextGenSize;i++) {
|
||||
cout << nextGen[i] << endl;
|
||||
}
|
||||
|
||||
|
||||
string vegetablesForPlanting[20];
|
||||
genetic_algorithm(population, populationSize, parentsNumber,vegetablesForPlanting, 20);
|
||||
|
||||
cout << atoi("000000000");
|
||||
|
||||
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user