Box volume maximization

% Boyd, Kim, Vandenberghe, and Hassibi, "A Tutorial on Geometric Programming"
% Written for CVX by Almir Mutapcic 02/08/06
% (a figure is generated)
%
% Maximizes volume of a box-shaped structure which has constraints
% on its total wall area, its total floor area, and which has lower
% and upper bounds on the aspect ratios. This leads to a GP:
%
%   maximize   h*w*d
%       s.t.   2(h*w + h*d) <= Awall, w*d <= Afloor
%              alpha <= h/w <= beta
%              gamma <= d/w <= delta
%
% where variables are the box height h, width w, and depth d.

% set the quiet flag (no solver reporting)
cvxq = cvx_quiet(true);

% problem constants
alpha = 0.5; beta = 2; gamma = 0.5; delta = 2;

% varying parameters for an optimal trade-off curve
N = 10;
Afloor = logspace(1,3,N);
Awall  = [100 1000 10000];
opt_volumes = zeros(length(Awall),N);

disp('Computing optimal box volume for:')

% setup various GP problems with varying parameters
for k = 1:length(Awall)
  for n = 1:N
    % resolve the problem with varying parameters
    cvx_begin gp
      variables h w d
      % objective function is the box volume
      maximize( h*w*d )
      subject to
        2*(h*w + h*d) <= Awall(k);
        w*d <= Afloor(n);

        h/w >= alpha;
        h/w <= beta;
        d/w >= gamma;
        d/w <= delta;
    cvx_end

    fprintf(1,'  Awall = %5d   Afloor = %7.2f   max_volume = %3.2f\n', ...
            Awall(k),Afloor(n),cvx_optval);
    opt_volumes(k,n) = cvx_optval;
  end
end

% restore initial solver reporting state
cvx_quiet(cvxq);

% plot the tradeoff curve
figure, clf
loglog(Afloor,opt_volumes(1,:), Afloor,opt_volumes(2,:), Afloor,opt_volumes(3,:));
xlabel('Afloor'); ylabel('V');
Computing optimal box volume for:
  Awall =   100   Afloor =   10.00   max_volume = 77.46
  Awall =   100   Afloor =   16.68   max_volume = 102.04
  Awall =   100   Afloor =   27.83   max_volume = 131.79
  Awall =   100   Afloor =   46.42   max_volume = 170.21
  Awall =   100   Afloor =   77.43   max_volume = 192.34
  Awall =   100   Afloor =  129.15   max_volume = 192.34
  Awall =   100   Afloor =  215.44   max_volume = 192.34
  Awall =   100   Afloor =  359.38   max_volume = 192.34
  Awall =   100   Afloor =  599.48   max_volume = 192.34
  Awall =   100   Afloor = 1000.00   max_volume = 192.34
  Awall =  1000   Afloor =   10.00   max_volume = 89.44
  Awall =  1000   Afloor =   16.68   max_volume = 192.70
  Awall =  1000   Afloor =   27.83   max_volume = 415.16
  Awall =  1000   Afloor =   46.42   max_volume = 894.43
  Awall =  1000   Afloor =   77.43   max_volume = 1926.98
  Awall =  1000   Afloor =  129.15   max_volume = 2839.27
  Awall =  1000   Afloor =  215.44   max_volume = 3667.06
  Awall =  1000   Afloor =  359.38   max_volume = 4736.19
  Awall =  1000   Afloor =  599.48   max_volume = 5998.44
  Awall =  1000   Afloor = 1000.00   max_volume = 6082.35
  Awall = 10000   Afloor =   10.00   max_volume = 89.44
  Awall = 10000   Afloor =   16.68   max_volume = 192.70
  Awall = 10000   Afloor =   27.83   max_volume = 415.16
  Awall = 10000   Afloor =   46.42   max_volume = 894.43
  Awall = 10000   Afloor =   77.43   max_volume = 1926.98
  Awall = 10000   Afloor =  129.15   max_volume = 4151.56
  Awall = 10000   Afloor =  215.44   max_volume = 8944.27
  Awall = 10000   Afloor =  359.38   max_volume = 19269.85
  Awall = 10000   Afloor =  599.48   max_volume = 41515.63
  Awall = 10000   Afloor = 1000.00   max_volume = 77457.25