00001 double** XORtable()
00002 {
00003 int i,j;
00004
00005 double XOR[][3] =
00006 {
00007 { 0.1, 0.1, 0.0 },
00008 { 0.1, 10.0, 10.0 },
00009 { 10.0, 0.1, 10.0 },
00010 { 10.0, 10.0, 0.0 },
00011 };
00012
00013 double ** table = (double**)malloc( 4 * sizeof(double*) );
00014
00015 for (i=0; i < 4; ++i)
00016 {
00017 table[i] = (double*)malloc( 3 * sizeof(double) );
00018 for (j=0; j < 3; ++j)
00019 table[i][j] = XOR[i][j];
00020 }
00021
00022 return table;
00023 }
00024
00025
00026
00027
00028
00029 double fitness(GAindividual p)
00030 {
00031 int i, num_rows, num_inputs, num_outputs;
00032 double score;
00033
00034 double ** table = XORtable();
00035
00036 num_rows = 4;
00037 num_inputs = 2;
00038 num_outputs = 1;
00039
00040 score = compareSteadyStates(p, table, num_rows, num_inputs, num_outputs, 1, 0);
00041
00042
00043 for (i=0; i < 4; ++i)
00044 {
00045 free(table[i]);
00046 }
00047
00048 free(table);
00049
00050 return score;
00051 }
00052
00053
00054 int callback(int iter,int popSz,GApopulation pop,double * fitnessArray, int *** parents)
00055 {
00056 double f = fitnessArray[0];
00057
00058 if (f > 0.9)
00059 {
00060 fitness(pop[0]);
00061 return 1;
00062 }
00063 return (int)(f > 0.9);
00064 }
00065