資源簡介
WFG多目標(biāo)測試函數(shù)測試集,用于測試多目標(biāo)性能,
代碼片段和文件信息
#include?“wfg.h“
static?void?trimLine(char?line[])
{
int?i?=?0;
while(line[i]?!=?‘\0‘)
{
if?(line[i]?==?‘\r‘?||?line[i]?==?‘\n‘)
{
line[i]?=?‘\0‘;
break;
}
i++;
}
}
void?printContents(FILECONTENTS?*f)
{
for?(int?i?=?0;?i?nFronts;?i++)
{
printf(“Front?%d:\n“?i+1);
for?(int?j?=?0;?j?fronts[i].nPoints;?j++)
{
printf(“\t“);
for?(int?k?=?0;?k?fronts[i].n;?k++)
{
printf(“%f?“?f->fronts[i].points[j].objectives[k]);
}
printf(“\n“);
}
printf(“\n“);
}
}
FILECONTENTS?*readFile(char?filename[])
{
FILE?*fp;
char?line[BUFSIZ];
int?front?=?0?point?=?0?objective?=?0;
FILECONTENTS?*fc?=?malloc(sizeof(FILECONTENTS));
fc->nFronts?=?0;
fc->fronts?=?NULL;
fp?=?fopen(filename?“r“);
if?(fp?==?NULL)
{
fprintf(stderr?“File?%s?could?not?be?opened\n“?filename);
exit(EXIT_FAILURE);
}
while(fgets(line?sizeof?line?fp)?!=?NULL)
{
trimLine(line);
if?(strcmp(line?“#“)?==?0)
{
front?=?fc->nFronts;
fc->nFronts++;
fc->fronts?=?realloc(fc->fronts?sizeof(FRONT)?*?fc->nFronts);
fc->fronts[front].nPoints?=?0;
fc->fronts[front].points?=?NULL;
}
else
{
FRONT?*f?=?&fc->fronts[front];
point?=?f->nPoints;
f->nPoints++;
f->points?=?realloc(f->points?sizeof(POINT)?*?f->nPoints);
f->n?=?0;
f->points[point].objectives?=?NULL;
char?*tok?=?strtok(line?“?\t\n“);
do
{
POINT?*p?=?&f->points[point];
objective?=?f->n;
f->n++;
p->objectives?=?realloc(p->objectives?sizeof(objectIVE)?*?f->n);
p->objectives[objective]?=?atof(tok);
}?while?((tok?=?strtok(NULL?“?\t\n“))?!=?NULL);
}
}
fc->nFronts--;
//?for?(int?i?=?0;?i?nFronts;?i++)?fc->fronts[i].n?=?fc->fronts[i].points[0].nobjectives;
????????fclose(fp);
/*?printf(“Read?%d?fronts\n“?fc->nFronts);
???printContents(fc);?*/
return?fc;
}
- 上一篇:Snake主動輪廓模型
- 下一篇:攻擊圖技術(shù)應(yīng)用研究綜述
評論
共有 條評論