#include #include #include "board2.h" using namespace std; class GA{ private: int population[POP_SIZE][NUM_FEATURES]; public: GA(); int fitness(int &pop_id, int &gen); void create_child(int child[NUM_FEATURES], int parent1[NUM_FEATURES], int parent2[NUM_FEATURES]); void evolve(); }; //GA constructor GA::GA(){ for(int i=0; i= (NUM_FEATURES/2)){ for(int i=0; i<=split; i++) child[i] = parent1[i]; for(int i=split+1; i400) child[i] = 400; if(child[i]<1) child[i] = 1; } } //Run the evolutionary process void GA::evolve(){ string file = "outfile.txt"; ofstream outfile (file.c_str()); if(!outfile){ cout << "\nThere was an error in creating an output file." << endl; exit(0); } int average[NUM_FEATURES] = {0}; int best[NUM_FEATURES] = {0}; //For a number of generations for(int gen=0; genbest_gen_fitness){ best_gen_fitness = pop_fitness[i]; for(int j=0; j= spoke){ num_children[i]++; correctness_checker++; spoke += increment; } i++; } if(correctness_checker!=POP_SIZE){ if(correctness_checker>POP_SIZE){ while(correctness_checker>POP_SIZE){ int x = rand()%POP_SIZE; while(num_children[x]==0) x = rand()%POP_SIZE; num_children[x]--; correctness_checker--; } } else{ cout << "\nThere was an error in the roulette wheel section! aborting" << endl; exit(0); } } //Create a child population int child_pop[POP_SIZE][NUM_FEATURES]; for(int child_i=0; child_i