Introduction to Optimization in Python
Jasmin Ludolf
Content Developer
$$\max 2\sqrt q$$
$$s.t. \ \ \ \ q\leq 16 $$
milp
expects a linear objectivemodel = LpProblem('Artist', LpMaximize)
q = LpVariable('q', lowBound=0, upBound=16)
model += 2 * q**(1/2)
--> 3 model += 2 * q**(1/2)
TypeError: unsupported operand type(s) for ** or pow(): 'LpVariable' and 'float'
model = LpProblem('Artist', LpMaximize) z = LpVariable('z', lowBound=0, upBound=4, cat='Integer') model += 2 * z
model.solve() print(f"Solution is {LpStatus[model.status]}.") print(f"The optimal number of paintings is {round(z.varValue**2)}.")
Solution is Optimal.
The optimal number of paintings is 16.
Problem statement
Modeling
$\max\ \ o_AV_A + o_Ao_BV_B + o_CV_C$
$s.t.\ \ \ \ o_AI_A + o_Ao_BI_B + o_CI_C\leq 4600$
$$\max\ \ o_AV_A + o_{AB}V_B + o_CV_C$$
$$s.t.\ \ \ \ o_AI_A + o_{AB}I_B + o_CI_C\leq 4600$$
$$ o_{A} + o_{B} -1 \leq o_{AB}\leq o_{A}, o_{B}$$
Introduction to Optimization in Python