0% found this document useful (0 votes)
56 views

2a.modeling Linear and Integer Programs-2

Modeling Linear and Integer Programs

Uploaded by

berkyildizdas
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views

2a.modeling Linear and Integer Programs-2

Modeling Linear and Integer Programs

Uploaded by

berkyildizdas
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 54

IE 311 – Operations Research I

Part 2: Modeling Linear and Integer Programs


2a. Linear Programs

Summer 2024
Modeling Linear and Integer Programs

• An extremely important aspect of Operations Research is to


formulate the optimization problem correctly.
• Another extremely important aspect of Operations Research is to
implement and solve the formulated optimization problem.
• We will spend the first 2-3 weeks of the course solely focusing on
how to formulate Linear and Mixed-Integer Linear Programming
problems and solve them using the Python-Gurobi interface.

IE 311 2
Recall: Types of Linear Optimization Models

• An optimization problem with linear relations between continuous


variables is called a Linear Program:

• An optimization problem with linear relations between integer


variables is called a (Pure) Integer (Linear) Program:

• An optimization problem with linear relations between continuous


and integer variables is called a Mixed-Integer Linear Program:

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.
• 7 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
Farmer LP: Components (I)

•Parameters (what are given?)


• Type of grains (corn and wheat)
• Yield of each type (10 bushels/acre for corn, 25 bushels/acre for wheat)
• Revenue of each type ($3/bushel for corn, $4/bushel for wheat)
• Area availability (7 acres in total)
• Labor requirement for each type (4 hrs/acre for corn, 10 hrs/acre for
wheat)
• Labor availability (40 hrs in total)
• Government regulations (at least 30 bushels of corn)

IE 311 5
Farmer LP: Components (II)

•Decision variables (what can be decided/changed?)


• c : amount of acres allocated to corn
• w : amount of acres allocated to wheat

•Objective function (what is the aim?)


• Maximize the total revenue

IE 311 6
Farmer LP: Components (III)

•Constraints (what should be obeyed/respected?)


• Land availability

• Labor availability

• Government regulations

• Nonnegativity

IE 311 7
Assumptions in Linear Programming

• Proportionality: A change in a variable results in a proportionate change in that variable's


contribution to the value of the function.
• due to linear relation between the variables
• e.g. Labor used = (Labor per acre for corn)*acres of corn + (Labor per acre for wheat)*acres of wheat
• Nonlinear relation between the variables would have violated this assumption.
• Additivity: The value of the function is the sum of the contributions of each term.
• due to linear relation between the variables
• e.g. Labor used = (Labor per acre for corn)*acres of corn + (Labor per acre for wheat)*acres of wheat
• Nonlinear relation between the variables would have violated this assumption.

IE 311 8
Assumptions in Linear Programming

• Divisibility: Each decision variable is be allowed to assume fractional values.


• due to continuity of the variables
• e.g. Planting 3.0 acres of corn and 2.8 acres of wheat is possible.
• Existence of integer variables would have violated this assumption.
• Certainty: Each parameter (objective function coefficient, righthand side, and
technological coefficient) is known with certainty.
• due to deterministic nature of parameters
• e.g. It is certain that 1 acre of corn yields 10 bushels.
• Existence of random/uncertain parameters would have violated this assumption.

IE 311 9
Giapetto LP (Winston, page 49)

• 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 uses $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 available.
• Demand for trains is unlimited, but at most 40 soldiers are bought each week.
• Giapetto wants to maximize weekly profit (revenues - costs).
IE 311 10
Giapetto LP: Model (I)

•Decision variables (what can be decided/changed?)


• s : number of soldiers built
• t : number of trains built

•Objective function (what is the aim?)


• Maximize the weekly profit

IE 311 11
Giapetto LP: Model (II)

•Constraints (what should be obeyed/respected?)


• Finishing hours availability

• Carpentry hours availability

• Demand for soldiers

• Nonnegativity

• Is the divisibility assumption satisfied?

IE 311 12
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 13
Graphical Solution Method: Giapetto LP

(1)
(3)
(1)
(2)
(3)

(2)

IE 311 14
Post Office (Winston, page 72)

• 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 15
Post Office: Key Observations

•Decision variables (what can be decided/changed?)


• We need to decide how many employees start working on each day 𝑖, 𝑖 = 1, … , 7.

•Constraints (what should be obeyed/respected?)


• We need to make sure that requirement on each day is satisfied.
• Question: Who is working on Friday?
• Answer: Employees who start on Monday, Tuesday, Wednesday, Thursday, Friday.

IE 311 16
Post Office LP vs. IP

• Decision variables: Let 𝑥𝑖 be the number of employees starting in day 𝑖, 𝑖 = 1, … , 7.


• LP Model

• IP Model: Declare the variables as integer


• Which model is more appropriate?
IE 311 17
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 Daily Requirement
Calories 400 200 150 500 500
Chocolate (oz) 3 2 0 0 6
Sugar (oz) 2 2 4 4 10
Fat (oz) 2 4 1 5 8
• 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 18
Diet LP – Specific Formulation

• Decision variables (what can be decided/changed?)


• xi: the amount of brownie, chocolate ice cream, cola and pineapple cheesecake
consumed, respectively, 𝑖 = 1, … , 4.

•Objective function (what is the aim?)


• Minimize the daily cost of my diet

IE 311 19
Diet LP – Specific Formulation

•Constraints (what should be obeyed/respected?)


• Calorie requirement

• Chocolate requirement

• Sugar requirement

• Fat requirement

• Nonnegativity

IE 311 20
Diet LP – Generic Formulation

IE 311 21
Transportation LP

• A company produces medical diagnostic equipment at two factories.


• Three medical centers have placed orders for this month.
• The table below shows
• the cost of shipping each unit from each factory to each of these customers
• the number of units that will be produced at each factory
• the number of units ordered by each customer.
Customer 1 Customer 2 Customer 3 Output
Factory 1 $600/item $800/item $700/item 400 units
Factory 2 $400/item $900/item $600/item 500 units
Order Size 300 units 200 units 400 units

• 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 22
Transportation LP: Key Observations

• Decision variables (what can be decided/changed?)


• We need to know how many items are sent from each factory to each customer.

C1
F1
C2

F2
C3

IE 311 23
Transportation LP: Key Observations

•Constraints (what should be obeyed/respected?)


• We need to obey the factory capacities and satisfy customer demands.
• Question: What is the total • Question: What is the total
amount sent from Factory 1? amount received by Customer 2?

C1 C1
F1 F1
C2 C2

F2 F2
C3 C3

IE 311 24
Transportation LP

IE 311 25
Transportation LP: General Model

IE 311 26
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 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).

IE 311 27
Blending LP: Key Observations

• Decision variables (what can be decided/changed?)


• We need to know how much oil of each type is used in each gas blend.
O1 G1

O2 G2

O3 G3

• We also need to know the advertisement amount for each gas.

IE 311 28
Blending LP: Key Observations

•Constraints (what should be obeyed/respected?)


• We need to obey the crude oil availability and satisfy gas demands.
• Question: What is the total • Question: What is the total
amount of oil 1 used? amount of gas 3 blended?

O1 G1 O1 G1

O2 G2 O2 G2

O3 G3 O3 G3

IE 311 29
Blending LP: Key Observations

•Constraints (what should be obeyed/respected?)


• We need to have gas blends satisfying the quality requirements.
• Question: What is the average octane rating of gas 3 blended?
12
O1 G1

6
O2 G2

8
O3 G3

12 × (Oil 1 in Gas 3) + 6 × (Oil 2 in Gas 3) + 8 × (Oil 3 in Gas 3)


Answer: 12 × (Oil 1 in Gas 3) + 6 × (Oil 2 in Gas 3) + 8 × (Oil 3 in Gas 3)

IE 311 30
Blending LP: Decision Variables and Objective Function
• Decision variables:

• Some “intermediary” quantities:

• Objective:

31
Blending LP: Constraints
• Oil availability:
• Gas demand:

• Total capacity:
• Octane rating:

• Sulfur content:

• Nonnegativity:
32
Production Planning

• A company must plan its production for the next 4 months.


• The demand for its product is 40, 70, 30, 50 units in months t = 1, … , 4. The
company must meet its demand exactly every month.
• The cost of production per unit product varies as: $20, $15, $35, $100 in
months t = 1, … , 4.
• The company can carry inventory of the inputs (i.e. the company can produce
more than required and store it as inventory to be used later). The per unit
cost of storing inventory from month 1 to month 2 is $15, month 2 to month
3 is $25, month 3 to month 4 is $10.
• Assume that the company has a starting inventory of 10 units. The company
plans to have no inventory at the end of month 4.
• Write a linear program to find an optimal production and inventory plan.
IE 311 33
Production Planning: Key Observations

• Decision variables (what can be decided/changed?)


• We need to know the production and ending inventory of each month.

•Constraints (what should be obeyed/respected?)


• We need to obey the inventory (or material balance) requirements.

Production Production Production Production


in month 1 in month 2 in month 3 in month 4
End inventory End inventory End inventory End inventory End inventory
Month 1 Month 2 Month 3 Month 4
of month 0 of month 1 of month 2 of month 3 of month 4
Demand Demand Demand Demand
of month 1 of month 2 of month 3 of month 4

IE 311 34
Production Planning

IE 311 35
A Few “Tricks” to Linearize Special Nonlinear Expressions

• Since | ∙ | is not a linear function, a constraint of the form |𝑥| ≤ 1 is not


linear either.
• However, this is an “easy” nonlinearity since 𝑥 ≤ 1  − 𝑥 ≤ 1, 𝑥 ≤ 1.

• More generally, we have max 𝑥1 , 𝑥2 ≤ 𝑦  𝑥1 ≤ 𝑦, 𝑥2 ≤ 𝑦.

• Even more generally, we have


max {σ𝑛𝑗=1 𝑎𝑖𝑗 𝑥𝑗 } ≤ 𝑦  σ𝑛𝑗=1 𝑎𝑖𝑗 𝑥𝑗 ≤ 𝑦 𝑖 = 1, … , 𝑚.
𝑖=1,…,𝑚

IE 311 36
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 37
Machine Balancing Example

IE 311 38
Piecewise Linear Example

• A farm grows two types of mangoes. This year the yield of mangoes of type 1 is 1000
units and that of type 2 is 700 units. The farm sells all its mangoes.
• The mangoes can be sold to a retail company and can also be sold in a local market
directly. The contract with the retail company has the following details:
• At least 60% of the total amount of mangoes sold to the retail company must be type 2.
• The retail company has a demand of 1000 units of mangoes and pays $3 per unit for both types.
The demand does NOT need to be satisfied exactly.
• If the total amount of mangoes sold to the retail company is less than 1000 units, then there is a
penalty of $0.05 per unit shortfall from 1000 units.
• If the number of units of mangoes is more than 1200, then each unit over the first 1200 units is
purchased by the retail store at the rate of $2.5 per unit.
• Mangoes of type 1 sell at $2.2 per unit in the local market and mangoes of type 2
sell for $3.1 per unit in the local market.
• Any amount of mangoes can be sold in the local market.
• Formulate a linear program to maximize the net revenue of the farm.

IE 311 39
Piecewise Linear Example

• Decision variables:

• Constraints:

• Objective function:
• We need to understand the details of the retailer contract.
IE 311 40
Piecewise Linear Example: Retailer Contract

• The retail company has a demand of 1000 units of mangoes and pays $3 per unit
for both types.
• If the total amount of mangoes sold to the retail company is less than 1000 units,
then there is a penalty of $0.05 per unit shortfall from 1000 units.
• If the number of units of mangoes is more than 1200, then each unit over the
first 1200 units is purchased by the retail store at the rate of $2.5 per unit.

IE 311 41
Piecewise Linear Example: Retailer Contract

IE 311 42
Piecewise Linear Example: Retailer Contract

• Notice that maximizing a concave piecewise linear function is “easy”:

• This is an LP!

IE 311 43
Piecewise Linear Example: Complete Model

IE 311 44
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
• The raw material will be provided from a warehouse to be located.
• The transportation cost between the warehouse located at (x,y) and a plant located at (a,b) is equal
to demand times the rectilinear distance, that is, 𝑥 − 𝑎 + |𝑦 − 𝑏|.
• Provide a linear program which minimizes the total transportation cost.
• What if our aim is to minimize the largest distance between the warehouse and plants?

IE 311 45
Single Facility Rectilinear Distance Location Problem

𝑥 ≥ 0, 𝑦 ≥ 0

IE 311 46
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 47
Sailco Inventory (Winston, page 101)

IE 311 48
Powerco Electric Company (Winston, page 360)

• 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 49
Powerco Electric Company (Winston, page 360)

• Decision Variables:
𝑥𝑖𝑗 : # of (million) kwh produced at plant i and sent to city j
• The model:

7.07.2024 Faculty Name 50


Powerco Electric Company (Winston, page 360)

7.07.2024 Faculty Name 51


Dorian Auto LP (Winston, page 60)

• Dorian Auto manufactures luxury cars and trucks.


• The company believes that its likely customers are high-income women and men.
• To reach these groups, Dorian Auto has decided to purchase 1-minute commercial
spots on two types of programs: comedy shows and football games.
• Each comedy commercial is seen by 7 million high-income women and 2 million
high-income men.
• Each football commercial is seen by 2 million high-income women and 12 million
high-income men.
• A 1-minute comedy ad costs $50,000, and a 1-minute football ad costs $100,000.
• Dorian would like the commercials to be seen by at least 28 million high-income
women and 24 million high-income men.
• How can Dorian Auto meet its advertising requirements at minimum cost?
• Model this problem as an LP, implement and solve in the Python-Gurobi interface.
IE 311 52
Dorian Auto LP (Winston, page 60)

• Decision Variables:

• Objective Function:

• Constraints:

IE 311 53
Giapetto LP: Python-Gurobi Implementation

•Two Python-Gurobi Implementations of the Giapetto LP is already


uploaded to the Sucourse.
• Implementation 1: See the function ModelHardcoded.
• In this version, all the parameters are “hard-coded”.
• This is NOT the best coding practice as the implementer would need to go to the details on this
function even if one of the parameters is changed.
• Implementation 2: See the function ModelBetterImplemented.
• In this version, all the parameters are sent as arguments.
• This is a better coding practice as the implementer would only need to change the arguments
sent to the function.
• Both implementations will be accepted when grading your work but it is strongly
suggested to follow Implementation 2 whenever possible.

IE 311 55

You might also like