wersja pod VS

This commit is contained in:
Tomasz Dzierzbicki 2020-06-08 21:19:05 +00:00
parent 3eaa94999a
commit 6f016b84a7

View File

@ -13,7 +13,7 @@
#include <stdio.h> #include <stdio.h>
#include <cstdlib> #include <cstdlib>
#include <ctime> #include <ctime>
#include<bits/stdc++.h> //#include<bits/stdc++.h>
#include <algorithm> #include <algorithm>
#include <utility> #include <utility>
@ -49,7 +49,11 @@ string kod_genetyczny[27][27];
string generateValue() { string generateValue() {
char trash[100]; char trash[100];
string x = itoa(rand() % 1000,trash,10); string x;
srand(time(NULL));
int random = (rand() % 1000, 1);
//string x = itoa(rand() % 1000,trash,10);
x = to_string(random);
if (x.size() == 2) { if (x.size() == 2) {
x = "0" + x; x = "0" + x;
} }
@ -128,7 +132,7 @@ bool comparePair(const pair<int, string>&i, const pair<int, string>&j)
void ranking(string * population,string * parents, int populationSize, int parentsNumber) { void ranking(string * population,string * parents, int populationSize, int parentsNumber) {
int i; int i;
pair <int,string> fitnessTable[populationSize]; pair <int,string> *fitnessTable=new pair <int, string>[populationSize];
for(i=0;i<populationSize;i++) { for(i=0;i<populationSize;i++) {
fitnessTable[i] = make_pair(fitness(population[i]),population[i]); fitnessTable[i] = make_pair(fitness(population[i]),population[i]);
} }
@ -138,6 +142,7 @@ void ranking(string * population,string * parents, int populationSize, int paren
for(i=0;i<parentsNumber;i++) { for(i=0;i<parentsNumber;i++) {
parents[i] = fitnessTable[i].second; parents[i] = fitnessTable[i].second;
} }
delete[] fitnessTable;
} }
@ -154,7 +159,7 @@ bool exists(int len, int * array, int element) {
void selection(string * population,string * parents, int populationSize, int parentsNumber) { void selection(string * population,string * parents, int populationSize, int parentsNumber) {
int i,j,k; int i,j,k;
pair <int,string> fitnessTable[populationSize]; pair <int,string> *fitnessTable= new pair <int, string>[populationSize];
for(i=0;i<populationSize;i++) { for(i=0;i<populationSize;i++) {
fitnessTable[i] = make_pair(fitness(population[i]),population[i]); fitnessTable[i] = make_pair(fitness(population[i]),population[i]);
} }
@ -162,7 +167,7 @@ void selection(string * population,string * parents, int populationSize, int par
sort(fitnessTable,fitnessTable+populationSize,comparePair); sort(fitnessTable,fitnessTable+populationSize,comparePair);
int roulette; int roulette;
int taken[parentsNumber]; int *taken=new int[parentsNumber];
int sum = 0; int sum = 0;
for(i=0;i<parentsNumber;i++) { for(i=0;i<parentsNumber;i++) {
for(j = populationSize - 1;j>=0;j--) { for(j = populationSize - 1;j>=0;j--) {