遗传算法求Y=X*X最大值,求指导.
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/23 16:34:34
遗传算法求Y=X*X最大值,求指导.
遗传算法求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");
}
问得太广了,1编程语言是什么?2自变量的取值范围?3你对遗传算法的基本步骤不懂还是希望改进其中的某一步还是你有算法参数但是还是不懂?
当然,这个问题的结果显然是31的时候961,但是由于算法本身进化的原因和参数的该函数在[0,31]上是严格增函数,最大值显然是:当x=31时 y=31^31 .
遗传算法一般是默认求最小,你可以考虑把问题转换为minY=-X^2