多目标遗传算法 ------ NSGA-II (部分源码解析)状态报告 打印 report.c

 /* Routines for storing population data into files */

 # include <stdio.h>
# include <stdlib.h>
# include <math.h> # include "global.h"
# include "rand.h" /* Function to print the information of a population in a file */
void report_pop (population *pop, FILE *fpt)
{
int i, j, k;
for (i=; i<popsize; i++)
{
for (j=; j<nobj; j++)
{
fprintf(fpt,"%e\t",pop->ind[i].obj[j]);
}
if (ncon!=)
{
for (j=; j<ncon; j++)
{
fprintf(fpt,"%e\t",pop->ind[i].constr[j]);
}
}
if (nreal!=)
{
for (j=; j<nreal; j++)
{
fprintf(fpt,"%e\t",pop->ind[i].xreal[j]);
}
}
if (nbin!=)
{
for (j=; j<nbin; j++)
{
for (k=; k<nbits[j]; k++)
{
fprintf(fpt,"%d\t",pop->ind[i].gene[j][k]);
}
}
}
fprintf(fpt,"%e\t",pop->ind[i].constr_violation);
fprintf(fpt,"%d\t",pop->ind[i].rank);
fprintf(fpt,"%e\n",pop->ind[i].crowd_dist);
}
return;
} /* Function to print the information of feasible and non-dominated population in a file */
void report_feasible (population *pop, FILE *fpt)
{
int i, j, k;
for (i=; i<popsize; i++)
{
if (pop->ind[i].constr_violation == 0.0 && pop->ind[i].rank==)
{
for (j=; j<nobj; j++)
{
fprintf(fpt,"%e\t",pop->ind[i].obj[j]);
}
if (ncon!=)
{
for (j=; j<ncon; j++)
{
fprintf(fpt,"%e\t",pop->ind[i].constr[j]);
}
}
if (nreal!=)
{
for (j=; j<nreal; j++)
{
fprintf(fpt,"%e\t",pop->ind[i].xreal[j]);
}
}
if (nbin!=)
{
for (j=; j<nbin; j++)
{
for (k=; k<nbits[j]; k++)
{
fprintf(fpt,"%d\t",pop->ind[i].gene[j][k]);
}
}
}
fprintf(fpt,"%e\t",pop->ind[i].constr_violation);
fprintf(fpt,"%d\t",pop->ind[i].rank);
fprintf(fpt,"%e\n",pop->ind[i].crowd_dist);
}
}
return;
}

report_pop   将种群中所有个体的   目标函数值, 限制条件值, 编码值  打印出来。

report_pop   种群中的非支配个体并且限制条件总和为0   (constr_violation == 0.0的个体的   目标函数值, 限制条件值, 编码值  打印出来。

上一篇:Java 问题定位工具 -- jps


下一篇:perl 初始化Hash