-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
rank.c
104 lines (101 loc) · 2.63 KB
/
rank.c
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
/* Rank assignment routine */
# include <stdio.h>
# include <stdlib.h>
# include <math.h>
# include "nsga2.h"
# include "rand.h"
/* Function to assign rank and crowding distance to a population of size pop_size*/
void assign_rank_and_crowding_distance (NSGA2Type *nsga2Params, population *new_pop)
{
int flag;
int i;
int end;
int front_size;
int rank=1;
list *orig;
list *cur;
list *temp1, *temp2;
orig = (list *)malloc(sizeof(list));
cur = (list *)malloc(sizeof(list));
front_size = 0;
orig->index = -1;
orig->parent = NULL;
orig->child = NULL;
cur->index = -1;
cur->parent = NULL;
cur->child = NULL;
temp1 = orig;
for (i=0; i<nsga2Params->popsize; i++)
{
insert (temp1,i);
temp1 = temp1->child;
}
do
{
if (orig->child->child == NULL)
{
new_pop->ind[orig->child->index].rank = rank;
new_pop->ind[orig->child->index].crowd_dist = INF;
break;
}
temp1 = orig->child;
insert (cur, temp1->index);
front_size = 1;
temp2 = cur->child;
temp1 = del (temp1);
temp1 = temp1->child;
do
{
temp2 = cur->child;
do
{
end = 0;
flag = check_dominance (nsga2Params, &(new_pop->ind[temp1->index]), &(new_pop->ind[temp2->index]));
if (flag == 1)
{
insert (orig, temp2->index);
temp2 = del (temp2);
front_size--;
temp2 = temp2->child;
}
if (flag == 0)
{
temp2 = temp2->child;
}
if (flag == -1)
{
end = 1;
}
}
while (end!=1 && temp2!=NULL);
if (flag == 0 || flag == 1)
{
insert (cur, temp1->index);
front_size++;
temp1 = del (temp1);
}
temp1 = temp1->child;
}
while (temp1 != NULL);
temp2 = cur->child;
do
{
new_pop->ind[temp2->index].rank = rank;
temp2 = temp2->child;
}
while (temp2 != NULL);
assign_crowding_distance_list (nsga2Params, new_pop, cur->child, front_size);
temp2 = cur->child;
do
{
temp2 = del (temp2);
temp2 = temp2->child;
}
while (cur->child !=NULL);
rank+=1;
}
while (orig->child!=NULL);
free (orig);
free (cur);
return;
}