/* ga.c */ /* this program will answer to question, "What is the sum of the numbers from 1 to 1000?" through a genetic algorithm. The algorithm pairs up numbers form 1 to 1000. Rather than compute the midpoint via a simple calculation it takes a random number as a starting point and then mutates the random number and uses a fitness function to select between the mutant and the original number to give the current best midpoint estimate. The process is repeated with increasing refinement. Twice the sum of the midpoints then becomes the some we are seeking. Snapshots of the algorithms progress are given along the way. */ #include #include void main () { #define generations 5000 #define max_num 1000 double search_more_fit_midpoint( int environ_limits_1, int environ_limits_2, double current_most_fit_mid_point); double current_most_fit_mid_point[max_num/2]; int i=0; int j=0; int k=0; double total = 0.0; /* initialize the midpoints */ for (k=0; k