-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathessGoBeyond.c
64 lines (47 loc) · 1.55 KB
/
essGoBeyond.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
#include "ess.h"
void goBeyond(eSSType *eSSParams, int parent_index,
void *inp, void *out){
bool improved;
int gamma = 1;
int improvement = 1;
// parent = eSSParams->refSet->members[parent_index];
// child = eSSParams->childsSet->members[parent_index];
Individual parent;
Individual child;
allocate_Ind(eSSParams, &parent);
allocate_Ind(eSSParams, &child);
copy_Ind(eSSParams, &parent, &(eSSParams->refSet->members[parent_index]));
copy_Ind(eSSParams, &child, &(eSSParams->childsSet->members[parent_index]));
double c1, c2;
improved = false;
for(;;) {
for (int k = 0; k < eSSParams->n_params; ++k){
c1 = child.params[k] - (parent.params[k] - child.params[k]) / gamma;
c2 = child.params[k];
c1 = MAX(eSSParams->min_real_var[k], c1); c1 = MIN(eSSParams->max_real_var[k], c1);
c2 = MAX(eSSParams->min_real_var[k], c2); c2 = MIN(eSSParams->max_real_var[k], c2);
// Copying child to parent in time.
parent.params[k] = child.params[k];
child.params[k] = c1 + (c2 - c1) * rndreal(0, 1);
}
parent.cost = child.cost;
evaluate_Individual(eSSParams, &child, inp, out);
if ( child.cost < parent.cost )
{
// IMPROVE: Move the copy out of the for, so, there is only one
// copy needed.
copy_Ind(eSSParams, &(eSSParams->childsSet->members[parent_index]), &child);
improved = true;
improvement++;
if ( 2 == improvement ){
improvement = 0;
gamma /= 2;
}
eSSParams->stats->n_successful_goBeyond++;
}else{
break;
}
}
deallocate_Ind(eSSParams, &parent);
deallocate_Ind(eSSParams, &child);
}