lb = [225 225 16 2 16 2 8 180];
ub = [700 1125 25 14 25 6 10 300];

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

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

%%
% We can also ask |ga| to return the optimal volume of the beam. 
fprintf('\nCost function returned by ga = %g\n', fbest);
lb = [1 1 1 1 1 1 1 1];
ub = [20 37 3 14 3 5 2 7];  %only write the numbers of limite (lb to ub)


% vector |1:6| to |ga| to define the integer variables.
rng(0, 'twister');
[xbestDisc, fbestDisc, exitflagDisc] = ga(@beamVolumeWithDisc, ...
    8, [], [], [], [], lb, ub, @beamConstraintsWithDisc,1:8, opts);

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


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