You are on page 1of 23

ISyE 3012 Optimization II

Lecture 2
September 14, 2016

Last class

The engineering way for optimization


I

Transform a real-world optimization problem to a


mathematical program
Transform the mathematical program into a computer file,
using a modeling language
Select the right solver to solve the mathematical program
encoded in the file

The first AMPL example

Todays agenda

Variable indexing and abstract models

Advanced AMPL coding techniques

Example 1: Steel production


A steel company must decide how to allocate next
weeks time on a rolling mill. The mill takes
unfinished slabs of steel as input, and can produce
either of two semi-finished products, which we will
call bands and coils.
I The mills two products come off the rolling line at different
rates: Bands - 200 tons/hour, Coils - 140 tons/hour. The
price is $25 per ton for bands and $30 per ton for coils. The
weekly production capacity is 6, 000 tons for bands and
4, 000 tons for coils.
I

If 40 hours of production time are available this week, how


many tons of bands and coils should be produced to bring
in the greatest total profit?

Solution: a concrete linear programming model

Decisions
I
I

XB - The number of tons of bands to be produced


XC - The number of tons of coils to be produced

The model
max
s.t.

25xB + 30xC

(maximize the net profit)

(1/200)XB + (1/140)XC 40

(Constraint on available hours)

0 XB 6000

(Production capacity on bands)

0 XC 4000

(Production capacity on coils)

Solution: an abstract model


I

Given:
I
I
I
I
I

P - a set of products
aj - tons per hour of product j, for each j P
b - hours available at the mill
cj - profit per ton of product j, for each j P
uj - maximum tons of product j, for each j P

Decision variables Xj - tons of product j to be made, for


each j P

The model

max

cj Xj

(maximize the net profit)

jP

s.t.

(1/aj )Xj b

(Constraint on available hours)

jP

0 Xj uj , for each j P

(Production capacity constraints)

The advantage of an abstract model

In practice, we usually solve similar optimization problems


(e.g., steel production) over and over again; the only
differences in these models are the number of decision
variables (e.g., if a new product plate is introduced, we
also need to decide how many tons of plate to produce)
and the values of some parameters (e.g., price of a
product).

We have to build a concrete model for every specific


optimization problem we solve.

The abstract model separates the model from the data.


You only need one model for the same type of optimization
problems. All the changes are done by changing the data
file.

Elements of an abstract model

sets, like the products

parameters, like the production and profit rates

variables, whose values the solver is to determine

an objective, to be maximized or minimized

constraints that the solution must satisfy.

The corresponding keywords in AMPL

Elements
sets
parameters
variables
an objective
constraints

AMPL keywords
set
param
var
maximize or minimize
subject to or s.t.

The AMPL code

Files
I

prod.mod - the model file containing the abstract model

prod.dat - the data file specifying the sets and parameters

Indexing and summation expressions


AMPL Syntax
{j in P}
var X{j in P}
c[j]
sum {j in P} c[j] * X[j]
Limit {j in P}: 0 <= X[j] <= u[j]

Meaning
for every j in P
declare variables Xj for j in P
theP
coefficient cj
jP cj Xj
0 Xj uj for every j in P

The improved AMPL code

Give more meaningful names to sets, parameters, and


variables
I

steel.mod

steel.dat - data file 1

steel2.dat - data file 2

Problem 1: Oil blending


I

Chandler Oil Company has 5, 000 barrels of oil 1 and


10, 000 barrels of oil 2. The company sells two products:
gasoline and heating oil. Both products are produced by
combining oil 1 and oil 2. The quality levels of oils 1 and 2
are 10 and 5 respectively. The combination of a barrels of
oil 1 and b barrels of oil 2 generates a + b barrels of
product of quality 10a+5b
a+b .

Gasoline must have an average quality level of at least 8,


and heating oil at least 6. Demand for each product must
be created by advertisement. Each dollar spent advertising
gasoline creates 5 barrels of demand and each dollar
spent on heating oil creates 10 barrels of demand.
Gasoline is sold for $25 per barrel, heating oil for 20.

Formulate an optimization model to help Chandler Oil


maximize profit.

Solution - a concrete model


I
I

Let index i denote the oil type and j denote the product
type (1 for gasoline and 2 for heating oil)
Decision variables
I
I

I
max
s.t.

xij - barrel of oil i used to make product j


yj - amount of dollars spent on advertising product j

The model (See AMPL files oil0.mod.)


25(x11 + x21 ) + 20(x12 + x22 ) y1 y2

(maximize the net profit)

x11 + x12 5000

(available limit on oil 1)

x21 + x22 10000

(available limit on oil 2)

10x11 + 5x21
8
x11 + x21
10x12 + 5x22
6
x12 + x22
x11 + x21 = 5y1
x12 + x22 = 10y2
xij 0, i = 1, 2, j = 1, 2
yj 0, j = 1, 2

(quality constraint for gasoline)


(quality constraint for heating oil)
(gasoline supply equals to demand)
(heating oil supply equals to demand)

Solution - a concrete model

Is this model a linear program?


I

Technical issues: x11 and x21 (x12 and x22 ) cannot both be
zero in the model, but it is a feasible decision for the
problem. (Try to solve the model in AMPL)

Can you transform the model to a linear program without


changing optimal decisions?

An abstract model
Suppose you need to solve the blending problem multiple times
with different products and parameters, how would you build
the abstract model?
I Define sets
I
I

Oil types (oil 1 and oil 2)


Product type (gasoline and heating oil)

Identify parameters
I
I
I
I

Initial inventory of each oil type


Quality level of each oil type
Required quality level of each type of product
Demand of each type of product generated by one dollar
spent on advertising
The unit price for each type of product

Write an abstract model in AMPL and specify the data file

Solve the model

Solution - an abstract model

Sets
I
I

parameters
I
I
I
I

I = {1, 2} - set of oil types


J = {gasoline, heating oil}
bi - initial inventory of oil i I at the beginning
qi - quality level of oil i I
rj - required quality level of product j J
dj - demand created for product j J with each dollar spent
on ads
pj - unit price for product j J

Decision variables
I
I

xij - barrel of oil i I used to make product j J


yj - amount of dollars spent on advertising product j J

The abstract model

max

X
jJ

s.t.

X
X
pj (
xij )
yj
iI

(maximize the net profit)

jJ

xij bi , i I

(available limit on oil)

qi xij rj

iI

xij , j J

(quality constraint on products)

iI

xij = dj yj , j J

(product supply equals to demand)

iI

xij 0, i I, j J
yj 0, j J

Tips: use x[i,j] in AMPL to reference the variable xij .

The maximum s-t flow problem from lecture 1

Given a directed graph G = (V , A), two vertices s, t V ,


and the capacity uij over arc (i, j) A, an s-t flow is an
assignment of values xij to each arc (i, j) A such that
I
I

I
I

0 xij uij for each (i, j) A (Bound constraints)


the total flow into vertex i equals the total flow out of vertex
i, for i V \ {s, t} (Flow balance constraints)

The value of an s-t flow is the difference of total flow out of


vertex s and the total flow into vertex s
The maximum flow problem
I

Input: a directed graph, two vertices s and t, the capacity


over each arc
Output: an s-t flow of maximum value

The abstract model

Sets
I
I

Parameters
I

I
I

Capacity uij for arc (i, j) A

Decision variables xij amount of flow sent through arc (i, j)


Constraints
I
I

Set of vertices V
Set of arcs A {(i, j) | i V , j V }

Flow balance constraints for each node i V except s, t


Bound constraints of xij for each (i, j) A

The objective - maximize the difference of total flow out of


vertex s and the total flow into vertex s

The abstract Model continued


I

Decision variables xij amount of flow sent through arc


(i, j) A
Constraints
I
I

max

Flow balance constraints for each node i V except s, t


Bound constraints of xij for each (i, j) A

The objective - maximize the difference of total flow out of


vertex s and the total flow into vertex s
X

xsj

X
j:(j,i)A

xjs

(maximize the net flow out of s)

j:(j,s)A

j:(s,j)A

s.t.

xji

xij = 0, i V \ {s, t}

(flow balance constraints)

j:(i,j)A

0 xij uij , (i, j) A

(Bound constraints)

We will learn how to transcribe the model above to AMPL code later (we need sets of
ordered pairs in AMPL).

The stable set problem from lecture 1

Given a graph G = (V , A), a stable set is a set S V of


vertices such that (i, j)
/ A for any i, j S.
The stable set problem.
I
I

Input: an undirected graph


Output: a stable set of largest size

The abstract model

Sets
I
I

Decision variables xi for each i V . (We let xi = 1 if vertex


i is included in the stable set and xi = 0 otherwise)
Constraints
I

Set of vertices V
Set of arcs A {(i, j) | i V , j V }

For each edge (i, j) A, vertex i and vertex j cannot both


belong to the stable set
xi {0, 1} for each i V

The objective - maximize the size of the stable set

The abstract Model continued

I
I

Decision variables xi for each i V .


Constraints
I

For each edge (i, j) A, vertex i and vertex j cannot both


belong to the stable set
xi {0, 1} for each i V

The objective - maximize the size of the stable set

max

xi

(maximize the size of the stable set)

iV

s.t.

xi + xj 1, (i, j) A

(conflict constraints)

xi {0, 1}, i V

(Binary constraints)

You might also like