solution_140e.py

#!/usr/bin/python3
# ====================================================================
# from: https://www.youtube.com/watch?v=Y7e7DCsDUMY
#       Linear Programming (Optimization) 2 Examples Minimize
#       & Maximize (YouTube)
# ====================================================================

import pulp as pl

x = pl.LpVariable('x',cat='integer')

y = pl.LpVariable('y',cat='integer')

prob = pl.LpProblem('LPProblem',pl.LpMinimize)

# ---- objective function

prob += 2*x + 3*y

# ---- constraints

prob += x >= 0

prob += y >= 0

prob += 3*x + 6*y >= 24

prob += y >= -3*x + 9

# ---- solve problem

status = prob.solve()

print(f'status = {pl.LpStatus[status]}')

# ---- describe solution

x = pl.value(x)
y = pl.value(y)

print(f'x = {x}')
print(f'y = {y}')
print(f'z = {2*x + 3*y}')