// functie test simpla
function f=ftest1(x)
    y1=x(1)*x(1);
    y2=(x(1)-1)*(x(1)-1);
    f(1,1)=y1;
    f(1,2)=y2;
endfunction


// functie test de tip DEB
function f=deb_1(x)
   f1_x1 = x(1);
   g_x2  = 1 + 9 * 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;  // dimensiunea populatiei 
Proba_cross = 0.5;  // probabilitate de incrucisare (implicit: 0.7)
Proba_mut   = 0.3;  // probabilitate de mutatie (implicit: 0.1)
NbGen       = 10;   // numar de generatii
//NbCouples   = 110;  // numar de perechi selectate pentru incrucisare
Log         = %T;   // afisare la fiecare generatie (daca e %T)
//nb_disp     = 10;   // numar de puncte selectate din populatia optimala
//pressure    = 0.1;  // presiune de selectie

ga_params = init_param();
ga_params = add_param(ga_params,'dimension',2);
ga_params = add_param(ga_params,'minbound',zeros(2,1)); // margine inferioara
ga_params = add_param(ga_params,'maxbound',ones(2,1));  // margine superioara

[pop_opt, fobj_pop_opt, pop_init, fobj_pop_init] = optim_nsga2(ftest1, PopSize,NbGen, Proba_mut, Proba_cross, Log, ga_params)
 
//[pop_opt, fobj_pop_opt, pop_init, fobj_pop_init] = optim_moga(ftest1, PopSize,NbGen, Proba_mut, Proba_cross, Log, ga_params) 
 
plot(fobj_pop_opt(:,1)',fobj_pop_opt(:,2)',"r*")
