clc;


p = input(' Dwse bathmo poluonumou (5,10,15):') ; 
er = zeros(18,1);
fbest = zeros(18,1);
rng default


i=1;
j=1;
k=1;
w=0;


fun = @ (x) antwnhsmar(x,p);


for i=1:3
    
    for j=1:2
        
        for k=1:3
            if i==1
            population=50;
            end
            if i==2
            population=100;
            end
            if i==3
            population=200;
            end
                if j == 1 && k == 1
                    options = gaoptimset('CreationFcn',@gacreationlinearfeasible,'MutationFcn',@mutationadaptfeasible,'StallGenLimit',2000,'Generations',2500,'TolFun',10e-08,'PlotFcn',@gaplotbestf,'SelectionFcn',@selectionroulette,'CrossoverFcn',@crossoverscattered,'PopulationSize',population);
                    w = w+1;
                end
                    if j == 1 && k == 2
                        options = gaoptimset('CreationFcn',@gacreationlinearfeasible,'MutationFcn',@mutationadaptfeasible,'StallGenLimit',2000,'Generations',2500,'TolFun',10e-08,'PlotFcn',@gaplotbestf,'SelectionFcn',@selectionroulette,'CrossoverFcn',@crossoversinglepoint,'PopulationSize',population);
                        w=w+1;
                    end
                        if j == 1 && k==3
                            options = gaoptimset('CreationFcn',@gacreationlinearfeasible,'MutationFcn',@mutationadaptfeasible,'StallGenLimit',2000,'Generations',2500,'TolFun',10e-08,'PlotFcn',@gaplotbestf,'SelectionFcn',@selectionroulette,'CrossoverFcn',@crossoverintermediate,'PopulationSize',population);
                            w=w+1;
                        end
                            if j == 2 && k == 1
                                options = gaoptimset('CreationFcn',@gacreationlinearfeasible,'MutationFcn',@mutationadaptfeasible,'StallGenLimit',2000,'Generations',2500,'TolFun',10e-08,'PlotFcn',@gaplotbestf,'SelectionFcn',@selectionuniform,'CrossoverFcn',@crossoverscattered,'PopulationSize',population);
                                w=w+1;
                            end
                                if j == 2 && k == 2
                                    options = gaoptimset('CreationFcn',@gacreationlinearfeasible,'MutationFcn',@mutationadaptfeasible,'StallGenLimit',2000,'Generations',2500,'TolFun',10e-08,'PlotFcn',@gaplotbestf,'SelectionFcn',@selectionuniform,'CrossoverFcn',@crossoversinglepoint,'PopulationSize',population);
                                    w=w+1;
                                end
                                    if j == 2 && k==3
                                        options = gaoptimset('CreationFcn',@gacreationlinearfeasible,'MutationFcn',@mutationadaptfeasible,'StallGenLimit',2000,'Generations',2500,'TolFun',10e-08,'PlotFcn',@gaplotbestf,'SelectionFcn',@selectionuniform,'CrossoverFcn',@crossoverintermediate,'PopulationSize',population);
                                        w=w+1;
                                    end

[x,fval,exitflag,output,population,scores]=ga(fun,p,[],[],[],[],-65.536,65.536,[],[],options);
set(gca, 'YScale', 'log');
savefig(sprintf('plot%d',w));
er(w) = norm(x,2);
fbest(w) = fval;

    if p==5
        xlswrite('results.xlsx',er,1,'G2');
        xlswrite('results.xlsx',fbest,1,'F2');
    end
        if p==10
            xlswrite('results.xlsx',er,1,'G20');
            xlswrite('results.xlsx',fbest,1,'F20');
        end
            if p==15
        xlswrite('results.xlsx',er,1,'G38');
        xlswrite('results.xlsx',fbest,1,'F38');
            end
            
            
disp(er(w));
disp(fbest(w));
        end
    end
end
                    
        
        