0
点赞
收藏
分享

微信扫一扫

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

1 /* Routines for storing population data into files */
2
3 # include <stdio.h>
4 # include <stdlib.h>
5 # include <math.h>
6
7 # include "global.h"
8 # include "rand.h"
9
10 /* Function to print the information of a population in a file */
11 void report_pop (population *pop, FILE *fpt)
12 {
13 int i, j, k;
14 for (i=0; i<popsize; i++)
15 {
16 for (j=0; j<nobj; j++)
17 {
18 fprintf(fpt,"%e\t",pop->ind[i].obj[j]);
19 }
20 if (ncon!=0)
21 {
22 for (j=0; j<ncon; j++)
23 {
24 fprintf(fpt,"%e\t",pop->ind[i].constr[j]);
25 }
26 }
27 if (nreal!=0)
28 {
29 for (j=0; j<nreal; j++)
30 {
31 fprintf(fpt,"%e\t",pop->ind[i].xreal[j]);
32 }
33 }
34 if (nbin!=0)
35 {
36 for (j=0; j<nbin; j++)
37 {
38 for (k=0; k<nbits[j]; k++)
39 {
40 fprintf(fpt,"%d\t",pop->ind[i].gene[j][k]);
41 }
42 }
43 }
44 fprintf(fpt,"%e\t",pop->ind[i].constr_violation);
45 fprintf(fpt,"%d\t",pop->ind[i].rank);
46 fprintf(fpt,"%e\n",pop->ind[i].crowd_dist);
47 }
48 return;
49 }
50
51 /* Function to print the information of feasible and non-dominated population in a file */
52 void report_feasible (population *pop, FILE *fpt)
53 {
54 int i, j, k;
55 for (i=0; i<popsize; i++)
56 {
57 if (pop->ind[i].constr_violation == 0.0 && pop->ind[i].rank==1)
58 {
59 for (j=0; j<nobj; j++)
60 {
61 fprintf(fpt,"%e\t",pop->ind[i].obj[j]);
62 }
63 if (ncon!=0)
64 {
65 for (j=0; j<ncon; j++)
66 {
67 fprintf(fpt,"%e\t",pop->ind[i].constr[j]);
68 }
69 }
70 if (nreal!=0)
71 {
72 for (j=0; j<nreal; j++)
73 {
74 fprintf(fpt,"%e\t",pop->ind[i].xreal[j]);
75 }
76 }
77 if (nbin!=0)
78 {
79 for (j=0; j<nbin; j++)
80 {
81 for (k=0; k<nbits[j]; k++)
82 {
83 fprintf(fpt,"%d\t",pop->ind[i].gene[j][k]);
84 }
85 }
86 }
87 fprintf(fpt,"%e\t",pop->ind[i].constr_violation);
88 fprintf(fpt,"%d\t",pop->ind[i].rank);
89 fprintf(fpt,"%e\n",pop->ind[i].crowd_dist);
90 }
91 }
92 return;
93 }


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

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


举报

相关推荐

0 条评论