# LP Final, problem 2

## 2372 days ago by haynef

Set "p" to be the LP to be solved.  "maximization=False" is setting the LP to be a minimization problem.

p = MixedIntegerLinearProgram(maximization=False)

x1p correlates to $x1^+$ and x1n to $x1^-$.

The same is true for x2, y1, y2

v = p.new_variable(real=True, nonnegative=True) x,y,x1p,x1n,y1p,y1n,x2p,x2n,y2p,y2n,x3p,x3n,y3p,y3n = v['x'],v['y'],v['x1p'],v['x1n'],v['y1p'],v['y1n'],v['x2p'],v['x2n'],v['y2p'],v['y2n'],v['x3p'],v['x3n'],v['y3p'],v['y3n']

Setting the objective function to be minimized.

p.set_objective((x1p+x1n) + (y1p+y1n) + (x2p+x2n)+(y2p+y2n) + (x3p+x3n)+(y3p+y3n))

Adding all of the constraints

x1p - x1n = x-10

x2p - x2n = x-5

x3p - x3n = x-20

y1p - y1n = y-3

y2p - y2n = y-15

y3p - y3n = y-25

Solve for the optimal objective value.

Optimal objective value: 37

This means that there will be 37 units of wire.

p.solve()
 37.0 37.0

Get the x and y values for the optimal objective value.

p.get_values(x)
 10.0 10.0
p.get_values(y)
 15.0 15.0

The optimal solution is (10,15). Meaning the central unit should be placed at position (10,15).