#!/usr/bin/python3 # ==================================================================== # Store sale problem # ---- 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 profit # -------------------------------------------------------------------- # Problem From : www.superprof.co.uk/resources/academic/maths/ # linear-algebra/linear-programming/ # linear-programming-problems-and-solutions.html # ==================================================================== import pulp as pl # ---- define variables x = pl.LpVariable('x',20,None,cat='integer') y = pl.LpVariable('y',10,None,cat='integer') # ---- define project prob = pl.LpProblem('TransportationCompanyProblem', pl.LpMaximize) # ---- add objective function (maximum money generated) prob += 30*x + 50*y # ---- add constraints prob += x + y <= 100 prob += x +3*y <= 200 # ---- solve problem (using default solver) status = prob.solve() print(f'status = {pl.LpStatus[status]}') # ---- describe solution x = pl.value(x) y = pl.value(y) print('solution from web site:') print(' offer A = 50') print(' offer B = 50') print(' max sales = 4000') print(f'{x} type A offers') print(f'{y} type B offers') print(f'max sales = {30*x + 50*y}')