码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2017-01-08 19:04:34      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:源码   解析   report   nes   math.h   files   ons   pop   repo   

 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的个体的   目标函数值, 限制条件值, 编码值  打印出来。

 

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

标签:源码   解析   report   nes   math.h   files   ons   pop   repo   

原文地址:http://www.cnblogs.com/devilmaycry812839668/p/6262461.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!