# 6.6 Geometric Programming¶

*Geometric programs* (GP) are a particular class of optimization problems which can be expressed in special polynomial form as positive sums of generalized monomials. More precisely, a geometric problem in canonical form is

where each \(f_0,\ldots,f_m\) is a *posynomial*, that is a function of the form

with arbitrary real \(\alpha_{ki}\) and \(c_k>0\). The standard way to formulate GPs in convex form is to introduce a variable substitution

Under this substitution all constraints in a GP can be reduced to the form

involving a *log-sum-exp* bound. Moreover, constraints involving only a single monomial in \(x\) can be even more simply written as a linear inequality:

We refer to the **MOSEK** Modeling Cookbook and to [BKVH07] for more details on this reformulation. A geometric problem formulated in convex form can be entered into **MOSEK** with the help of exponential cones.

## 6.6.1 Example GP1¶

The following problem comes from [BKVH07]. Consider maximizing the volume of a \(h\times w\times d\) box subject to upper bounds on the area of the floor and of the walls and bounds on the ratios \(h/w\) and \(d/w\):

The decision variables in the problem are \(h,w,d\). We make a substitution

after which (6.19) becomes

Next, we demonstrate how to implement a log-sum-exp constraint (6.18). It can be written as:

This presentation requires one extra variable \(u_k\) for each monomial appearing in the original posynomial constraint. In this case the affine conic constraints (ACC, see Sec. 6.2 (From Linear to Conic Optimization)) take the form:

As a matter of demonstration we will also add the constraint

as an affine conic constraint. It means that to define the all the ACCs we need to produce the following affine expressions (AFE) and store them:

We implement it by adding all the affine expressions (AFE) and then picking the ones required for each ACC:

```
# Affine expressions appearing in affine conic constraints
# in this order:
# u1, u2, x+y+log(2/Awall), x+z+log(2/Awall), 1.0, u1+u2-1.0
numafe = 6
u1, u2 = 3, 4 # Indices of slack variables
afeidx = [0, 1, 2, 2, 3, 3, 5, 5]
varidx = [u1, u2, x, y, x, z, u1, u2]
fval = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
gfull = [0, 0, log(2/Aw), log(2/Aw), 1.0, -1.0]
# New variables u1, u2
task.appendvars(2)
task.putvarboundsliceconst(u1, u2+1, boundkey.fr, -inf, inf)
# Append affine expressions
task.appendafes(numafe)
task.putafefentrylist(afeidx, varidx, fval)
task.putafegslice(0, numafe, gfull)
# Two affine conic constraints
expdom = task.appendprimalexpconedomain()
# (u1, 1, x+y+log(2/Awall)) \in EXP
task.appendacc(expdom, [0, 4, 2], None)
# (u2, 1, x+z+log(2/Awall)) \in EXP
task.appendacc(expdom, [1, 4, 3], None)
# The constraint u1+u2-1 \in \ZERO is added also as an ACC
task.appendacc(task.appendrzerodomain(1), [5], None)
```

We can now use this function to assemble all constraints in the model. The linear part of the problem is entered as in Sec. 6.1 (Linear Optimization).

```
def max_volume_box(Aw, Af, alpha, beta, gamma, delta):
# Basic dimensions of our problem
numvar = 3 # Variables in original problem
x, y, z = 0, 1, 2 # Indices of variables
numcon = 3 # Linear constraints in original problem
# Linear part of the problem
cval = [1, 1, 1]
asubi = [0, 0, 1, 1, 2, 2]
asubj = [y, z, x, y, z, y]
aval = [1.0, 1.0, 1.0, -1.0, 1.0, -1.0]
bkc = [boundkey.up, boundkey.ra, boundkey.ra]
blc = [-inf, log(alpha), log(gamma)]
buc = [log(Af), log(beta), log(delta)]
with Task() as task:
task.set_Stream(streamtype.log, streamprinter)
# Add variables and constraints
task.appendvars(numvar)
task.appendcons(numcon)
# Objective is the sum of three first variables
task.putobjsense(objsense.maximize)
task.putcslice(0, numvar, cval)
task.putvarboundsliceconst(0, numvar, boundkey.fr, -inf, inf)
# Add the three linear constraints
task.putaijlist(asubi, asubj, aval)
task.putconboundslice(0, numvar, bkc, blc, buc)
# Affine expressions appearing in affine conic constraints
# in this order:
# u1, u2, x+y+log(2/Awall), x+z+log(2/Awall), 1.0, u1+u2-1.0
numafe = 6
u1, u2 = 3, 4 # Indices of slack variables
afeidx = [0, 1, 2, 2, 3, 3, 5, 5]
varidx = [u1, u2, x, y, x, z, u1, u2]
fval = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
gfull = [0, 0, log(2/Aw), log(2/Aw), 1.0, -1.0]
# New variables u1, u2
task.appendvars(2)
task.putvarboundsliceconst(u1, u2+1, boundkey.fr, -inf, inf)
# Append affine expressions
task.appendafes(numafe)
task.putafefentrylist(afeidx, varidx, fval)
task.putafegslice(0, numafe, gfull)
# Two affine conic constraints
expdom = task.appendprimalexpconedomain()
# (u1, 1, x+y+log(2/Awall)) \in EXP
task.appendacc(expdom, [0, 4, 2], None)
# (u2, 1, x+z+log(2/Awall)) \in EXP
task.appendacc(expdom, [1, 4, 3], None)
# The constraint u1+u2-1 \in \ZERO is added also as an ACC
task.appendacc(task.appendrzerodomain(1), [5], None)
# Solve and map to original h, w, d
task.optimize()
task.writedata("gp1.ptf");
xyz = task.getxxslice(soltype.itr, 0, numvar)
return exp(xyz)
```

Given sample data we obtain the solution \(h,w,d\) as follows:

```
Aw, Af, alpha, beta, gamma, delta = 200.0, 50.0, 2.0, 10.0, 2.0, 10.0
h,w,d = max_volume_box(Aw, Af, alpha, beta, gamma, delta)
print("h={0:.3f}, w={1:.3f}, d={2:.3f}".format(h, w, d))
```