Maximizing the volume of a box¶
This example is adapted from Boyd, Kim, Vandenberghe, and Hassibi, “A Tutorial on Geometric Programming“.
In this example, we maximize the shape of a box with height \(h\), width \(w\), and depth \(w\), with limits on the wall area \(2(hw + hd)\) and the floor area \(wd\), subject to bounds on the aspect ratios \(h/w\) and \(w/d\). The optimization problem is
import cvxpy as cp # Problem data. A_wall = 100 A_flr = 10 alpha = 0.5 beta = 2 gamma = 0.5 delta = 2 h = cp.Variable(pos=True, name="h") w = cp.Variable(pos=True, name="w") d = cp.Variable(pos=True, name="d") volume = h * w * d wall_area = 2 * (h * w + h * d) flr_area = w * d hw_ratio = h/w dw_ratio = d/w constraints = [ wall_area <= A_wall, flr_area <= A_flr, hw_ratio >= alpha, hw_ratio <= beta, dw_ratio >= gamma, dw_ratio <= delta ] problem = cp.Problem(cp.Maximize(volume), constraints) print(problem)
maximize h * w * d subject to 2.0 * (h * w + h * d) <= 100.0 w * d <= 10.0 0.5 <= h / w h / w <= 2.0 0.5 <= d / w d / w <= 2.0
assert not problem.is_dcp() assert problem.is_dgp() problem.solve(gp=True) problem.value
# A 1% increase in allowed wall space should yield approximately # a 0.83% increase in maximum value. constraints.dual_value
# A 1% increase in allowed wall space should yield approximately # a 0.66% increase in maximum value. constraints.dual_value