Problem Description
This problem is from
Linear Programming Problems and Solutions
.
Please read the information
on the web page before proceeding.
A store wants to liquidate 200 shirts and 100 pairs of pants from last season.
They have decided to put together two offers, A and B.
- Offer A is a package of one shirt and a pair of pants which will
sell for 30.
- Offer B is a package of three shirts and a pair of pants, which will
sell for 50.
- The store wants to sell at least 20 packages of Offer A
and at least 10 of Offer B.
How many offers of A and B
do they have to sell with to maximize the money generated
from the promotion?
Problem #0
Install the Python PuLp library. Use a virtual environment for the project?
pip install pulp
or
python -m pip install pulp
Problem #1
This code uses the Python PuLp library to solves the problem in the
"Problem Description".
First, test the code to verify it works.
Second, create an interactive program that allow the user to modify
the input parameters and calculate different solutions.
(set some reasonable limits. No zero or negative values.)
- number shirts to sell
- number pairs of pants to sell
- number of shirts in offer B
- sale price of each offer
#!/usr/bin/python3
# ====================================================================
# Store sale problem using PuLp
# --------------------------------------------------------------------
# problem description
#
# ---- x = number of A packages sold
# ---- 1 shirt
# ---- 1 pair of pants
# ---- cost 30
# ---- sales >= 20
# ---- y = number of B packages sold
# ---- 3 shirt
# ---- 1 pair of pants
# ---- cost 50
# ---- sales >= 10
# ----
# ---- 200 shirts
# ---- 100 pairs of pants
#
# maximize sales profit
# --------------------------------------------------------------------
# To see information on Pulp classes go to
# https://www.coin-or.org/PuLP/pulp.html
# ====================================================================
import pulp as pl
# ---- define LP variables
x = pl.LpVariable('x',20,None,cat='integer')
y = pl.LpVariable('y',10,None,cat='integer')
# ---- define the problem
prob = pl.LpProblem('StoreSaleProblem', pl.LpMaximize)
# ---- add objective function
prob += 30*x + 50*y
# ---- add constraints
prob += x + y <= 100
prob += x +3*y <= 200
# ---- solve the problem
status = prob.solve()
print(f'status = {pl.LpStatus[status]}')
# ---- describe solution
x = pl.value(x)
y = pl.value(y)
print(f'{x} type A offers')
print(f'{y} type B offers')
print(f'max sales = {30*x + 50*y}')