#include #include "ga.h" TerminatingCondition() { extern unsigned long Generation; return (Generation >= 10000); } double fitness(ch) gene *ch; { double x = ch->x / 32767. * M_PI*2, y = ch->y / 32767.* M_PI*2; return cos(x+y) * exp(-(x*x+y*y)); } gene *random_gene() { static gene ch; ch.x = (short)(lrand48() & 0xffff); ch.y = (short)(lrand48() & 0xffff); return &ch; } print_gene(ch) gene *ch; { printf("(%d,%d)\n",ch->x,ch->y); }