Linear Programming Project #3

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.

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 pupl or python -m pip install pupl

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.)

#!/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}')