1 /* Domination checking routines */
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 for usual non-domination checking
11 It will return the following values
12 1 if a dominates b
13 -1 if b dominates a
14 0 if both a and b are non-dominated */
15
16 int check_dominance (individual *a, individual *b)
17 {
18 int i;
19 int flag1;
20 int flag2;
21 flag1 = 0;
22 flag2 = 0;
23 if (a->constr_violation<0 && b->constr_violation<0)
24 {
25 if (a->constr_violation > b->constr_violation)
26 {
27 return (1);
28 }
29 else
30 {
31 if (a->constr_violation < b->constr_violation)
32 {
33 return (-1);
34 }
35 else
36 {
37 return (0);
38 }
39 }
40 }
41 else
42 {
43 if (a->constr_violation < 0 && b->constr_violation == 0)
44 {
45 return (-1);
46 }
47 else
48 {
49 if (a->constr_violation == 0 && b->constr_violation <0)
50 {
51 return (1);
52 }
53 else
54 {
55 for (i=0; i<nobj; i++)
56 {
57 if (a->obj[i] < b->obj[i])
58 {
59 flag1 = 1;
60
61 }
62 else
63 {
64 if (a->obj[i] > b->obj[i])
65 {
66 flag2 = 1;
67 }
68 }
69 }
70 if (flag1==1 && flag2==0)
71 {
72 return (1);
73 }
74 else
75 {
76 if (flag1==0 && flag2==1)
77 {
78 return (-1);
79 }
80 else
81 {
82 return (0);
83 }
84 }
85 }
86 }
87 }
88 }
以上代码是判断两个个体的支配关系的。
基本遵循两个原则,首先是判断两个个体是是否超出限制条件,即判断 constr_violation 的大小。
如果个体 没有超过限制条件 则个体的 constr_violation >= 0,constr_violation 默认值 为 0 。
然后判断两个个体之间的支配关系。
以上代码含义基本为,首先判断两个个体是否 超出限制,即constr_violation<0 , 如果一个个体超出限制,另一个没有超出则直接选择 未超出限制的个体。
如果两个个体都超出限制了则选出 超出限制较小 的个体, 即 constr_violation 较大个体。
如果两个个体都超出限制了 而 constr_violation 相等, 则判断两个个体 支配关系为 互不支配。
如果两个个体 均没有超出限制, 则判断两个个体的支配关系。这里的具体操作是对两个个体的各个目标函数值进行大小判断,
如果 a 个体的目标函数有小于 b 个体的, flag1==1 。如果 b 个体的目标函数有小于 a 个体的, flag2==1 。
如果 flag1==1 flag2==0, 则 a 支配 b 。
如果 flag1==0 flag2==1, 则 b 支配 a 。
如果 flag1==1 flag2==1, 则 a b 互不支配 。