2a.modeling Linear and Integer Programs
2a.modeling Linear and Integer Programs
Spring 2021
Modeling Linear and Integer Programs
IE 311 2
Recall: Types of Linear Optimization Models
IE 311 3
A First Example: Farmer LP
• A farmer must determine how many acres of corn and wheat to plant.
• An acre of corn yields 10 bushels of corn and requires 4 hours of
labor per week.
• An acre of wheat yields 25 bushels of wheat and requires 10 hours of
labor per week.
• All corn can be sold at $3 a bushel and all wheat can be sold at $4 a
bushel.
• Seven acres of land and 40 hours per week of labor are available.
• Government regulations require that at least 30 bushels of corn be
produced.
• How can the farmer maximize the total revenue?
IE 311 4
• A farmer must determine how many acres of corn and wheat to plant.
• An acre of corn yields 10 bushels of corn and requires 4 hours of labor per week.
• An acre of wheat yields 25 bushels of wheat and requires 10 hours of labor per week.
IE 311 5
• A farmer must determine how many acres of corn and wheat to plant.
• An acre of corn yields 10 bushels of corn and requires 4 hours of labor per week.
• An acre of wheat yields 25 bushels of wheat and requires 10 hours of labor per week.
IE 311 6
• A farmer must determine how many acres of corn and wheat to plant.
• An acre of corn yields 10 bushels of corn and requires 4 hours of labor per week.
• An acre of wheat yields 25 bushels of wheat and requires 10 hours of labor per week.
• Labor availability
• Government regulations
• Nonnegativity
IE 311 7
Assumptions in Linear Programming
IE 311 8
Farmer LP: Simplest (but Dirty) s.t.
Python-Gurobi Implementation
from gurobipy import GRB,Model
m = Model('Farmer')
m.addConstr(4*corn + 10*wheat <= 40) # Constraint on the total number of labor hrs available
• Giapetto’s, Inc., manufactures two types of wooden toys: soldiers and trains.
• Each soldier built:
• sells for $27 and uses $10 worth of raw materials.
• increases Giapetto’s variable labor/overhead costs by $14.
• requires 2 hours of finishing labor and 1 hour of carpentry labor.
• Each train built:
• sells for $21 and used $9 worth of raw materials.
• increases Giapetto’s variable labor/overhead costs by $10.
• requires 1 hour of finishing labor and 1 hour of carpentry labor.
• Each week Giapetto has only 100 finishing hours and 80 carpentry hours.
• Demand for trains is unlimited, but at most 40 soldiers are bought each week.
• Giapetto wants to maximize weekly profit (revenues - costs).
IE 311 11
• Giapetto’s, Inc., manufactures two types of wooden toys: soldiers and trains.
• Each week Giapetto has only 100 finishing hours and 80 carpentry hours.
• s : number of soldiers built • Demand for trains is unlimited, but at most 40 soldiers are bought each week.
• Giapetto wants to maximize weekly profit (revenues - costs).
IE 311 12
• Giapetto’s, Inc., manufactures two types of wooden toys: soldiers and trains.
• Finishing hours availability • Each week Giapetto has only 100 finishing hours and 80 carpentry hours.
• Demand for trains is unlimited, but at most 40 soldiers are bought each week.
• Giapetto wants to maximize weekly profit (revenues - costs).
• Nonnegativity
IE 311 13
Giapetto LP: Python-Gurobi Implementation
IE 311 14
Giapetto LP - Generic Form
IE 311 15
Graphical Solution Method
• Notice that both examples considered so far (Farmer and Giapetto) have only
two variables.
• It is possible to solve LPs with two variables by the “Graphical Solution Method”.
• This method gives valuable intuition as to the possible outcomes of LPs:
• LP is infeasible (no feasible solution exists)
• LP is feasible (feasible solution exists)
• LP has unbounded objective (the “optimal value” is unbounded)
• LP has bounded objective (the optimal value is bounded)
• Unique optimal solution
• Multiple optimal solution
• We will see later in the course that the Simplex Method is based on the intuition
obtained from the Graphical Solution Method.
IE 311 16
Graphical Solution Method: Giapetto LP
IE 311 17
Post Office (Winston, page 72)
IE 311 18
• A post office requires different numbers of full-time employees on different days of the week.
• The number of full-time employees required on each day is given in as 17, 13, 15, 19, 14, 16, 11.
• Union rules state that each full-time employee must work five consecutive days and then receive two days
Post Office: Key Observations •
off. For example, an employee who works Monday to Friday must be off on Saturday and Sunday.
The post office wants to meet its daily requirements using only fulltime employees.
• Formulate an LP and IP that the post office can use to minimize the number of full-time employees who
must be hired.
IE 311 19
• A post office requires different numbers of full-time employees on different days of the week.
• The number of full-time employees required on each day is given in as 17, 13, 15, 19, 14, 16, 11.
•
Union rules state that each full-time employee must work five consecutive days and then receive two days
off. For example, an employee who works Monday to Friday must be off on Saturday and Sunday.
The post office wants to meet its daily requirements using only fulltime employees.
• Formulate an LP and IP that the post office can use to minimize the number of full-time employees who
must be hired.
IE 311 21
Diet LP (Winston, page 69)
• My diet requires that all the food I eat come from one of the four “basic food groups” (chocolate
cake, ice cream, soda, and cheesecake).
• At present, the following four foods are available: brownies, chocolate ice cream, cola, and pineapple
cheesecake.
• Each brownie costs 50¢, each scoop of chocolate ice cream costs 20¢, each bottle of cola costs 30¢,
and each piece of pineapple cheesecake costs 80¢.
• Each day, I must ingest at least 500 calories, 6 oz of chocolate, 10 oz of sugar, and 8 oz of fat.
• The nutritional content per unit of each food is shown in the following table:
Ingredients Brownie Chocolate ice cream Cola Pineapple cheesecake
Calories 400 200 150 500
Chocolate (oz) 3 2 0 0
Sugar (oz) 2 2 4 4
Fat (oz) 2 4 1 5
• Formulate a linear programming model that can be used to satisfy my daily nutritional requirements
at minimum cost. How can you generalize the model with m ingredients and n food types?
IE 311 22
• At present, the following four foods are available: brownies, chocolate ice cream, cola, and
pineapple cheesecake.
• Each brownie costs 50¢, each scoop of chocolate ice cream costs 20¢, each bottle of cola costs 30¢,
Diet LP – Specific Formulation •
and each piece of pineapple cheesecake costs 80¢.
Each day, I must ingest at least 500 calories, 6 oz of chocolate, 10 oz of sugar, and 8 oz of fat.
• Formulate a linear programming model that can be used to satisfy my daily nutritional requirements
at minimum cost. How can you generalize the model with m ingredients and n food types?
• Chocolate requirement
• Sugar requirement
• Fat requirement
• My diet requires that all the food I eat come from one of the n different
types of foods.
• One unit of food type j costs 𝑐𝑗 for 𝑗 = 1, … , 𝑛.
• One unit of food type j has 𝑎𝑖𝑗 units of ingredient type i for 𝑖 = 1, … , 𝑚.
• Each day, I must ingest at least 𝑏𝑖 units of ingredient type i for 𝑖 =
1, … , 𝑚.
• Formulate a linear programming model that can be used to satisfy my
daily nutritional requirements at minimum cost.
IE 311 25
Diet LP – Generic Formulation
IE 311 26
Transportation LP
• A decision now needs to be made about the shipping plan for how many units to
ship from each factory to each customer.
• Formulate this problem as an LP.
IE 311 27
Transportation LP: Key Observations
F2
C3
IE 311 28
Transportation LP: Key Observations
F2 F2
C3 C3
IE 311 29
Transportation LP
IE 311 30
Transportation LP: General Model
IE 311 31
Blending LP (Winston, page 86)
• Sunco Oil manufactures three types of gasoline. Each type is produced by blending three types of crude oil.
• The sales price of gasoline, the purchase price of crude oil and their octane and sulfur content are given as below:
Gas Price($) Oil Cost($) Octane Sulfur(%)
1 70 1 45 12 0.5
2 60 2 35 6 2.0
3 50 3 25 8 3.0
• Sunco can purchase up to 5,000 barrels of each type of crude oil daily. The three types of gasoline differ in their
octane and sulfur content as follows:
• The crude oil blended to form gas 1 must have an average octane rating of at least 10 and contain at most 1% sulfur.
• The crude oil blended to form gas 2 must have an average octane rating of at least 8 and contain at most 2% sulfur.
• The crude oil blended to form gas 3 must have an average octane rating of at least 6 and contain at most 1% sulfur.
• It costs $4 to transform one barrel of oil into one barrel of gasoline, Sunco’s refinery can produce up to 14,000
barrels of gasoline daily.
• Sunco’s customers require the following amounts of each gasoline daily: gas 1—3,000 barrels; gas 2—2,000
barrels; gas 3—1,000 barrels.
• Sunco also has the option of advertising to stimulate demand for its products. Each dollar spent daily in
advertising a particular type of gas increases the daily demand for that type of gas by 10 barrels.
• Formulate an LP that will enable Sunco to maximize daily profits (revenues - costs).
32
Blending LP: Key Observations
O2 G2
O3 G3
IE 311 33
Blending LP: Key Observations
O1 G1 O1 G1
O2 G2 O2 G2
O3 G3 O3 G3
IE 311 34
Gas Price($) Oil Cost($) Octane Sulfur(%)
Blending LP: Key Observations 1
2
70 1
60 2
45
35
12
6
0.5
2.0
3 50 3 25 8 3.0
6
O2 G2
8
O3 G3
IE 311 35
Gas Price($) Oil Cost($) Octane Sulfur(%)
Blending LP: Decision Variables and 1 70 1 45 12 0.5
2 60 2 35 6 2.0
Objective Function 3 50 3 25 8 3.0
• Decision variables:
• Objective:
Blending LP: Constraints
• Oil availability:
• Gas demand:
• Total capacity:
• Octane rating:
• Sulfur content:
• Nonnegativity:
Powerco Electric Company
• Powerco has three electric power plants that supply electricity to four cities.
• The table below shows
• the cost of sending 1 kwh of electricity from each plant to each city
• the capacity of each plant
• the exact demand of each city.
City 1 City 2 City 3 City 4 Capacity
Plant 1 $8/kwh $6/kwh $10/kwh $9/kwh ≤ 35 Mwh
Plant 2 $9/kwh $12/kwh $13/kwh $7/kwh ≤ 50 Mwh
Plant 3 $14/kwh $9/kwh $16/kwh $5/kwh ≤ 45 Mwh
Demand = 45 Mwh = 20 Mwh = 30 Mwh = 30 Mwh
• A decision now needs to be made about the dispatch of electricity regarding
how many Mwh to send from each plant to each city.
• Formulate this problem as an LP, implement and solve in the Python-
Gurobi interface.
IE 311 38
Production Process (Winston, page 95)
IE 311 39
Production Planning
IE 311 42
Production Planning
IE 311 43
A Few “Tricks” to Linearize Special Nonlinear Expressions
IE 311 44
Machine Balancing Example
• A machine shop has a drill press and a milling machine which are used
to produce two parts A and B.
• The required time (in minutes) per unit part on each machine is shown
in the table below.
Part Drill Press Milling Machine
A 3 4
B 5 3
• The shop must produce at least 50 units in total (both A and B) and at
least 30 units of part A, and it can make at most 100 units of part A and
100 units of part B.
• Formulate an LP to minimize the absolute difference between the total
running time of the drill press and that of the milling machine.
IE 311 45
Machine Balancing Example
IE 311 46
Single Facility Rectilinear Distance Location Problem
• We are given the location of 6 plants in 2D space and their raw material demand.
x-Coordinate y-Coordinate Demand
1 1 50
5 12 60
2 8 19
4 4 20
8 6 32
10 7 23
IE 311 53
Single Facility Rectilinear Distance Location Problem
IE 311 54
Sailco Inventory (Winston, page 101)
• Sailco must determine how many sailboats should be produced during next four quarters.
• The demand during each of the next four quarters is 40, 60, 75, 25, respectively.
• Sailco must meet demands on time. At the beginning of the first quarter, Sailco has an inventory
of 10 sailboats.
• At the beginning of each quarter, Sailco must decide how many sailboats should be produced
during that quarter. For simplicity, we assume that sailboats manufactured during a quarter can be
used to meet demand for that quarter.
• During each quarter, Sailco can produce up to 40 sailboats with regular-time labor at a total cost
of $400 per sailboat. By having employees work overtime during a quarter, Sailco can produce
additional sailboats with overtime labor at a total cost of $450 per sailboat.
• At the end of each quarter (after production has occurred and the current quarter’s demand has
been satisfied), a carrying or holding cost of $20 per sailboat is incurred.
• Use linear programming to determine a production schedule to minimize the sum of production
and inventory costs during the next four quarters.
IE 311 55
Sailco Inventory (Winston, page 101)
IE 311 56