-- Bug description --
The optim_moga, optim_nsga and optim_nsga2 functions do not take into account for the additionnal arguments in the cost function.
The help page says that f can be a list(f,p1,p2,...,pn), which is wrong. The bug fix is easy:
replace
if ~isdef('ga_f','local') then
error(gettext("optim_moga: ga_f is mandatory"));
end
with
if ~isdef('ga_f','local') then
error(sprintf(gettext("%s: ga_f is mandatory"),"optim_moga"));
else
if typeof(ga_f)=='list' then
deff('y=_ga_f(x)','y=ga_f(1)(x, ga_f(2:$))');
else
deff('y=_ga_f(x)','y=ga_f(x)');
end
end
The unit test should be updated, which is longer, as they are currently rather incomplete.
-- Scilab error message --
optim_moga: Initialization of the population
!--error 21
Invalid index.
at line 52 of function optim_moga called by :
, NbGen, Proba_mut, Proba_cross, Log, ga_params)
-- How to reproduce the bug --
function f = deb_2(x,p1,p2)
f1_x1 = x(1);
g_x2 = p1 + p2 * sum((x(2:$)-x(1)).^2) / (length(x) - 1);
h = 1 - sqrt(f1_x1 / g_x2);
f(1,1) = f1_x1;
f(1,2) = g_x2 * h;
endfunction
PopSize = 100;
Proba_cross = 0.5;
Proba_mut = 0.3;
NbGen = 4;
NbCouples = 110;
Log = %T;
nb_disp = 10; // Nb point to display from the optimal population
pressure = 0.1;
ga_params = init_param();
ga_params = add_param(ga_params,'dimension',2);
ga_params = add_param(ga_params,'minbound',zeros(2,1));
ga_params = add_param(ga_params,'maxbound',ones(2,1));
[pop_opt, fobj_pop_opt, pop_init, fobj_pop_init] = optim_moga(list(deb_2,1,9), PopSize, NbGen, Proba_mut, Proba_cross, Log, ga_params);