1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
| #include <stdlib.h>
#include <stdio.h>
#include <assert.h>
double calcIndicatorValue(sac* p_ind_a, sac* p_ind_b, int indicator, double rhot, int nbfcts, range* bounds);
double calcHypervolume(sac *p_ind_a, sac *p_ind_b, int nbfcts)
/* calculates the hypervolume of that portion of the objective space that
is dominated by individual a but not by individual b */
{
double a, b, r, max;
double volume = 0;
r = rhot * (bounds[nbfcts - 1].max - bounds[nbfcts - 1].min);
max = bounds[nbfcts - 1].min + r;
assert(p_ind_a != NULL);
a = p_ind_a->profit[nbfcts - 1];
if (p_ind_b == NULL)
b = max;
else
b = p_ind_b->profit[nbfcts - 1];
assert(nbfcts > 0);
if (nbfcts == 1)
{
if (a < b)
volume = (b - a) / r;
else
volume = 0;
}
else
{
if (a < b)
{
volume = calcHypervolume(p_ind_a, NULL, nbfcts - 1) *
(b - a) / r;
volume += calcHypervolume(p_ind_a, p_ind_b, nbfcts - 1) *
(max - b) / r;
}
else
{
volume = calcHypervolume(p_ind_a, p_ind_b, nbfcts - 1) *
(max - b) / r;
}
}
return (volume);
}
double calcHypervolumeIndicator(sac *p_ind_a, sac *p_ind_b, int nbfcts){
if (dominates(p_ind_a, p_ind_b))
return -calcHypervolume(p_ind_a, p_ind_b, nbfcts);
else return calcHypervolume(p_ind_b, p_ind_a, nbfcts);
}
double calcAddEpsIndicator(sac *p_ind_a, sac *p_ind_b)
/* calculates the maximum epsilon value by which individual a must be
decreased in all objectives such that individual b is weakly dominated */
{
int i;
double r;
double eps = 0;
r = bounds[0].max - bounds[0].min;
eps = (p_ind_a->profit[0] - bounds[0].min) / r -
(p_ind_b->profit[0] - bounds[0].min) / r;
for (i = 1; i < nbfcts; i++)
{
double temp_eps;
r = bounds[i].max - bounds[i].min;
temp_eps = (p_ind_a->profit[i] - bounds[i].min) / r -
(p_ind_b->profit[i] - bounds[i].min) / r;
if (temp_eps > eps)
eps = temp_eps;
}
return (eps);
}
double calcBentleyIndicator(sac *a, sac *b){
/* 1 if a dominates b 0 otherwise
to be used with indicator_merge=0! */
int i;
float res=0.0;
for (i=0; i<nbfcts; i++)
if (a->profit[i]<b->profit[i]) res-=1.0;
else if (a->profit[i]==b->profit[i]) res-=0.5;
return res;
}
double calcFonsecaIndicator(sac *a, sac *b){
/* 1 if a dominates b 0 otherwise
to be used with indicator_merge=0! */
if (dominates(a,b)) return -1; else return 0;
}
double calcDebIndicator(sac *a, sac *b){
/* fit(a)+1 if a dominates b fit(b) otherwise
to be used with indicator_merge=2! */
if (dominates(a,b)) return a->fitness-1; else return max_value;
}
double calcZitzlerIndicator(sac *a, sac *b){
/* 1 if b dominates a 0 otherwise
to be used with indicator_merge=0! */
if (dominates(b,a)) return 0; else return -1;
}
double calclex1Indicator(sac *a, sac *b){
if ((a->profit[0]<b->profit[0]) || ((a->profit[0]==b->profit[0])&&(a->profit[1]<b->profit[1]))) return -1;
else return 0;
}
double calclex2Indicator(sac *a, sac *b){
if ((a->profit[1]<b->profit[1]) || ((a->profit[1]==b->profit[1])&&(a->profit[0]<b->profit[0]))) return -1;
else return 0;
}
double calcIndicatorValue(sac *p_ind_a, sac *p_ind_b, int indicator, float r, int d, range *b){
rho=r;
dim=d;
bounds=b;
if (indicator == 0) return calcAddEpsIndicator(p_ind_a,p_ind_b);
else if (indicator == 1) return calcHypervolumeIndicator(p_ind_a,p_ind_b,nbfcts);
else if (indicator == 2) return calcBentleyIndicator(p_ind_a,p_ind_b);
else if (indicator == 3) return calcFonsecaIndicator(p_ind_a,p_ind_b);
else if (indicator == 4) return calcDebIndicator(p_ind_a,p_ind_b);
else if (indicator == 5) return calcZitzlerIndicator(p_ind_a,p_ind_b);
else if (indicator == 6) return calclex1Indicator(p_ind_a,p_ind_b);
else if (indicator == 7) return calclex2Indicator(p_ind_a,p_ind_b);
else return 0;
} |
Partager