/* C Programming, Final Project */
#include <stdio.h>
#include <stdlib.h>
#include "adv_fval.h"
#define POP 50
#define GENNO 4
int main(void)
{
double parent[GENNO],parentFit,offspring[POP][GENNO],oFit[POP];
int gen,i,j;
for (i=0;i<GENNO;i++)
parent[i] = initPetPar2();
parentFit = IQEval2(parent[0], parent[1], parent[2], parent[3]);
for (gen=1;gen<300;gen++) {
for (i=0;i<POP;i++) {
for (j=0;j<GENNO;j++)
offspring[i][j] = parent[j] + (double)rand()/RAND_MAX*10-5.0;
oFit[i] = IQEval2(offspring[i][0], offspring[i][1], offspring[i][2], offspring[i][3]);
}
for (i=0;i<POP;i++) {
if (oFit[i]>parentFit) {
for (j=0;j<GENNO;j++) {
parent[j] = offspring[i][j];
}
parentFit = oFit[i];
}
}
printf("%10.4f %10.4f %10.4f %10.4f, parentFit=%10.4f\n", parent[0], parent[1], parent[2], parent[3], parentFit);
}
system("pause");
return 0;
}
期末作業題目
回到首頁
沒有留言:
張貼留言