#pragma warning(disable:4786) // disable debug warning #include // for cout etc. #include // for vector class #include // for string class #include // for sort algorithm #include // for random seed #include // for abs() #define GA_POPSIZE 2048 // ga population size #define GA_MAXITER 16384 // maximum iterations #define GA_ELITRATE 0.10f // elitism rate #define GA_MUTATIONRATE 0.25f // mutation rate #define GA_MUTATION RAND_MAX * GA_MUTATIONRATE #define GA_TARGET std::string("Hello world!") using namespace std; // polluting global namespace, but hey... struct ga_struct { string str; // the string unsigned int fitness; // its fitness }; typedef vector ga_vector;// for brevity void init_population(ga_vector &population, ga_vector &buffer ) { int tsize = GA_TARGET.size(); for (int i=0; i