// simple test function
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


// DEB's test function
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     = 10;  // problem size 
Proba_cross = 0.5;  // crossover probability (default: 0.7)
Proba_mut   = 0.3;  // mutation probability (default: 0.1)
NbGen       = 50;   // number of generations
Log         = %T;   // printing infprmation during the run (daca e %T)
//nb_disp     = 10;   
//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)); // lower bound
ga_params = add_param(ga_params,'maxbound',ones(2,1));  // upper bound

[pop_opt, fobj_pop_opt, pop_init, fobj_pop_init] = optim_nsga2(deb_1, 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*") // plot the approximated Pareto front
