00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "reactionNetwork.h"
00021
00022
00023
00024 void init()
00025 {
00026 setNetworkTypeProbability(0,0);
00027 setNetworkTypeProbability(1,0);
00028 setNetworkTypeProbability(2,1);
00029 setNetworkTypeProbability(3,0);
00030 setDistributionOfMassActionNetwork(0.2,0.2,0.2,0.2,0.2,0.2);
00031 setRateConstantForMassActionNetwork(0.01,100);
00032 setMutationRatesForMassActionNetwork(0.5,0.25,0.25);
00033 setRateConstantsForProteinInteractionNetwork(0.001,100,0.1,100,0.1,100);
00034 setMutationRatesForProteinInteractionNetwork(0.2,0.4,0.2,0.2);
00035 setRateConstantsForEnzymeNetwork(0.001,100,-4,4,-4,4,1,4,0.001,20,0.001,20);
00036 setMutationRatesForEnzymeNetwork(0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1);
00037 setResourceRestriction(0,0);
00038 setRateConstantsForGeneRegulationNetwork(1,4,0.001,100,0.1,20,0.1,10);
00039 setMutationRatesForGeneRegulationNetwork(0.2,0.2,0.2,0.2,0.2);
00040 setNetworkSize(3,6,2,10);
00041 setCrossoverRate(0.5);
00042 setAverageInitialValue(1.0);
00043 setMutationRateOfInitialValues(0.05);
00044 configureContinuousLog(1,0,1,0,0,1);
00045 configureFinalLog(1,1,1,0,1,1,1);
00046 enableLogFile("evolution.log");
00047 GAlineageTrackingON();
00048 }
00049
00050
00051 double fitness(GAindividual p);
00052
00053 #define INITIAL_POPULATION_SIZE 1000
00054 #define SUCCESSIVE_POPULATION_SIZE 200
00055 #define NUM_GENERATIONS 80
00056
00057 int callback(int iter,int popSz, GApopulation P, double * fitnessArray, int *** parents)
00058 {
00059 return (fitnessArray[0] > 0.45);
00060 }
00061
00062
00063 int main()
00064 {
00065 int N;
00066 double * y;
00067 GApopulation pop;
00068 GAindividual * best;
00069
00070 init();
00071
00072 printf ("Oscillator Evolution\n\n");
00073 pop = evolveNetworks(INITIAL_POPULATION_SIZE, SUCCESSIVE_POPULATION_SIZE, NUM_GENERATIONS, &fitness, &callback);
00074
00075 best = pop[0];
00076
00077
00078
00079 N = getNumSpecies(best);
00080
00081 y = simulateNetworkODE(best, 500, 1);
00082
00083 writeToFile("dat.txt",y,500,N+1);
00084
00085 free(y);
00086
00087
00088 GAfree(pop);
00089
00090 printf("Press a key to exit\n");
00091 getchar();
00092
00093 return 0;
00094 }
00095
00096
00097 double fitness(GAindividual net)
00098 {
00099 int i, N, n;
00100 double x, * y, time, f, mXY = 0,mX = 0, mY = 0, mX2 = 0, mY2 = 0, dx = 0.01;
00101
00102 N = getNumSpecies(net);
00103
00104 time = 500.0;
00105
00106 y = simulateNetworkODE(net,time,1);
00107
00108 f = 0;
00109 if (y != 0)
00110 {
00111 n = 0;
00112 mXY = mX = mY = mX2 = mY2 = 0;
00113 for (i = 0; i < (time); ++i)
00114 {
00115 x = sin((double)i/4.0) > 0;
00116 mX += getValue(y,N+1,i,1);
00117 mY += x;
00118 mXY += x * getValue(y,N+1,i,1);
00119 mX2 += getValue(y,N+1,i,1)*getValue(y,N+1,i,1);
00120 mY2 += x*x;
00121 ++n;
00122 }
00123
00124 mX /= (double)(n);
00125 mY /= (double)(n);
00126 mXY /= (double)(n);
00127 mX2 /= (double)(n);
00128 mY2 /= (double)(n);
00129
00130 if (((mX2 - mX*mX)) < 0.0001)
00131 {
00132 f = 0.0;
00133 }
00134 else
00135 {
00136 f = ( (mXY - mX*mY)/(sqrt(mX2 - mX*mX)*sqrt(mY2 - mY*mY)) );
00137 if (f < 0) f = -f;
00138 }
00139 free(y);
00140 }
00141
00142 return (f);
00143 }