Professional Documents
Culture Documents
Forums Topic 88211 Genetic Algorithm Program
Forums Topic 88211 Genetic Algorithm Program
net/forums/topic/88211-genetic-algorithm-program/
1 of 2
12/11/2011 12:26 PM
http://www.dreamincode.net/forums/topic/88211-genetic-algorithm-program/
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 } 73 }
for(i=0;i<population;i++) { //to not reproduct with itself //it would be a waste of time //(although this if could introduce a break in the pipeline, well.. forget about this) if(i!=best) { for(j=0;j<7;j++) { //either the gene will be kept the same or it will be changed //to be what the best chromosome has if(rand()%2) chromosome[i][j]=chromosome[best][j]; else chromosome[i][j]=chromosome[i][j];
} }
return 0;
74 int fitness(bool* chromosome) 75 { 76 77 78 79 80 81 } // the ingredients are: // 0 1 2 3 4 5 6 salt sugar lemon egg water onion apple
2 of 2
12/11/2011 12:26 PM