Anda di halaman 1dari 21

TP5027 Transport & Freight Terminal

M
Management t

Optimization Solvers

Dr. MENG Qiang


Office: E1-07-10
Tel: 6516 5494
E-mail: cvemq@nus.edu.sg

1
Learning Objectives & Reference
 Master two optimization software packages:
 Microsoft Excel Solver

 AMPL (A
( Mathematical
h i l Programming
i Language))

 References
 Fourer, R. D., Gay, D. and Kernighan (2003) AMPL, A Modeling
Language for Mathematical Programming, 2nd edition.
Brooks/Cole-Thomson.
 Handout for AMPL
 Handout for Excel Solver

2
Contents

 Introduction
oduc o too algorithms
go s solving
so v g LP,, N
NLP and
d IP
 Microsoft Excel Solver
 AMPL

3
Linear Programming Models – Algorithms
 Simplex Method (G. B. Dantzig, 1947)
– An iterative method
x2
– From one vertex to another one 5
2x1+x2=5
– Terminated in the limited iterations 4
D
 Example (1,3)
3 C
max f (x ) = 3x 1 + 2x 2 -x1+4x2=2
2
s.t.
B
x1 + x 2 ≤ 4 1 A x1+x2=4
2x 1 + x 2 ≤ 5 x1
−x 1 + 4x 2 ≥ 2 -2
2 -1
1 1 2 3 4 5
x 1, x 2 ≥ 0 3x1+2x2=2 3x1+2x2=4 3x1+2x2=9

4
Linear Programming Models – Algorithms (cont’d)
(cont d)

Principle behind the simplex method


– Check that if a vertex is an optimal solution
– If it is not, find another vertex which is adjacent to the current vertex

x2 feasible solution set - a polytope x2 feasible solution set - a polytope

x1 x1

 I t i point
Interior i t algorithm
l ith (Karmarkar,
(K k 1984)
N. Karmarkar. A new polynomial-time algorithm for linear programming. In
Proceedings of the Sixteenth Annual ACM Symposium on Theory of
Computing, pp. 302-311, Washington, D.C., 1984.
5
N li
Nonlinear Programming
P i Models
M d l – Optimal
O ti l Solutions
S l ti
 Global minimum of a NLP (minimization problems)
x* is a feasible solution in the set Ω and we have f(x*)≤f(x) for any x in the
set Ω
 Local minimum of a NLP (minimization problems)
x* is a feasible solution in the set Ω and we have f(x*)≤ f(x) for any x in
neighborhood
i hb h d off x* *
 Optimality conditions
─ Karush-Kuhn-Tucker (KKT) conditions
Kuhn, H. W. and Tucker, A. W. (1951) Nonlinear Programming. J. Neyman (ed.)
Proceedings of the Second Berkeley Symposium on Mathematical Statistics and
Probabilities. University of California, Berkeley, pp. 481-492.
Karush, W. (1939) Minima of Functions of Several Variables with Inequalities as
Side Conditions
Conditions, MSc
MS Th
Thesis,
i D Department
t t off M
Mathematics,
th ti University
U i it off Chicago,
Chi
Chicago.
6
Nonlinear Programming Models – Algorithms
 Gradient based algorithms
x2
min f (x ) = 3x 1 + 2x 2 Ω Set
Ω: S off ffeasible
ibl solutions
l i
4
s.t.
x1 + x 2 ≤ 4 Direction:∇f ( x ) = ( 3,
3 2)
(1)
3
2x 1 + x 2 ≤ 5 x(1)
2
−x 1 + 4x 2 ≥ 2
x 1, x 2 ≥ 0 1
Contour of the objective function d1
x1
 Idea behind an algorithm for a NLP 1 2 3 4
3x1+2x2=5 3x +2x =9
3x1+2x2=2 1 2
– Given a feasible solution x(1)= (0.5, 1.75),
gradient of the objective function: ∇f ( x (1) ) = ( 3,
3 2)
–Observation: the objective function value will decrease if we move along the
negative gradient direction at point x(1) from that point
x(2)= x(1)+α1d1 where α1 is the step size
7
Integer Programming Models - Algorithms
 Differences between solving a LP and an ILP
 Example 1. A LP problem x2 Optimum: x1=3.75,
x2=1.25, f=23.75
max f ( x ) = 5 x1 + 4 x2 5
s.t.
4
x1 + x2 ≤ 5
10 x1 + 6 x2 ≤ 45 3

x1 , x2 ≥ 0 2

 Example
E l 2.
2 An
A ILP problem
bl 1
x1
max f ( x ) = 5 x1 + 4 x2
0 1 2 3 4 5
s.t.
Optimum: x1=3,
x1 + x2 ≤ 5 x2=2, f = 23
10 x1 + 6 x2 ≤ 45 It seems that rounding off the optimal solution for
x1 , x2 ≥ 0 and integer Example 1 can yield the optimal solution for Example 2
8
Integer Programming Models – Algorithms (cont’d)
(cont d)

 Example
p 3. A LP Problem
max f ( x1 , x2 ) = x1 + x2
Optimum:
s.t.
x1*=4,
* 4 x2*=4.5
* 45
−2 x1 + 2 x2 ≥ 1
−8 x1 + 10 x2 ≤ 13 f(x1*,x2*)=8.5
x1 , x2 ≥ 0
 Example 4. An ILP Problem
max f ( x1 , x2 ) = x1 + x2
Optimum: It is necessary to
s.t.
x1*=1, x2*=2 develop dedicated
−2 x1 + 2 x2 ≥ 1
algorithms for IP
−8 x1 + 10 x2 ≤ 13 f(x1*,x2*)=3
x1 , x2 ≥ 0 and integer
9
Integer Programming Models – Algorithms (cont’d)
(cont d)

 Existing
s g algorithms
go s
 Cutting plane methods

− Solve any MIP problems


− have not been proved very successful on large-scale problems

 Enumerative methods

− Solve the class of 0-1 PIP problems


p
− have been proved very successful with certain types of problem
and not very successful on others
 Branch and bound methods
− Solve any MIP problems
− have proved most successful in general on practical MIP problems

10
O ti i ti Solvers
Optimization S l
 Software Packages
 CPLEX (http://www.ilog.com/products/cplex/)
 LINDO (http://www.lindo.com/)
p )
AMPL (http://www.ampl.com/)
 Add-in Solver in Microsoft Excel
(http://www.solver.com/)

 Optimization subroutines in programming languages

 IMSL numerical library for Fortran


(http://www absoft com/Products/Libraries/imsl html)
(http://www.absoft.com/Products/Libraries/imsl.html)

 Optimization tollbox in Matlab


(http://www.mathworks.com/access/helpdesk/help/toolbox/optim/optim.shtml)

11
Add-in Solver of Microsoft Excel
 Solver in Microsoft Excel
A powerful add-in tool in Microsoft Excel, which is of capability in solving
− Linear p
programming
g g models
− Nonlinear programming models
− Integer programming models

 How to use Solver?


 Install
I t ll Solver
S l
To activate the Excel Solver for the first time, select Tools and then select
Add-Ins
Add Ins. Checking the Solver Add-in
Add in box will cause Excel to open Solver
whenever you check tools and then Solver.
 Procedure to use Solver
Step 1: Set up a spreadsheet that tracks all the decision variables, objective
function and constraints 12
Add-in Solver of Microsoft Excel
Step 2.1: From the Tools menu, select Solver. The dialog box in Figure 1
will appear.
appear

Figure 1

Step 2.2: Move the mouse to the Set Target Cell portion of the dialog box and
click on the target cell (objective function) defined in Step 1 and select
min or max 13
Add-in Solver of Microsoft Excel (cont’d)
(cont d)
Step
p 2.3: Move the mouse to the By y Changing
g g Cells pportion of the dialog
g box
and click the changing cells (decision variables) defined in Step 1.

Step 2.4:
2 4: Click on the Add button to add constraints
constraints. The following screen will
appear. Move the Cell Reference part of the Add constraint dialog box
to add a constraint.

Step 2.5: Click on Options button in Figure 1 to configure parameters

S 22.6:
Step 6 Click
Cli k on the
h Solve
S l button
b off Figure
Fi 1
14
Add-in Solver of Microsoft Excel (cont’d)
(cont d)
 Three
ee Examples
p es

 Example 1. LP  Example 2. MIP

max z = 5 x1 + 4 x2 max z = 3 x1 + x2
subject to subject
bj t to
t
6 x1 + 4 x2 ≤ 24 17 x1 + 11x2 ≤ 86.5
− x1 + x2 ≤ 1 x1 + 2 x2 ≤ 10.2
10 2
x2 ≤ 2 x1 ≤ 3.87
x1 ≥ 0, x2 ≥ 0 x1 is a non-negative integer
x2 ≥ 0

15
Add-in Solver of Microsoft Excel (cont’d)
(cont d)
 Example 3. PIP  Example 4. NLP
6
min z =  xi min f ( x ) = 0.04 x1 + 0.1x2 + 0.07 x3
i =1
subject to
subject to x1 + x2 + x3 = 100
x1 + x2 ≥ 1 0.01x2 + 0.001x22 ≤ 0.5
x1 + x2 + x6 ≥ 1 0.35 x1 − 0.04 x2 − 0.002 x12 ≥ −1
x3 + x4 ≥ 1 0.1x1 + 0.06 x2 − 0.3 x3 + 0.01x1 x2 + 0.05 x22 + 0.001x32 ≥ −9
0.1x1 + 0.06 x2 − 0.3 x3 + 0.01x1 x2 + 0.05 x22 + 0.001x32 ≤ 1
x3 + x4 + x5 ≥ 1
x1 ≥ 25
x4 + x5 + x6 ≥ 1
x1 ≤ 60
x2 + x5 + x6 ≥ 1 x2 ≥ 0
xi = 0 or 1,
1 i = 1,
1 22,,66 x3 ≥ 50
16
AMPL - Introduction

 A modeling
ode g language
gu ge for
o mathematical
e c programming
p og g
 AMPL is notable for the similarity of its arithmetic expressions to
customary algebraic notation,
 AMPL is notable for the generality and power of its set and subscripting
expression.
 AMPL was designed and implemented by Fourer, R. (Northwestern
University), Gay, G., and Kernighghan, B. W. (Princeton University) around
1985.
 Editor
Edit
 Notepad
 Running environment
 DOS

17
AMPL – A Rudimentary Format

 Example
p e 1:: LP
 AMPL Code
max z ( x ) = 5 x1 + 4 x2
var x1 >=0;
0;
subject var x2 >=0;
6 x1 + 4 x2 ≤ 24 maximize z: 5*x1+4*x2;
subject to
x1 + 2 x2 ≤ 6 c1: 6*x1+4*x2<=24;
c2: x1+2*x2<=6;
− x1 + x2 ≤ 1
c3
3: -x1+x2<=1;
1+ 2< 1
x2 ≤ 2 c4: x2<=2;
solve;
x1 , x2 ≥ 0 display z,x1,x2;

18
#--------------------------------------------AMPL model
param m;
AMPL – An Algebraic param n;
Model param c{1..n};
{1 }
param b{1..m};

max z ( x ) = 5 x1 + 4 x2 param a{1..m,1..n};


p { , };
subject
var x{1..n}>=0;
6 x1 + 4 x2 ≤ 24
maximize
i i z: sum{j {j in
i 1..n}c[j]*x[j];
1 } [j]* [j]
x1 + 2 x2 ≤ 6 subject to restr{i in 1..m}:
sum{j in 1..n}a[i,j]*x[j]<=b[i];
− x1 + x2 ≤ 1 #------------------------------------------specify
p y model data
data;
param n:=2;
x2 ≤ 2 param m:=4;
param c:= 1 5 2 4; 4
x1 , x2 ≥ 0
param b:=1 24 2 6 3 1 4 2;
param a: 1 2 :=
1 6 4
2 1 2
3 -1 1
4 0 1;
#
#------------------------------------------solve
l e the problem
ble
solve;
display z, x; 19
param n;
set I={1..n};
AMPL – MIP set JJ={1
{1..n};
n}; #I is the same as J
param p{I};
min penalty = 19 s1+ + 12s2+ + 34 s3+ param d{I};
param perDayPenalty{I};
subject to param M=1000;
x1 − x2 + My12 ≥ 20 var x{J}>=0; #continuous
var y{I,J} binary; #0-1
− x1 + x2 + M (1 − y12 ) ≥ 5 var sMinus{J}>
sMinus{J}>=0;
0; # s=sMinus-sPlus
s sMinus sPlus
var sPlus{J}>=0;
x1 − x3 + My13 ≥ 15 minimize penalty: sum {j in J}
perDayPenalty[j]*sPlus[j];
− x1 + x3 + M (1 − y13 ) ≥ 5 subject to
ConstraintType1{i in I,j in J:i<j}:
x2 − x3 + My23 ≥ 15 M*y[i,j]+x[i]-x[j]>=p[j];
− x2 + x3 + M (1 − y23 ) ≥ 20 ConstraintType2{i in I,j
I j in J:i<j}:
M*(1-y[i,j])+x[j]-x[i]>=p[i];
dueDate{j in J}:x[j]+sMinus[j]-sPlus[j]=d[j]-p[j];
x1 + s1+ − s1− = 25 − 5
data;
x2 + s2− − s2+ = 22 − 20 param n:=3;
param p:= 1 5 2 20 3 15;
x3 + s3− − s3+ = 35 − 15 param d:= 1 25 2 22 3 35;
param perDayPenalty := : 1 19 2 12 3 34;
x1 , x2 , x3 , s1− , s1+ , s2− , s2+ , s3− , s3+ ≥ 0
option solver cplex; solve;
y12 , y13 , y23 ∈ {0,1} display penalty,x;
20
AMPL – NLP

max z ( x ) = x1 − x2 #
#------- Example -NLP
NLP
var x1>=0 :=10; #inital value = 10
subject to
var x2>=0 :=10; #initial value = 10
3 x14 + x2 ≤ 243
maximize z: x1-x2;
x1 + 2 x22 ≤ 32 subject to
x1 ≥ 2.1 c1:
1 3*x1^4+x2<=243;
3* 1^4+ 2< 243
c2: x1+2*x2^2<=32;
x2 ≥ 3.5 c3: x1>=2.1;
c4: x2>=3.5;
Remark:
solve;
An initial feasible solution display z,x1,x2;
should be provided by users

21

Anda mungkin juga menyukai