作业帮 > 英语 > 作业

遗传算法求Y=X*X最大值,求指导.

来源:学生作业帮 编辑:搜搜考试网作业帮 分类:英语作业 时间:2024/06/04 19:18:56
遗传算法求Y=X*X最大值,求指导.
遗传算法求Y=X*X最大值,求指导.
/* This is a simple genetic algorithm implementation where the\x05\x05 */
/* evaluation function takes positive values only and the\x05\x05 */
/* fitness of an individual is the same as the value of the\x05\x05 */
/* objective function\x05\x05\x05\x05\x05\x05\x05 */
//
void main(void)
{
\x05int\x05i;
\x05if ((galog = fopen("galog.txt","w"))==NULL)
\x05{
\x05\x05exit(1);
\x05}
\x05generation = 0;
\x05fprintf(galog,"\n generation best average standard \n");
\x05fprintf(galog," number value fitness deviation \n");
\x05initialize();
\x05evaluate();
\x05keep_the_best();
\x05while (generation < MAXGENS)
\x05{
\x05\x05generation++;
\x05\x05select();
\x05\x05crossover();
\x05\x05mutate();
\x05\x05evaluate();
\x05\x05report();
\x05\x05//evaluate();
\x05\x05elitist();
\x05}
\x05fprintf(galog,"\n\n Simulation completed\n");
\x05fprintf(galog,"\n Best member:\n");
\x05for (i = 0; i < NVARS; i++)
\x05{
\x05\x05fprintf (galog,"\n var(%d) = %3.6f",i,population[POPSIZE].gene[i]);
\x05}
\x05fprintf(galog,"\n\n Best fitness = %3.6f",population[POPSIZE].fitness);
\x05fclose(galog);
\x05printf("Success\n");
}