Slides (ORPOT2)

advertisement
Chapter 2: Linear Programming Problems:
Basic Ideas
2.1 Introduction to Linear Programming
2.2 Formulating and Solving Linear Programming
Problems Using the OPTMODEL Procedure
2.3 Reading Data from SAS Data Sets
2.4 Writing Output from the OPTMODEL Procedure
2.5 Dual Values, Reduced Costs, and Pricing in the
Simplex Method
1
Chapter 2: Linear Programming Problems:
Basic Ideas
2.1 Introduction to Linear Programming
2.2 Formulating and Solving Linear Programming
Problems Using the OPTMODEL Procedure
2.3 Reading Data from SAS Data Sets
2.4 Writing Output from the OPTMODEL Procedure
2.5 Dual Values, Reduced Costs, and Pricing in the
Simplex Method
2
Objectives


3
Understand how, geometrically, the primal simplex,
dual simplex, and interior point methods solve linear
programming problems.
Enter and solve simple linear programming problems
using the OPTMODEL procedure.
A Linear Programming Problem
min | max c1x1 +...+ c n xn
subject to Ax {, , } b
l j  x j  u j ( j 1,2,...,n)


4
Each of the linear constraints can be either an
inequality or an equation.
The bounds can be ±∞, so that xj can be restricted
to be non-negative (lj=0 and uj=+∞) or free (lj=-∞
and uj=+∞).
Implicit Assumptions of Linear Programming




5
Proportionality
Additivity
Divisibility
Certainty
Two-Dimensional Example
The following LP has decision variables x and y:
maximize
12x +19y
subject to
x + 3y ≤ 225
x + y ≤ 117
3x + 4y ≤ 420
x ≥ 0, y ≥ 0
The constraints of the LP determine a feasible region
in two dimensions.
6
y axis
Feasible Region
x axis
7
Feasible Region
An extreme
point is a
corner of the
feasible region
[0, 75]
y axis
[63, 54]
optimal
solution
extreme point
solutions
[117, 0]
[0, 0]
x axis
8
Solving a Linear
Programming Problem
Using PROC OPTMODEL
2dimensional.sas
This demonstration illustrates the solution
of a linear programming problem using
PROC OPTMODEL with the default, primal
simplex and iterative interior point solvers.
14
Primal Simplex Trajectory
[0, 75]
y axis
[63, 54]
optimal
solution
extreme point
solutions
[117, 0]
[0, 0]
x axis
15
Dual Simplex Trajectory
[0, 75]
y axis
[63, 54]
optimal
solution
extreme point
solutions
[117, 0]
[0, 0]
x axis
16
Iterative Interior Trajectory
[0, 75]
y axis
[63, 54]
optimal
solution
extreme point
solutions
[117, 0]
[0, 0]
x axis
17
Exercises 1 and 2
These exercises reinforce the concepts discussed
previously.
18
Chapter 2: Linear Programming Problems:
Basic Ideas
2.1 Introduction to Linear Programming
2.2 Formulating and Solving Linear Programming
Problems Using the OPTMODEL Procedure
2.3 Reading Data from SAS Data Sets
2.4 Writing Output from the OPTMODEL Procedure
2.5 Dual Values, Reduced Costs, and Pricing in the
Simplex Method
19
Objectives


20
Formulate linear programming problems using
array indexing or index sets, name constraints,
and store values in arrays and matrices.
Use the EXPAND statement to verify that a
formulation is correct.
A Furniture-Making Problem
A furniture-making company can manufacture desks,
chairs, bookcases, and bedframes, all of which require
various person-hours of labor and units of metal and
wood, given in the table below:
Desks
Chairs
Bookcases
Bedframes
21
Labor
(hrs)
2
1
Metal
(lbs)
1
1
Wood
(ft3)
3
3
Selling
Price ($)
52
44
3
2
1
1
4
4
70
61
A Furniture-Making Problem
The cost and availability of labor, metal, and wood are
as follows:
Labor
Metal
Wood
(hrs)
(lbs)
(ft3)
Cost ($)
Availability
7
225
10
117
Assuming that all furniture can
be sold, how many desks, chairs,
bookcases, and bedframes should
the company produce per day in
order to make its profit as large
as possible?
22
5
420
Three Distinct Formulation Approaches
Array Indices
Variable Names



explicit
enter data
intuitive



Index Sets




23
compact
read data
intuitive
flexible
compact
read data
abstract
A Furniture-Making Problem
The cost and availability of labor, metal, and wood are
as follows:
Labor
Metal
Wood
(hrs)
(lbs)
(ft3)
Cost ($)
Availability
7
225
10
117
Assuming that all furniture can
be sold, how many desks, chairs,
bookcases, and bedframes should
the company produce per day in
order to make its profit as large
as possible?

24
What should the decision
variables be?
5
420
A Furniture-Making Problem
The cost and availability of labor, metal, and wood are
as follows:
Labor
Metal
Wood
(hrs)
(lbs)
(ft3)
Cost ($)
Availability
7
225
10
117
5
420
Assuming that all furniture can
be sold, how many desks, chairs,
bookcases, and bedframes should
the company produce per day in
order to make its profit as large
as possible?

25
What should the decision
variables be?
Furniture-Making Problem Data
Labor
(hrs)
Metal
(lbs)
Wood
(ft3)
Selling
Price ($)
Desks
Chairs
Bookcases
Bedframes
2
1
3
2
1
1
1
1
3
3
4
4
52
44
70
61
Cost ($)
Availability
7
225
10
117
5
420

26
What should the objective be?
Furniture-Making Problem Data
Labor
(hrs)
Metal
(lbs)
Wood
(ft3)
Selling
Price ($)
Desks
Chairs
Bookcases
Bedframes
2
1
3
2
1
1
1
1
3
3
4
4
52
44
70
61
Cost ($)
Availability
7
225
10
117
5
420

What should the objective be?
Maximize profit = revenue - cost
27
Mathematical Optimization Formulations
The basic structure of the formulation of a mathematical
optimization problem is shown here:
min|max
objective function
subject to
constraints
variable bounds
The formulation should be followed by a description of the
decision variables, sets, and parameters in the formulation.
28
PROC OPTMODEL Formulations
The basic structure of a PROC OPTMODEL formulation
of a mathematical optimization problem is shown here:
proc optmodel;
/* declare sets and parameters */
/* declare variables */
/* declare constraints */
/* declare objective */
solve;
/* print solution */
quit;
29
Formulation Using Variable Names
proc optmodel;
/* declare variables */

desks, chairs, bookcases, bedframes
/* declare constraints */

availability of labor, metal, wood
/* declare objective */

maximize profit = revenue - cost
solve;
/* print solution */
quit;
30
Using PROC OPTMODEL
to Solve the Variable Names
Formulation of the
Furniture-Making Problem
furniture_names.sas
This demonstration illustrates using the
interactive nature of PROC OPTMODEL to
expand and then solve a linear programming
problem formulated using variable names.
31
The EXPAND Statement
The EXPAND statement has options to print only
a part of the linear programming formulation. This
is the statement’s syntax:
EXPAND [ identifier-expression ] [ / options ] ;
Identifier-expression is the name of a variable,
objective, or constraint. Options include the following:
VAR outputs variables.
OBJECTIVE|OBJ outputs objectives.
CONSTRAINT|CON outputs constraints.
32
Arrays versus Names in PROC OPTMODEL
An LP is compactly represented by arrays and matrices:
min | max cx
subject to Ax {, , } b
l x u
Advantages of arrays and matrices in PROC OPTMODEL:
 enter objective/constraint coefficients compactly
 read data from SAS data files
 make formulations portable/scalable/adaptable
PROC OPTMODEL syntax for matrix and array entries is
A[i,j] and b[i].
33
Example: Transportation Problem
Given supply values at a set of origins and demand
values at a set of destinations, the transportation problem
is to determine the amount to transport from each origin to
each destination to meet the demand at a minimum cost.
A linear programming model of a transportation problem
with two origins and three destinations is
3
i=1
j=1 ij ij
3
j=1
ij
i
2
i=1
ij
j
xij  0 (i =1,2; j =1,2,3)
34
1
Origins
subject to
  cx
 x  s (i =1,2)
 x  d ( j =1,2,3)
2
1
2
2
3
Destinations
minimize
The SUM Aggregation Operator
The SUM aggregation operator can be used to add numeric
or variable expressions:
print (sum{k in 1..24} k**2);
PROC OPTMODEL Output
4900
In this sum, k is a local dummy parameter.
35
The SUM Aggregation Operator
The SUM aggregation operator can be used to add numeric
or variable expressions:
print (sum{k in 1..24} k**2);
min Cost = sum{i in 1..2, j in 1..3}
c[i,j] * x[i,j];
con
con
con
con
con
s1:
s2:
d1:
d2:
d3:
sum{j
sum{j
sum{i
sum{i
sum{i
in
in
in
in
in
1..3}
1..3}
1..2}
1..2}
1..2}
x[1,j]
x[2,j]
x[i,1]
x[i,2]
x[i,3]
<=
<=
>=
>=
>=
s[1];
s[2];
d[1];
d[2];
d[3];
In these sums, i, j, and k are local dummy parameters.
36
Expanding a Transportation Problem
The EXPAND statement also expands summations:
3
i=1
j=1 ij ij
3
j=1
ij
i
2
i=1
ij
j
xij  0 (i =1,2; j =1,2,3)
1
Origins
subject to
  cx
 x  s (i =1,2)
 x  d ( j =1,2,3)
2
1
2
2
3
Destinations
minimize
Minimize Cost=c11*x[1,1]+c12*x[1,2]+c13*x[1,3]+c21*x[2,1]+
c22*x[2,2]+c23*x[2,3]
Constraint s1: x[1,1]+x[1,2]+x[1,3] <= s1
Constraint s2: x[2,1]+x[2,2]+x[2,3] <= s2
Constraint d1: x[1,1]+x[2,1] >= d1
Constraint d2: x[1,2]+x[2,2] >= d2
Constraint d3: x[1,3]+x[2,3] >= d3
37
Declaring Parameters in PROC OPTMODEL
Parameters (other than local dummy parameters) must
be declared in PROC OPTMODEL before they are used.
 number or num declares numeric parameters
num n;
num pi = constant('pi');
num M{1..n,1..n};
38
Declaring Parameters in PROC OPTMODEL
Parameters (other than local dummy parameters) must
be declared in PROC OPTMODEL before they are used.
 number or num declares numeric parameters:
num n;
num pi = constant('pi');
num M{1..n,1..n};

string or str declares character-valued parameters:
str name;
str wkday{1..5}=[Mon Tue Wed Thu Fri];
39
Declaring Parameters in PROC OPTMODEL
Parameters (other than local dummy parameters) must
be declared in PROC OPTMODEL before they are used.
 number or num declares numeric parameters.


string or str declares character-valued parameters.
set <number> or set <num> declares a set of
numbers.

set <string> or set <str> declares a set of
strings.

set <type-1,…,type-n> declares a set of n-tuples
(types can be number (num) or string (str)).
set <num> Sixties = 1960..1969;
set <str> Cities = /Cary 'New York'/;
set <str,num> Parts = /<R 1> <C 2>/;
40
Declaring Parameters in PROC OPTMODEL
Parameters (other than local dummy parameters) must
be declared in PROC OPTMODEL before they are used.
 number or num declares numeric parameters.


string or str declares character-valued parameters.
set <number> or set <num> declares a set of
numbers.

set <string> or set <str> declares a set of
strings.

set <type-1,…,type-n> declares a set of n-tuples
(types can be number (num) or string (str)).
set Sixties = 1960..1969;
set Cities = /Cary 'New York'/;
set Parts = /<R 1> <C 2>/;
41
Using Arrays in PROC
OPTMODEL to Solve the
Furniture-Making Problem
furniture_arrays.sas
This demonstration illustrates the use of arrays
and matrices in PROC OPTMODEL to solve a
linear programming problem.
42
Array Indexing versus Index Sets
The indices used in
arrays and matrices
often correspond to
index sets that are
more meaningful
than 1,2,…,n:
Array Indexing
num A{1..3,1..4} = [2 1 3 2
1 1 1 1
3 3 4 4];
num s{1..4} = [52 44 70 61];
num c{1..3} = [7 10 5];
num b{1..3} = [225 117 420];
versus Mnemonic Index Sets
set Products = /desks chairs bookcases bedframes/;
set Resources = /labor metal wood/;
43
num A{Resources,Products} = [2 1 3 2
1 1 1 1
3 3 4 4];
num s{Products} = [52 44 70 61];
num c{Resources} = [7 10 5];
num b{Resources} = [225 117 420];
Array Indexing versus Index Sets
The indices used in
arrays and matrices
often correspond to
index sets that are
more meaningful
than 1,2,…,n:
Array Indexing
num A{1..3,1..4} = [2 1 3 2
1 1 1 1
3 3 4 4];
num s{1..4} = [52 44 70 61];
num c{1..3} = [7 10 5];
num b{1..3} = [225 117 420];
versus Mnemonic Index Sets (and Names)
set Products = /desks chairs bookcases bedframes/;
set Resources = /labor metal wood/;
44
num Requirements{Resources,Products} = [2 1 3 2
1 1 1 1
3 3 4 4];
num Selling_Price{Products} = [52 44 70 61];
num Cost{Resources} = [7 10 5];
num Availability{Resources} = [225 117 420];
The SUM Aggregation Operator
The SUM aggregation operator can be used with index
sets. This is the statement’s syntax:
SUM{ index-set } expression
If the index-set is a set of tuples, the dummy parameter
must match the number of terms in the tuple:
set Cities = /Cary 'New York'/;
num Total, Population{Cities};
Total = sum{c in Cities} Population[c];
set Parts = /<R 1> <C 2>/;
num Inv, Stock{Parts};
Inv = sum{<p,n> in Parts} Stock[p,n];
45
Using Index Sets in PROC
OPTMODEL to Solve the
Furniture-Making Problem
furniture_indices.sas
This demonstration illustrates the use of index
sets in PROC OPTMODEL to solve a linear
programming problem.
46
Exercise 3
This exercise reinforces the concepts discussed
previously.
47
Chapter 2: Linear Programming Problems:
Basic Ideas
2.1 Introduction to Linear Programming
2.2 Formulating and Solving Linear Programming
Problems Using the OPTMODEL Procedure
2.3 Reading Data from SAS Data Sets
2.4 Writing Output from the OPTMODEL Procedure
2.5 Dual Values, Reduced Costs, and Pricing in the
Simplex Method
48
Objectives

49
Read data from multiple SAS data sets to formulate
linear programming problems.
Reading Data from SAS Data Sets: Example
How can you read the height, weight, and age of students
into the arrays Height, Weight, and Age?
SAS Data Set: Opt.Class (just the first four columns)
Name
Height
Weight
Age
50
1
Alfred
69
112.5
14
2
Alice
56.5
84
13
3
Barbara
65.3
98
13
4
Carol
62.8
102.5
14
Reading Data from SAS Data Sets: Example
How can you read the height, weight, and age of students
into the arrays Height, Weight, and Age?
SAS Data Set: Opt.Class (just the first four rows)
Name
Height
Weight
Age
1
Alfred
69
112.5
14
2
Alice
56.5
84
13
3
Barbara
65.3
98
13
4
Carol
62.8
102.5
14
read data Opt.Class into Students=[Name]
Height Weight Age;
51
Reading Data from SAS Data Sets: Example
Can you read just the first four rows (observations)?
SAS Data Set: Opt.Class (just the first four rows)
Name
Height
Weight
Age
52
1
Alfred
69
112.5
14
2
Alice
56.5
84
13
3
Barbara
65.3
98
13
4
Carol
62.8
102.5
14
Reading Data from SAS Data Sets: Example
Can you read just the first four rows (observations)?
SAS Data Set: Opt.Class (just the first four rows)
Name
Height
Weight
Age
1
Alfred
69
112.5
14
2
Alice
56.5
84
13
3
Barbara
65.3
98
13
4
Carol
62.8
102.5
14
read data Opt.Class(obs=4) into
Students=[Name] Height Weight Age;
53
Furniture-Making Problem SAS Data Sets
data Resource_Data;
input Resource $ Cost Amount_Available;
datalines;
labor 7 225
metal 10 117
wood
5 420
run;
data Product_Data;
length Product $9;
input Product $ Selling_Price labor metal wood;
datalines;
desks
52 2 1 3
chairs
44 1 1 3
bookcases 70 3 1 4
bedframes 61 2 1 4
run;
54
Furniture-Making Problem SAS Data Sets
SAS Data Set: Work.Resource_Data
Resource Cost Amount_Available
1 labor
7
225
2 metal
10
117
3
wood
5
420
SAS Data Set: Work.Product_Data
Product Selling_Price labor metal wood
1 desks
52
2
1
3
2
3
4
55
chairs
bookcases
bedframes
44
70
61
1
3
2
1
1
1
3
4
4
Reading Data: The READ Statement
READ DATA SAS-data-set [ NOMISS ] INTO
[set-name=] [ read-key-column(s) ] [ read-column(s)] ;





56
SAS-data-set specifies the input data set.
read-key-column(s) provide the index values for array
destinations.
The optional set-name saves index values as a set.
read-column(s) specify the data values to read and
destination locations.
The optional NOMISS keyword suppresses the
assignment of missing values.
Reading the Furniture-Making Data Sets
proc optmodel;
/* declare sets and parameters */
set <str> Products, Resources;
num Cost{Resources}, Availability{Resources};
num Selling_Price{Products};
num Requirements{Resources,Products};
read data Resource_Data into Resources=[Resource]
Cost Availability=Amount_Available;
read data Product_Data into Products=[Product]
Selling_Price {r in Resources}
<Requirements[r,Product]=col(r)>;
58
Reading the Furniture-Making Data Sets
proc optmodel;
/* declare sets and parameters */
set <str> Products, Resources;
num Cost{Resources}, Availability{Resources};
num Selling_Price{Products};
num Requirements{Resources,Products};
read data Resource_Data into Resources=[Resource]
Cost Availability=Amount_Available;
read data Product_Data into Products=[Product]
Selling_Price {r in Resources}
<Requirements[r,Product]=col(r)>;

59
Declare index-sets (with no initialization expression,
<str> is necessary because the default is <num>).
Reading the Furniture-Making Data Sets
proc optmodel;
/* declare sets and parameters */
set <str> Products, Resources;
num Cost{Resources}, Availability{Resources};
num Selling_Price{Products};
num Requirements{Resources,Products};
read data Resource_Data into Resources=[Resource]
Cost Availability=Amount_Available;
read data Product_Data into Products=[Product]
Selling_Price {r in Resources}
<Requirements[r,Product]=col(r)>;

60
Declare parameter arrays, which are indexed by the
(unpopulated) index-sets Products and Resources.
Reading the Furniture-Making Data Sets
set <str> Products, Resources;
num Cost{Resources}, Availability{Resources};
read data Resource_Data into Resources=[Resource]
Cost Availability=Amount_Available;
read-key-column
(SAS data set variable name)
data Resource_Data;
input Resource $ Cost Amount_Available;
datalines;
labor 7 225
metal 10 117
wood
5 420
run;
61
Reading the Furniture-Making Data Sets
set <str> Products, Resources;
num Cost{Resources}, Availability{Resources};
read data Resource_Data into Resources=[Resource]
Cost Availability=Amount_Available;
set-name
(OPTMODEL index-set)
data Resource_Data;
input Resource $ Cost Amount_Available;
datalines;
labor 7 225
metal 10 117
wood
5 420
run;
62
Reading the Furniture-Making Data Sets
set <str> Products, Resources;
num Cost{Resources}, Availability{Resources};
read data Resource_Data into Resources=[Resource]
Cost Availability=Amount_Available;
read-columns
(OPTMODEL array name [=SAS data set variable name] )
data Resource_Data;
input Resource $ Cost Amount_Available;
datalines;
labor 7 225
metal 10 117
wood
5 420
run;
63
Reading the Furniture-Making Data Sets
set <str> Products, Resources;
num Selling_Price{Products};
num Requirements{Resources,Products};
read data Product_Data into Products=[Product]
Selling_Price {r in Resources}
<Requirements[r,Product]=col(r)>;
read-key-column (SAS data set variable name)
64
data Product_Data;
length Product $9;
input Product $ Selling_Price labor metal wood;
datalines;
desks
52 2 1 3
chairs
44 1 1 3
bookcases 70 3 1 4
bedframes 61 2 1 4
run;
Reading the Furniture-Making Data Sets
set <str> Products, Resources;
num Selling_Price{Products};
num Requirements{Resources,Products};
read data Product_Data into Products=[Product]
Selling_Price {r in Resources}
<Requirements[r,Product]=col(r)>;
set-name (OPTMODEL index-set)
65
data Product_Data;
length Product $9;
input Product $ Selling_Price labor metal wood;
datalines;
desks
52 2 1 3
chairs
44 1 1 3
bookcases 70 3 1 4
bedframes 61 2 1 4
run;
Reading the Furniture-Making Data Sets
set <str> Products, Resources;
num Selling_Price{Products};
num Requirements{Resources,Products};
read data Product_Data into Products=[Product]
Selling_Price {r in Resources}
<Requirements[r,Product]=col(r)>;
read-column (OPTMODEL array name)
66
data Product_Data;
length Product $9;
input Product $ Selling_Price labor metal wood;
datalines;
desks
52 2 1 3
chairs
44 1 1 3
bookcases 70 3 1 4
bedframes 61 2 1 4
run;
Reading the Furniture-Making Data Sets
set <str> Products, Resources;
num Selling_Price{Products};
num Requirements{Resources,Products};
read data Product_Data into Products=[Product]
Selling_Price {r in Resources}
<Requirements[r,Product]=col(r)>;
iterated read-column (array destination=COL expression)
67
data Product_Data;
length Product $9;
input Product $ Selling_Price labor metal wood;
datalines;
desks
52 2 1 3
chairs
44 1 1 3
bookcases 70 3 1 4
bedframes 61 2 1 4
run;
Reading Data Sets in
PROC OPTMODEL for the
Furniture-Making Problem
furniture_read.sas
This demonstration reads data from SAS data
sets for the formulation of the furniture-making
problem using index sets in PROC OPTMODEL.
68
Reading Data with No Read-Key-Column
How can you read break point values into an array a?
data Break_Points;
input a @@;
datalines;
0 1 2 5 10 20
run;
read data SAS-DATA-SET into [ SET-NAME=]
[READ-KEY-COLUMNS] READ-COLUMN;
69
Reading Data with No Read-Key-Column
How can you read break point values into an array a?
data Break_Points;
input a @@;
datalines;
0 1 2 5 10 20
run;
read data Break_Points into [ SET-NAME=]
[READ-KEY-COLUMNS] READ-COLUMN;
70
Reading Data with No Read-Key-Column
How can you read break point values into an array a?
data Break_Points;
input a @@;
datalines;
0 1 2 5 10 20
run;
read data Break_Points into [ SET-NAME=]
[READ-KEY-COLUMNS] a;
71
Reading Data with No Read-Key-Column
data Break_Points;
input a @@;
datalines;
0 1 2 5 10 20
run;
SAS Data Set:
Work.Break_Points
How can you read break point values into an array a?
a
1
2
0
1
3
4
5
6
2
5
10
20
read data Break_Points into [ SET-NAME=]
[READ-KEY-COLUMNS] a;
72
Reading Data with No Read-Key-Column
data Break_Points;
input a @@;
datalines;
0 1 2 5 10 20
run;
SAS Data Set:
Work.Break_Points
How can you read break point values into an array a?
_N_
1
2
3
4
5
6
a
0
1
2
5
10
20
read data Break_Points into [ SET-NAME=]
[_N_] a;
73
Reading Data with No Read-Key-Column
data Break_Points;
input a @@;
datalines;
0 1 2 5 10 20
run;
Why would you
need the set name?
SAS Data Set:
Work.Break_Points
How can you read break point values into an array a?
_N_
1
2
3
4
5
6
a
0
1
2
5
10
20
read data Break_Points into [ SET-NAME=]
[_N_] a;
74
Reading Data with No Read-Key-Column
data Break_Points;
input a @@;
datalines;
0 1 2 5 10 20
run;
Why would you
need the set name?
SAS Data Set:
Work.Break_Points
How can you read break point values into an array a?
_N_
1
2
3
4
5
6
read data Break_Points into domain=
[_N_] a;
75
a
0
1
2
5
10
20
Reading Data with Read-Key-Columns
How can you read the starting inventory levels into the
matrix Start[p,n] indexed by Plant and Part_No?
SAS Data Set: Colorado.Inventory_by_Plant
Plant
Part_No
Init_Inventory
1
Denver
WD12X300
340
2
Denver
WD18X213
456
3
Boulder WD12X300
120
4
Boulder WD1X1097
1203
read data SAS-DATA-SET into [ SET-NAME=]
[READ-KEY-COLUMNS] READ-COLUMN;
76
Reading Data with Read-Key-Columns
How can you read the starting inventory levels into the
matrix Start[p,n] indexed by Plant and Part_No?
SAS Data Set: Colorado.Inventory_by_Plant
Plant
Part_No
Init_Inventory
1
Denver
WD12X300
340
2
Denver
WD18X213
456
3
Boulder WD12X300
120
4
Boulder WD1X1097
1203
read data Colorado.Inventory_by_Plant into
[READ-KEY-COLUMNS] READ-COLUMN;
77
Reading Data with Read-Key-Columns
How can you read the starting inventory levels into the
matrix Start[p,n] indexed by Plant and Part_No?
SAS Data Set: Colorado.Inventory_by_Plant
Plant
Part_No
Init_Inventory
1
Denver
WD12X300
340
2
Denver
WD18X213
456
3
Boulder WD12X300
120
4
Boulder WD1X1097
1203
read data Colorado.Inventory_by_Plant into
[Plant Part_No] READ-COLUMN;
78
Reading Data with Read-Key-Columns
How can you read the starting inventory levels into the
matrix Start[p,n] indexed by Plant and Part_No?
SAS Data Set: Colorado.Inventory_by_Plant
Plant
Part_No
Init_Inventory
1
Denver
WD12X300
340
2
Denver
WD18X213
456
3
Boulder WD12X300
120
4
Boulder WD1X1097
1203
read data Colorado.Inventory_by_Plant into
[Plant Part_No] Start=Init_Inventory;
79
Example: Oil Refinery Blending Problem
How much of each raw gasoline should be blended into
each aviation gasoline to maximize profit while meeting
limits on performance (PN) and vapor pressure (RVP)?
PN RVP
107
Alk
93
8
Cat
87
4
Str
108
80
5
21
Iso
Raw
Gasolines
A
PN ≥ 100
RVP ≤ 7
B
PN ≥ 91
RVP ≤ 7
Aviation
Gasolines
Reading Data Sets in
PROC OPTMODEL for the
Oil Refinery Blending
Problem
blending_partial.sas
This class participation exercise includes
the use of index sets and reading data from
SAS data sets in PROC OPTMODEL to solve
a linear programming problem.
81
Exercises 4–6
These exercises reinforce the concepts discussed
previously.
82
Chapter 2: Linear Programming Problems:
Basic Ideas
2.1 Introduction to Linear Programming
2.2 Formulating and Solving Linear Programming
Problems Using the OPTMODEL Procedure
2.3 Reading Data from SAS Data Sets
2.4 Writing Output from the OPTMODEL
Procedure
2.5 Dual Values, Reduced Costs, and Pricing in the
Simplex Method
83
Objectives


84
Interpret PROC OPTMODEL output and write
formatted output.
Write linear programming problems to Math
Programming System (MPS) format.
PROC OPTMODEL Output: Suffixes
85

Decision Variables
.init (initial value)
.lb (lower bound)
.ub (upper bound)
.sol (solution value)
.rc or .dual (reduced cost)

Objective Function
.sol (objective value)

Constraints
.body (body value)
.lb (lower bound)
.ub (upper bound)
.dual (dual value)
Writing Output: The CREATE Statement
The CREATE statement mimics the READ statement:
CREATE DATA SAS-data-set FROM
[ key-column(s) ] [ = key-set ] column(s) ;




86
SAS-data-set specifies the output data set.
key-column(s) specify data set variable names whose
values index array locations in column(s).
The optional key-set specifies a set of index values
for key-column(s).
column(s) specify data set variable names and
PROC OPTMODEL source data.
Writing Output from the Furniture-Making LP
create data Optimal_Solution from
[Product]=Products Solution_Value=x;
SAS Data Set: Work.Optimal_Solution
Product
88
Solution_Value
1
desks
0
2
chairs
48
3
bookcases
39
4
bedframes
30
Writing Output from the Furniture-Making LP
create data Optimal_Solution from
[Product]=Products Solution_Value=x;
SAS Data Set: Work.Optimal_Solution
Reminder:
Products is the
set of products
that can be made
(an index-set).
89
Product
Solution_Value
1
desks
0
2
chairs
48
3
bookcases
39
4
bedframes
30
Writing Output from the Furniture-Making LP
create data Optimal_Solution from
[Product]=Products Solution_Value=x;
SAS Data Set: Work.Optimal_Solution
Reminder:
x=x.sol is an
array that holds
the optimal
production levels.
90
Product
Solution_Value
1
desks
0
2
chairs
48
3
bookcases
39
4
bedframes
30
Writing Output from the Furniture-Making LP
create data Optimal_Solution from
[Product]=Products Solution_Value=x;
SAS Data Set: Work.Optimal_Solution
Product
The key-column
declares index
values and their
data set variables.
91
Solution_Value
1
desks
0
2
chairs
48
3
bookcases
39
4
bedframes
30
Writing Output from the Furniture-Making LP
create data Optimal_Solution from
[Product]=Products Solution_Value=x;
SAS Data Set: Work.Optimal_Solution
Product
The key-set
specifies a set of
index values for
the key-column(s).
92
Solution_Value
1
desks
0
2
chairs
48
3
bookcases
39
4
bedframes
30
Writing Output from the Furniture-Making LP
create data Optimal_Solution from
[Product]=Products Solution_Value=x;
SAS Data Set: Work.Optimal_Solution
Product
The column
specifies data
set variables and
OPTMODEL
source data.
93
Solution_Value
1
desks
0
2
chairs
48
3
bookcases
39
4
bedframes
30
Writing Output from the Furniture-Making LP
How could you write just the variables that occur (are
nonzero) in the optimal solution?
94
Writing Output from the Furniture-Making LP
How could you write just the variables that occur (are
nonzero) in the optimal solution? Two approaches:

Data set option where=
Optimal_Solution(where=(Solution_Value>0))
95
Writing Output from the Furniture-Making LP
How could you write just the variables that occur (are
nonzero) in the optimal solution? Two approaches:

Data set option where=
Optimal_Solution(where=(Solution_Value>0))

Restrict the key-set by a selection expression
[Product]={p in Products: x[p]>0}
96
Writing Output with Multiple Key Columns
How can we write only those transportation links that occur
in the optimal solution to a SAS data set
Shipping_Links?
create data Shipping_Links from
[Origin Destination]={i in Origins,
j in Destinations: x[i,j]>0} Amount=x;
create data
Shipping_Links(where=(Amount>0))
[Origin Destination] Amount=x;
97
Writing Output Using Dummy Parameters
Dummy parameters in the key-set can also be used
to specify the columns:
create data Excess(where=(Amount>0))
from [Supplier]={i in Origins}
Amount=(Supply[i]-Supply_Avail[i].body);
SAS Data Set: Work.Excess
Supplier
Amount
98
1
Atlanta
175
2
Los_Angeles
150
3
Bozeman
25
Writing Output Using Dummy Parameters
Dummy parameters in the key-set can also be used
to specify the columns:
create data Excess(where=(Amount>0))
from [Supplier]={i in Origins}
Amount=(Supply[i]-Supply_Avail[i].body);
SAS Data Set: Work.Excess
Supplier
Amount
Amount does
not need to
be declared.
99
1
Atlanta
175
2
Los_Angeles
150
3
Bozeman
25
Formatted Output Using the PRINT Statement
print 'Profit:'
(Profit.sol) DOLLAR.;
PROC OPTMODEL Output
Profit:
100
$1,827
Formatted Output Using the PRINT Statement
print 'Profit:'
(Profit.sol) DOLLAR.;
print 'Optimal Solution:';
print {p in Products: x[p]>0} x;
PROC OPTMODEL Output
Profit:
$1,827
Optimal Solution:
[1]
bedframes
bookcases
chairs
101
x
30
39
48
Formatted Output Using the PRINT Statement
print 'Resource Usage:';
print Usage.body Usage.ub;
PROC OPTMODEL Output
Resource Usage:
[1]
labor
metal
wood
102
Usage.
BODY
Usage.UB
225
117
420
225
117
420
Formatted Output Using the PUT Statement
The FILE statement selects the current output file for the
PUT statement (the default is the SAS log).
file print;
put / 'Products=' Products;
put 'Resources=' Resources;
file 'greeting.txt';
put 'hello, world';
closefile 'greeting.txt';
103
(The slash
outputs the
current line.)
Formatted Output Using the PUT Statement
The FILE statement selects the current output file for the
PUT statement (the default is the SAS log).
file print;
put / 'Products=' Products;
put 'Resources=' Resources;
file 'greeting.txt';
put 'hello, world';
closefile 'greeting.txt';
(The slash
outputs the
current line.)
PROC OPTMODEL Output
Products={'desks','chairs','bookcases','bedframes'}
Resources={'labor','metal','wood'}
104
Writing PROC OPTMODEL
Output for the FurnitureMaking Problem
furniture_output.sas
This demonstration illustrates the different
methods of writing output from PROC
OPTMODEL after solving a linear programming
problem.
105
Sparsity in Linear Programming Problems
Many practical linear programming problems are sparse:
most coefficients in the constraint matrix A are zero.
An LP with
Staircase
Structure
388 rows
466 columns
1,534 nonzeros
106
Writing Problems to MPS Format
The SAVE MPS statement saves the structure and
coefficients for an LP model into a SAS data set, which
can be used as input data for the OPTLP procedure.
A Supply
Chain
Problem
108,500 rows
1.7 million
columns
4.2 million
nonzeros
107
Writing an LP to
MPS Format Using
PROC OPTMODEL
transportation.sas
This demonstration illustrates writing a linear
programming model to the (industry standard)
MPS format, which preserves sparsity.
108
Exercises 7–9
These exercises reinforce the concepts discussed
previously.
109
Chapter 2: Linear Programming Problems:
Basic Ideas
2.1 Introduction to Linear Programming
2.2 Formulating and Solving Linear Programming
Problems Using the OPTMODEL Procedure
2.3 Reading Data from SAS Data Sets
2.4 Writing Output from the OPTMODEL Procedure
2.5 Dual Values, Reduced Costs, and Pricing in
the Simplex Method
110
Objectives


111
Explain the interpretation of dual values in linear
programming.
Describe how dual values are used in the primal
simplex method and how pricing options influence
the behavior of the simplex method.
Interpretation of Dual Values

The dual value of a constraint is defined as
Change in optimal objective
Dual Value =
112
Unit increase in constraint RHS
Interpretation of Dual Values

The dual value of a constraint is defined as
Change in optimal objective
Dual Value =

113
Unit increase in constraint RHS
This assumes that the extreme point determining the
optimal solution is not over-determined:
Interpretation of Dual Values

The dual value of a constraint is defined as
Change in optimal objective
Dual Value =

This assumes that the extreme point determining the
optimal solution is not over-determined:
over-determined
(degenerate)
114
Unit increase in constraint RHS
y axis
Feasible Region
[63, 54]
optimal
solution
x axis
115
Feasible Region
dual value = 8.5
y axis
dual value = 0
[63, 54]
optimal
solution
x axis
116
dual value = 3.5
y axis
Feasible Region
[60.5, 56.5]
optimal
solution
x axis
117
y axis
Feasible Region
[58, 59]
optimal
solution
x axis
118
y axis
Feasible Region
[55.5, 61.5]
optimal
solution
x axis
119
y axis
Feasible Region
[70.5, 51.5]
optimal
solution
x axis
120
y axis
Feasible Region
[72, 51]
optimal
solution
x axis
121
Dual Values for the Furniture-Making Problem
The dual values can be written using the PRINT statement:
print Usage.dual;
122
Dual Values for the Furniture-Making Problem
The dual values can be written using the PRINT statement:
print Usage.dual;
PROC OPTMODEL Output
[1]
labor
metal
wood
123
Usage.
DUAL
2
1
3
Dual Values for the Furniture-Making Problem
The dual values can be written using the PRINT statement:
print Usage.dual;
If additional overtime
hours are available for
$10.50 (time-and-a-half),
would they be used?
124
PROC OPTMODEL Output
[1]
labor
metal
wood
Usage.
DUAL
2
1
3
Dual Values for the Furniture-Making Problem
The dual values can be written using the PRINT statement:
print Usage.dual;
If additional overtime
hours are available for
$10.50 (time-and-a-half),
would they be used?
PROC OPTMODEL Output
[1]
labor
metal
wood
Usage.
DUAL
2
1
3
No. For an additional hour at $7, the objective increases by
at most $2; for overtime the cost is $10.50=$7+$3.50.
125
Making Tables: Pricing an Activity
Tables require 3 hours of labor, 1 pound of metal, and
2 ft3 wood. Tables sell for $55. Should any be produced?
Profit for a table:
$55-3($7)-1($10)-2($5) = $14
126
Making Tables: Pricing an Activity
Tables require 3 hours of labor, 1 pound of metal, and
2 ft3 wood. Tables sell for $55. Should any be produced?
Profit for a table:
$55-3($7)-1($10)-2($5) = $14
Cost of reduced availability:
3($2)+1($1)+2($3) = $13
127
Making Tables: Pricing an Activity
Tables require 3 hours of labor, 1 pound of metal, and
2 ft3 wood. Tables sell for $55. Should any be produced?
Profit for a table:
$55-3($7)-1($10)-2($5) = $14
Cost of reduced availability:
3($2)+1($1)+2($3) = $13
$14-$13=$1 is the unit gain of making tables.
128
Making Tables: Pricing an Activity
Tables require 3 hours of labor, 1 pound of metal, and
2 ft3 wood. Tables sell for $55. Should any be produced?
Profit for a table:
$55-3($7)-1($10)-2($5) = $14
Cost of reduced availability:
3($2)+1($1)+2($3) = $13
The difference is called the
reduced cost.
$14-$13=$1 is the unit gain of making tables.
129
Pricing in the Primal and Dual Simplex
Methods
SOLVE WITH LP / PRICETYPE = option ;
Option
Description
FULL
Most negative* reduced cost
PARTIAL
Maintain a candidate queue (of length
QUEUESIZE=k)
STEEPESTEDGE Steepest edge pricing strategy (dual
simplex default)
DEVEX
Approximate steepest edge
HYBRID
130
Hybrid of DEVEX and STEEPESTEDGE
(primal simplex default)
Solving the McDonald’s
Diet Problem Using
PROC OPTMODEL
mcdonalds.sas
This demonstration introduces the linear
programming problem on which the following
exercise is based.
131
Exercises 10–12
These exercises reinforce the concepts discussed
previously.
132
Download