0
点赞
收藏
分享

微信扫一扫

多目标遗传算法 ------ NSGA-II (部分源码解析) 目标函数值计算 eval.c

这部分比较简单,具体的函数数值计算是需要调用设定的目标函数的,此部分一个不能忽略的问题是  超出限制条件的处理 , 故对此加以解释。

首先是包装函数, 核心操作调用  evaluate_ind  实现。

1 /* Routine for evaluating population members  */
2
3 # include <stdio.h>
4 # include <stdlib.h>
5 # include <math.h>
6
7 # include "global.h"
8 # include "rand.h"
9
10 /* Routine to evaluate objective function values and constraints for a population */
11 void evaluate_pop (population *pop)
12 {
13 int i;
14 for (i=0; i<popsize; i++)
15 {
16 evaluate_ind (&(pop->ind[i]));
17 }
18 return;
19 }


1 /* Routine to evaluate objective function values and constraints for an individual */
2 void evaluate_ind (individual *ind)
3 {
4 int j;
5 test_problem (ind->xreal, ind->xbin, ind->gene, ind->obj, ind->constr);
6 if (ncon==0)
7 {
8 ind->constr_violation = 0.0;
9 }
10 else
11 {
12 ind->constr_violation = 0.0;
13 for (j=0; j<ncon; j++)
14 {
15 if (ind->constr[j]<0.0)
16 {
17 ind->constr_violation += ind->constr[j];
18 }
19 }
20 }
21 return;
22 }

6行 到 9行,根据标识位判断是否需要进行  超限  处理。

13行  到  19行, 对个体的所有限制条件遍历, 如果  某限制条件 constr[j]>=0 ,  证明该个体在该条件上没有超限。

17行, 将  个体  所有超出限制条件的数值相加(所有小于0的 条件数值  constr[j]<0),  其和便是该个体的超限的非法数值 constr_violation ,

有此可知   constr_violation  小于0  说明该个体有超出限制条件的情况,  等于0  说明没有超出限制,   不存在大于0的情况


举报

相关推荐

0 条评论