lb = [225 225 16 2 16 2 8 100 180];
ub = [700 1125 25 12 25 12 10 170 270];

% Guide for more details.
opts = gaoptimset(...
    'PopulationSize', 100, ...
    'Generations', 100, ...
    'EliteCount', 10, ...
    'TolFun', 1e-6);
    %'PlotFcns', @gaplotbestf);

%%
% for reproducibility.
rng(0, 'twister');
[xbest, fbest, exitflag] = ga(@beam13920Volume,9, [], [], [], [], ...
    lb, ub, @beam13920Constraints,[], opts);
    
% GA.
display(xbest);

 
fprintf('\nCost function returned by ga = %g\n', fbest);


lb = [1 1 1 1 1 1 1 1 1];
ub = [20 37 3 11 3 11 2 8 10];  %only write the numbers of limite (lb to ub)



rng(0, 'twister');
[xbestDisc, fbestDisc, exitflagDisc] = ga(@beam13920VolumeWithDisc, ...
    9, [], [], [], [], lb, ub, @beam13920ConstraintsWithDisc,1:9, opts);

% value in their engineering units.
xbestDisc = beam13920MapVariables(xbestDisc);
display(xbestDisc);


fprintf('\nCost function returned by ga = %g\n', fbestDisc);
