-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathessProblem.c
206 lines (174 loc) · 6.91 KB
/
essProblem.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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#include "ess.h"
// #include "benchmarks/Ackleys.h"
// #include "benchmarks/AluffiPentini.h" // Accurate!
// #include "benchmarks/BeckerLago.h" // Accurate!
// #include "benchmarks/Bohachevsky1.h" // Accurate!
// #include "benchmarks/Bohachevsky2.h" // Accurate!
// #include "benchmarks/Branin.h" // Accurate!
// #include "benchmarks/Camel3.h" // Accurate!
// #include "benchmarks/Camel6.h" // Accurate!
// #include "benchmarks/CosMix2.h" // Accurate!
// #include "benchmarks/CosMix4.h" // Accurate!
// #include "benchmarks/DekkersAarts.h" // Accurate!
// #include "benchmarks/Easom.h" // Accurate!
// #include "benchmarks/EMichalewicz.h" // Accurate!
// #include "benchmarks/Expo.h" // Accurate!
// #include "benchmarks/GoldPrice.h" // Accurate!
// #include "benchmarks/Hartman3.h" // Accurate!
#include "benchmarks/Hartman6.h" // Accurate!
// #include "benchmarks/Kowalik.h" // Accurate!
// #include "benchmarks/LM1.h" // Accurate!
// #include "benchmarks/LM2n5.h" // Accurate!
// #include "benchmarks/LM2n10.h" // Accurate!
// #include "benchmarks/MeyerRoth.h" // Accurate!
// #include "benchmarks/MieleCantrell.h" // Accurate!
// #include "benchmarks/ModRosenbrock.h" // Accurate!
// #include "benchmarks/MultiGauss.h" // Accurate!
// #include "benchmarks/Neumaier2.h" // Accurate!
// #include "benchmarks/Neumaier3.h" // Accurate!
// #include "benchmarks/Paviani.h" // Accurate!
// #include "benchmarks/Periodic.h" // Accurate!
// #include "benchmarks/PowellQ.h" // Accurate!
// #include "benchmarks/Schaffer1.h" // Accurate!
// #include "benchmarks/Schaffer2.h" // Accurate!
// #include "benchmarks/Schubert.h" // Accurate!
// #include "benchmarks/Shekel10.h" // Accurate!
// #include "benchmarks/Shekel5.h" // Accurate!
// #include "benchmarks/Shekel7.h" // Accurate! More iterations needed
// #include "benchmarks/Shekelfox10.h" // NOT Accurate!
// #include "benchmarks/Shekelfox5.h" // Accurate! More Iteration needed
// #include "benchmarks/Wood.h" // Accurate!
// #include "benchmarks/Zeldasine10.h" // Accurate!
// #include "benchmarks/Zeldasine20.h" // Accurate!
// #include "benchmarks/Gulf.h" // Accurate!
// #include "benchmarks/Rosenbrock.h" // Accurate!
// #include "benchmarks/Beale.h" // Accurate!
// #include "benchmarks/McCormic.h" // Accurate!
// #include "benchmarks/Hosaki.h" // Accurate!
// #include "benchmarks/Schwefel.h" // Accurate!
// #include "benchmarks/Griewank.h" // Accurate! // ...
// #include "benchmarks/Helical.h" // Accurate! // not many subsituation // There was a problem in function definition
// #include "benchmarks/PriceTransistor.h" // Not accurate enough!
// #include "benchmarks/Salomon.h" // Not accurate! // not many subsituation
// #include "benchmarks/STChebychev9.h" // Not Accurate! // ...
// #include "benchmarks/STChebychev17.h" // Not Accurate! // ...
// #include "benchmarks/Rastrigin.h" // Accurate! // I got it with performing warm start in a good solutions set
// #include "benchmarks/Modlangerman.h" // Not accurate! Stuck!
// #include "benchmarks/Oddsquare.h" // Not accurate! Stuck!
//
// #include "benchmarks/expb.h" // Accurate
/**
* Initialize the sample parameters for optimization
*/
void init_sampleParams(eSSType *eSSParams){
#ifdef TEST_PROBLEM
eSSParams->n_params = N;
eSSParams->sol = (double)SOL;
printf("%s", KCYN);
printf("\n---------------------------------");
printf("\n %s:", (const char*)TEST_PROBLEM);
printf("\n Analytic Solution: %lf \n", (double)SOL);
printf("---------------------------------\n\n");
printf("%s", KNRM);
#endif
/**
* User Options
*/
eSSParams->logBound = 0;
eSSParams->print_freqs = 500;
eSSParams->save_freqs = 1;
// eSSParams->perform_warm_start = 0;
eSSParams->perform_refSet_randomization = 1;
eSSParams->n_randomization_Freqs = 1;
eSSParams->goBeyond_freqs = 10;
eSSParams->n_archiveSet = 100;
eSSParams->refSet_std_tol = 1e-3;
eSSParams->equality_type = 1;
// eSSParams->init_with_user_guesses = 1;
/**
* Global Options
*/
if (eSSParams->max_iter == 0)
eSSParams->max_iter = 200;
eSSParams->max_stuck = 20;
eSSParams->perform_elite_preservation = 1;
eSSParams->max_preserve_elite = 3;
eSSParams->perform_flatzone_check = 0;
eSSParams->flatzone_coef = 0.0001;
eSSParams->min_real_var = (double *)malloc(eSSParams->n_params * sizeof(double));
eSSParams->max_real_var = (double *)malloc(eSSParams->n_params * sizeof(double));
for (int i = 0; i < eSSParams->n_params; ++i)
{
eSSParams->min_real_var[i] = 0;
eSSParams->max_real_var[i] = 0;
}
#ifdef TEST_PROBLEM
bounds(eSSParams->min_real_var, eSSParams->max_real_var);
#endif
eSSParams->n_refSet = ceil(1.0 + sqrt(1.0 + 40.0 * eSSParams->n_params) / 2.0);
if (eSSParams->n_refSet %2 != 0)
eSSParams->n_refSet++;
eSSParams->n_refSet = MAX(eSSParams->n_refSet, 20);
eSSParams->n_sub_regions = MIN(4, eSSParams->n_params);
eSSParams->n_scatterSet = MAX(10 * eSSParams->n_params, 40);
eSSParams->n_childsSet = eSSParams->n_refSet;
eSSParams->n_candidateSet = eSSParams->n_refSet -1 ;
eSSParams->max_delete = eSSParams->n_refSet / 4;
eSSParams->perform_cost_tol_stopping = 1;
eSSParams->cost_tol = 1e-3;
eSSParams->euclidean_dist_tol= 1e-3;
eSSParams->param_diff_tol = 5e-4;
/**
* Local Search Options
*/
// eSSParams->perform_local_search = 1;
if (eSSParams->local_SolverMethod == '0') eSSParams->local_SolverMethod = 'n';
// eSSParams->local_minCostCriteria = ((double)SOL + 1) ;
eSSParams->local_maxIter = 500;
eSSParams->local_tol = 1e-3;
eSSParams->local_N1 = 50;
eSSParams->local_N2 = 25;
eSSParams->local_atEnd = 1;
eSSParams->local_onBest_Only = 0;
// eSSParams->local_merit_Filter;
// eSSParams->local_distance_Filter;
// eSSParams->local_th_merit_Factor;
// eSSParams->local_max_distance_Factor;
// eSSParams->local_wait_maxDist_limit;
// eSSParams->local_wait_th_limit;
eSSParams->compute_Ind_Stats = 1;
eSSParams->compute_Set_Stats = 1;
}
/**
* This will call the problem simulator to the cost function for the Individual.
* The function should first copy ind->params to the inp->params and call the
* simulator like `simulator(inp, out)`, and finally write the `out` to `ind->cost`
*/
double objectiveFunction(eSSType *eSSParams, Individual *ind, void *inp, void *out){
double cost = 0;
double penalty = 0;
// #ifdef GSL_TESTFUNCTION
// #ifdef LEVMER
if (eSSParams->perform_local_search){
if (eSSParams->local_SolverMethod == 'l'){
gsl_vector *ff = gsl_vector_alloc(40);
gsl_vector_view x = gsl_vector_view_array(ind->params, 3);
levermed_objfn(&x.vector, inp, ff);
cost = gsl_blas_dnrm2(ff);
gsl_vector_free(ff);
return cost;
}
if (eSSParams->local_SolverMethod == 'n'){
// #elif defined NELDER
gsl_vector_view x = gsl_vector_view_array(ind->params, 3);
return nelder_objfn(&x.vector, inp);
}
}
else{
// return objfn(&x.vector, inp);
// #endif
// #else
cost = objfn(ind->params);
}
return (cost + penalty);
}