Linear Programming Project #2

Problem Description

This problem is from Linear Programming Problems and Solutions . Please read the information on the web page before proceeding.

A school is preparing a trip for 400 students.

Calculate how many buses of each type that minimizes the cost of the trip.

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 # ==================================================================== # Bus Capacity Problem using PuPl #--------------------------------------------------------------------- # problem description # # ---- x = number of small buses # ---- number of buses is 8 # ---- bus capacity is 40 # ---- cost per bus 600 # ---- y = number of large buses # ---- number of buses is 10 # ---- bus capacity is 50 # ---- cost per bus 800 # ---- # ---- number of students 400 # ---- number of drivers 9 # # minimize bus rental cost # -------------------------------------------------------------------- # 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',0,8,cat='integer') y = pl.LpVariable('y',0,10,cat='integer') # ---- define LP problem prob = pl.LpProblem('BusCapacityProblem', pl.LpMinimize) # ---- add objective function prob += 600*x + 800*y # ---- add constraints prob += 40*x + 50*y >= 400 prob += x + y <= 9 # ---- 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} small buses') print(f'{y} large buses') print(f'total cost = {600*x + 800*y}')