labinfo (1fuiu

35
Linköpings Tekniska Högskola 2009–09–01 Matematiska institutionen/Optimeringslära Oleg Burdakov Computer exercises for course TAOP23 Optimization Contents 1 General information 2 2 Computer exercise 1: Modelling and solving LP-problems 3 2.1 Preparations ................................... 3 2.2 Part 1: The simplex method in tableau form .................. 3 2.3 Assignments for Part 1 .............................. 4 2.4 Part 2: Modelling and solving LP-problems with standard software ..... 6 2.5 Model 1 ...................................... 6 2.6 Model 2 ...................................... 7 2.7 Model 3 - Diet problem on the Internet ..................... 8 3 Computer exercise 2: Nonlinear optimization 9 3.1 Part A – Solving NLP problems with standard software ........... 9 3.2 Part B – Unconstrained optimization ...................... 11 4 Computer exercise 3: Solution of a structured mixed integer problem 15 4.1 The problem ................................... 15 4.2 Preparations ................................... 15 4.3 Assignments .................................... 16 4.4 Results ....................................... 17 5 Information about Matlab-Simplex 19 6 Information about GLPK/glpsol 21 7 The GMPL/AMPL modelling language 24 7.1 Examples ..................................... 24 7.2 Syntax ....................................... 25 8 Information about AMPL 28 1

Upload: michael-taylor

Post on 24-Oct-2015

25 views

Category:

Documents


3 download

DESCRIPTION

uiigi

TRANSCRIPT

Page 1: labinfo (1fuiu

Linköpings Tekniska Högskola 2009–09–01Matematiska institutionen/OptimeringsläraOleg Burdakov

Computer exercises for course TAOP23 Optimization

Contents

1 General information 2

2 Computer exercise 1: Modelling and solving LP-problems 3

2.1 Preparations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

2.2 Part 1: The simplex method in tableau form . . . . . . . . . . . . . . . . . . 3

2.3 Assignments for Part 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

2.4 Part 2: Modelling and solving LP-problems with standard software . . . . . 6

2.5 Model 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

2.6 Model 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

2.7 Model 3 - Diet problem on the Internet . . . . . . . . . . . . . . . . . . . . . 8

3 Computer exercise 2: Nonlinear optimization 9

3.1 Part A – Solving NLP problems with standard software . . . . . . . . . . . 9

3.2 Part B – Unconstrained optimization . . . . . . . . . . . . . . . . . . . . . . 11

4 Computer exercise 3: Solution of a structured mixed integer problem 15

4.1 The problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

4.2 Preparations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

4.3 Assignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

4.4 Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

5 Information about Matlab-Simplex 19

6 Information about GLPK/glpsol 21

7 The GMPL/AMPL modelling language 24

7.1 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

7.2 Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

8 Information about AMPL 28

1

Page 2: labinfo (1fuiu

1 General information

The computer rooms are located in the B-house, 1tr, B-corridor, between entrances 21 and23. They are called Roxen, Glan, Hunn and Boren. Computers in these rooms can be usedalso beyond the scheduled time, provided that they are not occupied by other students.Please follow all the rules.

The available computers are Sun Ray workstations (thin clients connected to twoservers), running Solaris with CDE as a user interface. In order to be able to use theseworkstations, you need a personal account. It is obtained together with your personalemail address (@student.liu.se) if you are registered on this course (or another ISY/MAI-course/program). Your user name on MAI’s system is the same as your email identity.Initially your password is the same as on the student mail server.

After logging in, you can run the Unix commands in a terminal window. The very firstcommand that you must run in the terminal window is

TAOP23setup

It sets up paths for the course library. All programs that need this path must be startedfrom a terminal window where you run the setup command. Log out by using the EXITbutton in the CDE-panel.

In the framework of this course, three computer lab sessions (exercises) are scheduled.The exercises should be done in teams of (at most) two persons. At the end of eachcomputer session (or shortly after) each team should hand in their report sheet with allanswers filled in. One can find three report sheets at the very end of this document. Yourreport is regarded as passed only when all wrong answers are properly corrected.

The deadline for submitting your final corrections is October 9. It is recommendedthat you hand in your corrected reports far in advance before the deadline, because somefurther corrections may be required. Please don’t forget to check the status of your report(accepted or not).

2

Page 3: labinfo (1fuiu

2 Computer exercise 1: Modelling and solving LP-problems

The assignment in the first part is interactive solution of small LP-problems using a demon-stration code in matlab. The aim of the second part is to practice formulation and solutionof LP-problems and to get an acquaintance with useful and publicly available software. Thepreparations must be done before the scheduled lab time.

The software to be used are the demonstration code Matlab-Simplex for the firstpart, and the LP-solver GLPK and modelling language GMPL/AMPL for the second part.Sections 5-8 contains some documentation. Extra information about this software can befound on the course home page.

2.1 Preparations

1. Study the documentation for the software to be used.

2. Consider the expression for the reduced cost for the j-th non-basic variable, c̄j =cj − yT aj , so that you know how to use it. (y is the dual solution.)

3. For the first part, reduce all the problems to the standard form by introducing slackvariables.

4. Decide which of the variables are basic at the starting point in assignment 2 of section2.3.

5. Formulate the problems in the second part as LP-problems. The cargo plane problemcan be found at http://people.brunel.ac.uk/˜ mastjjb/jeb/or/lpmore.html.

2.2 Part 1: The simplex method in tableau form

In the first part, a couple of small LP-problems are to be solved with the simplex method.The purpose is to help you to understand better the linear programming and sensitivityanalysis, and to offer you a training on the simplex method. You will use Matlab-

Simplex, a code written in Matlab. The code helps creating simplex tableaus, but youmust specify the starting basis, as well as entering and leaving variables at each iteration.

First start Matlab. Then you need to make an input data file, with a text editor(such as Emacs) or with tools within Matlab.

3

Page 4: labinfo (1fuiu

2.3 Assignments for Part 1

1. Solve the problem

max z = 2x1 + 4x2 + 3x3

s.t. x1 + 3x2 + 2x3 ≤ 30x1 + x2 + x3 ≤ 24

3x1 + 5x2 + 3x3 ≤ 60x1, x2, x3 ≥ 0

Write the primal optimal solution: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Write the dual optimal solution: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Write the optimal objective function value: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Which of the variables are basic in the optimal solution? . . . . . . . . . . . . . . . . . . . . . . . . .

Calculate, by hand, the reduced cost for a new variable with objective function co-efficient 2 and constraint column (0 2 3)T . (Use the previously found dual solution.)Does the reduced cost indicate that the optimal solution will change if this variablewas introduced in the problem?

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Find the new optimal solution by inserting the new column in the tableau and re-optimizing. Start from the previous optimal basis. Compare with the answer givenabove. Write the optimal solution and the change in objective function value:

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

2. Solve the following problem. Mark every iteration point in figure 1. Start at thepoint where constraints 1 and 2 are active.Which variables are basic in that point? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

max z = 10x1 + 2x2

då x1 + x2 ≥ 3 (1)5x1 + 2x2 ≥ 10 (2)2x1 − x2 ≤ 10 (3)x1 + x2 ≤ 7 (4)

−x1 + 3x2 ≤ 9 (5)x1, x2 ≥ 0

The optimal z∗ and basic variables: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

The shadow price for constraint (4): . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4

Page 5: labinfo (1fuiu

−2 −1 0 1 2 3 4 5 6 7 8 9−2

−1

0

1

2

3

4

5

6

7

8

9

X1

X2

(1)

(2)

(3)

(4)(5)

Figure 1: Feasible set for problem 2

Change the right-hand-side of constraint (4) from 7 to 8 (the dashed line). Find thenew optimal solution. Does the optimal basis change? What is the actual changein the objective function value? (Compare with the change predicted by the shadowprice.)

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Change the right-hand-side of constraint (4) from 7 to 4. Find the new optimal so-lution. Does the optimal basis change? What is the actual change in the objectivefunction value? (Compare with the change predicted by the shadow price.)

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

How does the quality of the prediction (exact or not) depend on whether the optimalbasis changes or not with the change of b4?

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Find graphically the interval within which the right-hand-side in constraint (4) canchange without the optimal basis being changed.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

5

Page 6: labinfo (1fuiu

2.4 Part 2: Modelling and solving LP-problems with standard software

In this part, you should formulate LP-problems, write them in the modelling languageGMPL/AMPL and then solve them by the standard software GLPK with the stand-aloneprogram glpsol.

2.5 Model 1

The Swedish food company Sylt & Mos wants to plan its production during one week (40h)so that the profit is maximized. The company provides two jar sizes. A large jar contains1.5 kg of jam and costs 4 Skr per unit. A small jar contains 0.8 kg of jam and costs 2 Skrper unit. There are two different machines, one for filling the large jars and another onefor the small jars. The production rates of the machines are 350 and 650 jars per hourrespectively. During the fall season, the company produces jam out of blue berries andlingon berries. Both types of jam are sold in both types of jars. The selling prices and theavailable amount of berries are given by the table:

Product Price (large) Price (small) Supply (kg)

Blue berry 20 15 20000Lingon berry 21 13 25000

1. Formulate the problem as an LP-problem.

Variable definition:

Objective function:

Constraints:

2. Solve the problem using glpsol. What is the optimal solution and objective value?

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

6

Page 7: labinfo (1fuiu

3. Answer the following questions:

a) What is the optimal production? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

b) How large is the profit? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

c) Are all berries used? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

d) Are both machines fully used? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

e) If you had free access to more berries, which type would you prefer (lingon orblue berries)? Why?

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

2.6 Model 2

(See J.E. Beasley: OR-Notes, http://people.brunel.ac.uk/˜ mastjjb/jeb/or/lpmore.html.)A cargo plane has three compartments for storing cargo: front, centre and rear. Thesecompartments have the following limits on both weight and space:

Compartment Weight capacity (tonnes) Space capacity (cubic metres)

Front 10 6800Centre 16 8700Rear 8 5300

Furthermore, the weight of the cargo in the respective compartments must be the sameproportion of that compartment’s weight capacity to maintain the balance of the plane.

The following four cargoes are available for shipment on the next flight:

Cargo Weight (tonnes) Volume (cubic metres/tonne) Profit (£/tonne)

C1 18 480 310C2 15 650 380C3 23 580 350C4 12 390 285

Any proportion of these cargoes can be accepted. The objective is to determine howmuch (if any) of each cargo C1, C2, C3 and C4 should be accepted and how to distributeeach among the compartments so that the total profit for the flight is maximized.

1. Formulate the above problem as a linear program.

7

Page 8: labinfo (1fuiu

Variable definition:

Objective function:

Constraints:

2. Solve the optimization problem with glpsol. Give optimal solution and objectivefunction value:

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

2.7 Model 3 - Diet problem on the Internet

If you have time; point your Internet browser athttp://www-fp.mcs.anl.gov/otc/Guide/CaseStudies/diet/index.html.The diet problem is one of the earliest linear programming problems. The model allowsyou to satisfy your need of protein, vitamins etc. at the minimal cost, choosing betweendifferent meals.

8

Page 9: labinfo (1fuiu

3 Computer exercise 2: Nonlinear optimization

In the first part of the computer exercises on nonlinear optimization (NLP), a modelinglanguage and standard software is used to solve constrained optimization problems. Thesecond part concerns unconstrained optimization, and aims at giving an insight into thesteepest descent method and Newton’s method. The second part will be done with thehelp of MATLAB which is a self explanatory software. The both parts emphasize theimportance of convexity, and show that the lack of convexity may cause difficulties insolving problems.

3.1 Part A – Solving NLP problems with standard software

1. (Prepare) Study the software documentation.

2. Consider the following problem.

max f(x1, x2) = x1 − 8(x1 − 3)2 + 2x2 − 2(x2 − 3)2 + x1x2

s.t. x21

− x2 ≤ 02x1 − x2 ≥ 0

a) Solve the problem with AMPL. It is important that the run file specifies MINOSas the solver. Give the optimal solution and mark it in the figure 2.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

b) Give the optimal values of the dual variables (multipliers).

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

c) (Prepare partly) Illustrate graphically (in figure 2) that the KKT-conditionshold in the optimal point.

d) (Prepare partly) Check the convexity of the problem and determine if theobtained solution is a global maximum.

9

pratish
Text Box
x[1]=2, x[2]=4
pratish
Text Box
Dual Variables: v1=10.5, v2=-10.5 respectively
pratish
Text Box
Hessian Matrix of function f(x1,x2)= [-16 1; 1 -4] thus eigenvalues are (-63+-sqrt(63^2-80))/2 therefore both are negative thus function is strictly concave. For a Max problem with a concave function and convex set, the local maximum is global maximum. The set is convex because g1 & g2 are convex: Hessian of g1 is [1 0; 0 0] thus eigenvalue is positive {0,1} giving semi definite Positive Convex set. The second constraint g2 is linear.
Page 10: labinfo (1fuiu

−1 0 1 2 3 4−1

0

1

2

3

4

5

6Uppgift 2

X1

X2

(1)

(2)

Figure 2: Assignment 2

3. Consider the problem

min f(x1, x2) = x1

då (x1 − 1)2 + (x2 + 2)2 ≤ 16x2

1+ x2

2≥ 13

a) (Prepare) Draw below the feasible set and find graphically all KKT points,local and global minima.

10

Page 11: labinfo (1fuiu

b) Solve the problem with AMPL. Start in the points (0,4), (4,0), (-4,4) and atleast two points of your own choice. (It is OK to start from infeasible points.)Which solutions are obtained? (z∗ and x∗)

(0,4): . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

(4,0): . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

(-4,4): . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

c) Can you be sure that any of the obtained points is a global minimum withoutusing the figure?

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3.2 Part B – Unconstrained optimization

In this part we study methods for unconstrained optimization problems with the help of ademonstration program in MATLAB.

Start by opening a terminal window. Then give the commands TAOP23setup andmatlab in the terminal window. When the MATLAB window is opened, give ilpmeny.The functions to study are already coded in the program, and you only need to choosefunction, solution method and give starting point. “BL” means steepest descent (Brantastelutningsmetoden in Swedish) and “Newton” is a modification of Newton’s method with aline search. All functions in Part B are to be minimized.

1. Consider function 1

f(x1, x2) = 2(x1 + 1)2 + 8(x2 + 3)2 + 5x1 + x2

a) Solve with BL (at least 200 iterations) and Newton. Start in the points (10, 10)and (−5,−5), as well as a point of your own choice. Towards which point(s) dothe methods converge?

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

b) Is the obtained point a global minimum? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

c) What is the type of problems, for which the Newton method always convergesto the minimum in one iteration (for any starting point)?

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

11

pratish
Text Box
x*={-3,-2} ::: z*=-3 x*={3.605,0} ::: z*=3.605 x*={-3,-2} ::: z*=-3 x*={-3,-2} ::: z*=-3 x*={3.4,1.1} ::: z*=3.4
pratish
Text Box
No, we cannot be sure about obtained points being global the minimum because the set is non-convex. The points in the line between any two KKT points is infeasible
pratish
Text Box
x*={x1,x2}={-2.25,-3.06}
pratish
Text Box
Yes, the obtained point is the global minimum. Function is Convex.
Page 12: labinfo (1fuiu

2. Consider function 2 (Rosenbrock’s function)

f(x1, x2) = 100(x2 − x2

1)2 + (1 − x1)

2

a) Solve with BL (at least 200 iterations) and Newton. Start in the point (−1.5,−1).Towards which point(s) do the methods converge?

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

b) Is the function convex? Is the obtained point a global optimum?

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

c) Try some starting points of your own.

3. Consider function 3

f(x1, x2) = −5e−x21+x

22

10 +4e−x21+x

22

100 −5e−(x1−5)2+(x2+4)2

20 −5e−(x1+4)2+(x2−5)2

30 −4e−(x1+4)2+(x2−5)2

300

a) Solve with BL and start in the points (-20,20), (20,20), (20,-20) and (10,5).Towards which point(s) does the method converge?

(-20,20): . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

(20,20): . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

(20,-20): . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

(10,5): . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

b) Solve with Newton using the same starting points. Explain why this methoddoes not work.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

c) (Prepare) Study Marquart’s modification of Newton’s method.

d) Solve with Newton-Marquardt using the same starting points.Towards which point(s) does the method converge?

(-20,20): . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

(20,20): . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

(20,-20): . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

(10,5): . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

12

pratish
Text Box
Converging towards {1.0002,1.0003} , BL doesn't converge in 200 iterations
pratish
Text Box
Function is neither convex nor concave. Clear from the figure and also Hessian calculation.
pratish
Text Box
Converges towards {-4.52, 5.68} Converges towards {-4.52, 5.68} Converges towards {5.06,-3.9} Converges towards { -4.52,5.68}
pratish
Text Box
Newton method does not work using the same starting points because the function is concave around the starting points hence giving an ascent direction. Therefore in the software the 'line search' is 0 because it is already locally in the minimum.
pratish
Text Box
Converges towards {-4.52, 5.68} Converges towards {-4.54, 5.65} Converges towards {5.07,-3.99} Converges towards {-4.52, 5.67}
Page 13: labinfo (1fuiu

4. Consider function 4

f(x1, x2) = x3

1 + 2x3

2 − 27x1 − 6x2

a) (Prepare) Calculate the gradient and the Hessian of the function. Find allstationary points and specify the type (local/global min/max, saddle point) ofeach of them.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

b) Start in the point (0,0) and solve with BL, Newton and Newton Marquardt.

Explain why Newton does not work. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

c) Identify in the displayed graph the stationary points found in a).

5. Consider the other functions in the menu (if you have time).

Function 5: It is easy to end up in the “moat”.

Function 6: Watch out for the “foot hills”. Start in for example (-0.5 -0.4) with BL.

Function 7: Watch out for the the “pile of stones”.

13

Page 14: labinfo (1fuiu

14

Page 15: labinfo (1fuiu

4 Computer exercise 3: Solution of a structured mixed inte-

ger problem

The purpose of this assignment is to practice solving a structured mixed integer program-ming problem with a general standard modelling language, and give an insight into therelations between an integer problems and its LP-relaxation. It will also show how theLP-relaxation can be made tighter. We will use GLPK, and the modelling language GNUMath Prog (GMPL).

4.1 The problem

The task is to solve the capacitated facility location problem. Let m be the number ofpossible locations for the facilities, n the number of customers, dj the demand of customerj, si the capacity of a facility at location i, fi the fixed setup cost for opening a facility atlocation i, and cij the transportation cost per unit to customer j from a facility at locationi. All costs are assumed to be positive.

Variable definition:

yi =

{

1 if a facility is opened at location i

0 if notxij = transported amount from the facility at place i to customer j.

The problem of finding the solution with the least total cost can be modelled as follows.

v∗ = minm

i=1

n∑

j=1

cijxij +m

i=1

fiyi

s.t.n

j=1

xij ≤ siyi ∀i (1)

m∑

i=1

xij = dj ∀j (2)

xij ≥ 0 ∀i, j (3)yi ∈ {0, 1} ∀i (4)

[P1]

There are two main difficulties in solving this problem. One is the conflict betweenthe fixed costs and the transportation costs. A location with low fixed cost for openinga facility often has high transportation costs to the customers, and vice versa. The otherdifficulty comes from the integrality, i.e. that a facility is either closed or opened in full,even if only a small part of the capacity is needed. Relaxing the integrality requirementson y makes the problem easier to solve, but often produces unrealistic solutions, wherefractions of facilities are opened.

4.2 Preparations

1. Given m locations for facilities and n customers, what is the number of variables andconstraints in P1? Specify this for floc5 (see below).

2. Construct a GMPL model of P1 for the input file, based on the following definitions.

15

Page 16: labinfo (1fuiu

param n > 0;param m > 0;param s {1..m};param d {1..n};param f {1..m};param c {1..m, 1..n};

Add variable definition, objective function and constraints.

3. Consider question 3 in section 4.3. Find the number of constraints in P2, and comparewith P1. Specify this for floc5.

4.3 Assignments

Your task is to solve this mixed integer problem for five instances, named floc1 (3 x 5),floc2 (12 x 18), floc3 (10 x 25), floc4 (10 x 27) and floc5 (10 x 50), given in data files withthe names floc1.dat, floc2.dat etc.

Start by setting up the search paths by typing TAOP23setup. Problem data can be foundat the webpage http://www.mai.liu.se/∼kahol/kurser/all/, or copied by the command:cp $KURSBIB/floc* . (Observe the space and dot at the end.)

1. Use glpsol (or AMPL) to solve P1 for all instances, floc1 - floc5. Give optimalobjective function values (i.e. the minimal costs). Fill in the table in section 4.4.How many branch-and-bound nodes were generated for each instance?

2. Solve the LP-relaxation of the instances by simply removing the integer requirementin the model. (Do not remove the upper bound 1 on the y-variables.) The LP-relaxation gives a lower bound on v∗. What is the difference in total cost between theinteger optimum and the LP-relaxation? The most important information obtainedby solving the problem is where the facilities shall be located. Does the LP-relaxationgive this information? Study and write down the y-solutions.

3. For an integer problem it is desirable that the LP-relaxation yields a solution andobjective function value which is as close to the integer optimum as possible. Let P2be P1 with the following constraints added

xij ≤ uijyi ∀i, j

where uij = min(si, dj). These extra constraints provide a stronger LP-relaxation(i.e. values of y that are closer to 1 when they are not 0). Explain why the addedconstraints do not cut off any feasible solution.

4. Solve the LP-relaxation of P2 for all instances. Does this make the estimations andinformation better? Compare the y-solutions with the those in assignment 2.

5. Solve the integer problem P2 for all instances. Note the number of branch-and-boundnodes and compare with the results for P1.

16

Page 17: labinfo (1fuiu

4.4 Results

1. Number of variables of P1: . . . . . . . . . . . . . . . . . . . . . . . . Floc5: . . . . . . . . . . . . . . . . . . . . . . . .

Number of constraints of P1: . . . . . . . . . . . . . . . . . . . . . . .Floc5: . . . . . . . . . . . . . . . . . . . . . . .

Number of constraints of P2: . . . . . . . . . . . . . . . . . . . . . . .Floc5: . . . . . . . . . . . . . . . . . . . . . . .

2.

1 2 4 5

Problem Cost Nodes Cost Cost Nodes

floc1

floc2

floc3

floc4

floc5

3. Optimal y-solutions of the LP-relaxations:

Floc1/P1: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .P2: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Floc2/P1: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Floc2/P2: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Floc3/P1: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Floc3/P2: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Floc4/P1: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Floc4/P2: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Floc5/P1: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Floc5/P2: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

17

Page 18: labinfo (1fuiu

18

Page 19: labinfo (1fuiu

5 Information about Matlab-Simplex

Introduction

Matlab-Simplex is a code written in Matlab for interactive solution of small LP-problems. The code creates the simplex tableaus, but requires the user to give startingbasis and also entering and leaving variables at each iteration.

Problem input

The problem must be written in the form of a matlab file with suffix ’.m’, for instance,uppg1.m. You can use any text editor, for instance, emacs.

The following data must be defined in the matlab file:

• The vector c (row vector) containing the objective function coefficients.• The matrix A containing the constraint coefficients.• The vector b (column vector) containing the right-hand-sides.

The problem must be written in standard form for LP problems, i.e. all constraintsmust be equality constraints. Slack variables must already have been added. (Don’t forgetthat the slack variables appear in the objective function with coefficients equal to 0.)

Example:

max z = 3x1 + 7x2

då 4x1 + 5x2 + s1 = 72x1 − 3x2 + s2 = 1

x1, x2, s1, s2 ≥ 0

corresponds to the file

c = [ 3 7 0 0 ];A = [ 4 5 1 0

2 −3 0 1 ];b = [ 7

1 ];

The sizes of the vectors and the matrix must be consistent. Transposing a vector ormatrix is done in Matlab by writing a ’ after the last square bracket (for example b = [7 1]′

is a column vector).

19

Page 20: labinfo (1fuiu

Start Matlab-Simplex

First open a terminal window and set the search paths with the command TAOP23setup.Matlab is started by the command matlab in that terminal window. (With matlab -nojvm

you can avoid all extra Matlab’s windows.) Start the simplex routine with the commandsimplexmeny in the Matlab window. (If you start Matlab another way, the paths willnot be set, and you will not find the simplex code.)

Open/save file and pivoting

Load the problem with Open (skip the suffix ’.m’ in the file name). Choose a starting

basis with Give basis . Give the indices of the basic variables, separated by spaces or

commas. The problem is solved by using Pivot repeatedly, until the optimum is found

(and verified). The command Save saves the problem and current basis.

Adding a variable

A new variable (column) can be added by using New column . You must then giveobjective function coefficient, followed by all constraint coefficients for the new variable.

Adding a constraint

A new constraint requires a new row and often a new slack variable (column). If needed,we recommend to add the new column first.Add the new row with New row . You must then give the coefficients for all variables,followed by the right-hand-side.Note that after adding a row, a basis contains more basic variables, so give the new basiswith Give basis . (Often the previous basic variables plus the new slack variable yields abasic feasible solution.)

Changes of the coefficients in A, b or c

Changes in the problem data can either be done by changing in the problem file andloading it again, or directly in the program, with Change data . (In the latter case, the

input file is unchanged, unless you do Save .)

Figure 3: Matlab-Simplex

20

Page 21: labinfo (1fuiu

6 Information about GLPK/glpsol

Introduction to GLPK

The GLPK (GNU Linear Programming Kit) package is intended for solving large-scalelinear programming (LP), mixed integer programming (MIP), and other related problems.GLPK supports the GNU MathProg language (GMPL), which is a subset of the AMPLlanguage.

The GLPK package includes the following main components:* Revised simplex method.* Primal-dual interior point method.* Branch-and-bound method.* Translator for GNU MathProg.* Application program interface (API).* Stand-alone LP/MIP solver, glpsol.

The main idea of glpsol and the GNU MathProg language is to enable easier modellingof optimization problems. The model is written on a file, together with data for theproblem, and, possibly, other commands concerning the solution method and the outputof the solution.

Solving models with the use of glpsol

The GLPK package includes the program glpsol which is a stand-alone LP/MIP solver.This program can be invoked from the command line to solve models written in the GNUMathProg modeling language. The following switches can be used.

-m filename Read model section and optional data section from filename.-d filename Read data section from filename.-o filename Write solution to filename in plain text format.- -bounds filename Write sensitivity bounds to filename.- -wtxt filename Write problem to filename in plain text format.- -log filename Write copy of screen output to filename.- -nomip Consider all integer variables as continuous.- -intopt Use advanced MIP solver.- -cuts Generate cuts (assumes - -intopt).- -help This information (and more).

More information can be found in the last chapter of the complete GLPK manual.

21

Page 22: labinfo (1fuiu

Examples:

Read model file foobar.mod (containing data), solve it and write the solution to filefoobar.sol:

glpsol -m foobar.mod -o foobar.sol

Read model file foobar.mod, data file foobar.dat, solve the problem, write the solutionto file foobar.sol and write the whole model to file foobar.txt:

glpsol -m foobar.mod -d foobar.dat -o foobar.sol --wtxt foobar.txt

Read model file foobar.mod (containing data), solve it and write sensitivity bounds to filefoobar.bnd:

glpsol -m foobar.mod --bounds foobar.bnd

A small example

max z = 5x1 + 6x2 + 2x3 + 4x4

s.t. 3x1 + 2x2 + x3 + 5x4 ≤ 802x1 + x2 + 2x3 + 4x4 ≤ 453x1 − 3x2 + 4x3 + 5x4 ≥ 80x1 , x2 , x3 , x4 ≥ 0

File mymodel1.mod:

var x {1..4} >=0; # Variable definition

maximize z: 5*x[1] + 6*x[2] + 2*x[3] + 4*x[4]; # Objective function

subject to con1: 3*x[1] + 2*x[2] + x[3] + 5*x[4] <= 80; # Constraint 1

subject to con2: 2*x[1] + x[2] + 2*x[3] + 4*x[4] <= 45; # Constraint 2

subject to con3: 3*x[1] - 3*x[2] + 4*x[3] + 5*x[4] >= 80; # Constraint 3

end;

The following output appears on the screen, when solving the problem.

> glpsol -m mymodel1.mod -o mysol1.txt

Reading model section from mymodel1.mod...

7 lines were read

Generating z...

Generating con1...

Generating con2...

Generating con3...

Model has been successfully generated

lpx_simplex: original LP has 4 rows, 4 columns, 16 non-zeros

lpx_simplex: presolved LP has 3 rows, 4 columns, 12 non-zeros

lpx_adv_basis: size of triangular part = 3

0: objval = 0.000000000e+00 infeas = 1.000000000e+00 (0)

2: objval = 7.500000000e+01 infeas = 0.000000000e+00 (0)

OPTIMAL SOLUTION FOUND

Time used: 0.0 secs

Memory used: 0.2M

lpx_print_sol: writing LP problem solution to ‘mysol1.txt’...

22

Page 23: labinfo (1fuiu

Afterwards, the file mysol1.txt will contain the following.

Problem: mymodel1

Rows: 4

Columns: 4

Non-zeros: 16

Status: OPTIMAL

Objective: z = 75 (MAXimum)

No. Row name St Activity Lower bound Upper bound Marginal

------ ------------ -- ------------- ------------- ------------- -------------

1 z B 75

2 con1 B 42.5 80

3 con2 NU 45 45 7

4 con3 NL 80 80 -3

No. Column name St Activity Lower bound Upper bound Marginal

------ ------------ -- ------------- ------------- ------------- -------------

1 x[4] NL 0 0 -9

2 x[3] B 12.5 0

3 x[2] NL 0 0 -10

4 x[1] B 10 0

Karush-Kuhn-Tucker optimality conditions:

KKT.PE: max.abs.err. = 1.24e-14 on row 4

max.rel.err. = 1.54e-16 on row 4

High quality

KKT.PB: max.abs.err. = 0.00e+00 on row 0

max.rel.err. = 0.00e+00 on row 0

High quality

KKT.DE: max.abs.err. = 1.33e-15 on column 3

max.rel.err. = 7.84e-17 on column 3

High quality

KKT.DB: max.abs.err. = 0.00e+00 on row 0

max.rel.err. = 0.00e+00 on row 0

High quality

End of output

Here we see that x1 and x3 are basic variables at the optimum, and that the solutionis x1 = 10, x2 = 0, x3 = 12.5, x4 = 0, with the objective function value equal to 75. Theshadow prices are 0, 7 and -3 for the three constraints.

23

Page 24: labinfo (1fuiu

7 The GMPL/AMPL modelling language

Here we describe briefly the GNU Math Prog modelling language, GMPL, for optimizationmodels used by the GLPK (GNU Linear Programming Kit) and AMPL. There are somesmall differences between GMPL and AMPL, but for our purposes they can be regarded asidentical. Our description covers only the basics, which are the same, so that the model anddata files can be used by either program (and by others conforming to the same standard).

7.1 Examples

A small example

Let us start with a small LP-problem where data and model are combined.

max z = 5x1 + 6x2 + 2x3 + 4x4

s.t. 3x1 + 2x2 + x3 + 5x4 ≤ 802x1 + x2 + 2x3 + 4x4 ≤ 453x1 − 3x2 + 4x3 + 5x4 ≥ 80x1 , x2 , x3 , x4 ≥ 0

The model file (also containing the data) is as follows.

var x {1..4} >=0; # Variable definition

maximize z: 5*x[1] + 6*x[2] + 2*x[3] + 4*x[4]; # Objective function

subject to con1: 3*x[1] + 2*x[2] + x[3] + 5*x[4] <= 80; # Constraint 1

subject to con2: 2*x[1] + x[2] + 2*x[3] + 4*x[4] <= 45; # Constraint 2

subject to con3: 3*x[1] - 3*x[2] + 4*x[3] + 5*x[4] >= 80; # Constraint 3

end;

The constraints must have different names (con1, con2 etc.) and comments are givenafter # (the rest of the row is ignored).

Using summations

Below we describe how to solve the same problem, expressed with sums as follows.

max z =N

j=1

cjxj

s.t.N

j=1

aijxj ≤ bi i = 1, .., M

xj ≥ 0 j = 1, .., N

The use of summations in the model file allows us to formulate the following model withoutspecifying the actual values of the coefficients, which are given in a separate data file.

param N; # Number of variables

param M; # Number of constraints

param c{1..N}; # Definition of objective function coefficients

param a{1..M,1..N}; # Definition of constraint matrix

24

Page 25: labinfo (1fuiu

param b{1..M}; # Definition of right-hand-sides

var x{1..N} >= 0; # Variable definition

maximize z: sum {j in 1..N} c[j]*x[j];

subject to con {i in 1..M} : sum {j in 1..N} a[i,j]*x[j] <= b[i];

end;

Here N, M, c, a and b are parameters. N is the number of variables and M is the numberof constraints. Then 1..N is the set of indices of all variables and 1..M the set of indicesof all constraints. sum {j in 1..N} is thus a sum over all j in the set of indices of allvariables. The parameters c, a, b are the objective function coefficients, the constraintcoefficients and the right-hand-sides. var declares the variables.

Numerical data are given as follows. (The sign of the last constraint is changed, inorder to yield the same inequalities in all constraints.)

param N := 4;

param M := 3;

param : c :=

1 5

2 6

3 2

4 4;

param a : 1 2 3 4 :=

1 3 2 1 5

2 2 1 2 4

3 -3 3 -4 -5;

param : b := 1 80 2 45 3 -80;

end;

Here c and b are given in two different, but equivalent ways. Notice how the indices aregiven for c, a and b.

7.2 Syntax

Below we describe the most common commands in the modelling language. Each row musthave ; (semi colon) at the end.

param

Constants are declared with param. Specific values are assigned to parameters asfollows.

param N := 7;

param : vek := 1 50 2 75 3 100;

param : vek2 := 1 34 2 105 3 65 4 120;

param matr : 1 2 3 : =

1 80 9 77

2 11 120 13;

param mat2 {i in 1..3, j in 1..4} := min (vek[i],vek2[j]);

25

Page 26: labinfo (1fuiu

N sets to 7, the vector vek is assigned the values vek[1]=50, vek[2]=75 and vek[3]=100

and the matrix matr gets the values matr[1,1]=80, matr[1,2]=9, matr[1,3]=77,matr[2,1]=11 and so on. The matrix mat2 is created from the vectors vek and vek2

so that element (i, j) gets the least value of element i in vek and element j in vek2.

This results in mat2 =

34 50 50 5034 75 65 7534 100 65 100

.

set

Set declares a set of either numerical or symbolical values.

set CARS := SAAB VOLVO BMW;

set UddaNR := 1 3 5 7 9;

set VECKOR := 1..N;

var

Each variable must be declared.

var X; # A continuous variable named X

var Y binary; # A binary variable

var Q integer; # An integer variable

var X{1..8}; # Variable vector X[i], i=1..8

var X{1..8,1..20}; # Variable matrix X[i,j]

var Weigth{CARS}; # Variable vector Weigth[i], i element in set CARS

var Y{1..N}>=0; # Variable vector Y[i], Y[i]>=0, i=1..N

sum

Sum can be used in linear functions to sum over a set of variables.

sum{i in Cars} Weight[i] # Sum Weigth over all elements in set Cars

sum{i in 1..20} (x[i] - y[i]) # Sum x[i]-y[i] for i=1 to 20

sum {i in ORIG, j in DEST} z[i,j] # Sum over two indices

maximize / minimize

Specifies the objective function (which must be given a name). The name is followedby : (colon) and then the objective function.

maximize profit: sum{i in Units} c[i] * x[i];

subject to

Declares one or a set of constraints. The constraints must have different names. Thename is followed by : (colon) and then the constraint.

subject to constraint1: x + y = 7;

subject to storage{i in Products}:

produced[i] + left[i] - sold[i] <= storagecap[i];

subject to con3{i in N}:

sum{j in 1..i} x[j] >= d[i];

end

Here is a difference. GMPL requires end, while AMPL tolerates it.

26

Page 27: labinfo (1fuiu

Arithmetic operators:+ x unary plus- x unary minusx + y additionx - y subtractionx less y positive difference (if x < y then 0 else x − y)x * y multiplicationx / y divisionx div y quotient of exact divisionx mod y remainder of exact divisionx ** y, x ^ y x raised to the power y

where x and y are numerical expressions.

27

Page 28: labinfo (1fuiu

8 Information about AMPL

Introduction to AMPL

AMPL is a modelling language for formulating optimization models. It is very similarto GMPL, but can also handle nonlinear problems. Different optimization solvers, forlinear, integer or nonlinear problems, can be coupled to AMPL. (Details about AMPL canbe found in AMPL, A Modeling Language For Mathematical Programming by R. Fourer,D.M. Gay and B.W. Kernighan, The Scientific Press.)

In addition to the model file and the data file, it is convenient to use in AMPL a runfile, in which one can specify:

• the solver to be used;• name of the model file;• name of the data file;• name on the output file.

For nonlinear models, we use MINOS as a solver. Suppose that we wish to solve thefollowing nonlinear optimization problem.

min f(x) = 2x21+ x1x2 + 3x1 + 4x2

2

s.t. x1 + 2x22

≥ 3x1 + 3x2 = 5

The model file and the run file can look as follows.

nonlin.mod

var x{1..2};

minimize obj: 2*x[1]^2 + x[1]*x[2] + 3*x[1] + 4*x[2]^2;

s.t. con1: x[1] + 2*x[2]^2 >= 3;

con2: x[1] + 3*x[2] = 5;

data; # Starting point

var x :=

1 4

2 5;

nonlin.mod

At the end of the model file the starting point x1 = 4 and x2 = 5 is specified. (The firstdata column contains the indices.)

28

Page 29: labinfo (1fuiu

ILPproblem.run

option solver minos; # Use minos as solver

model nonlin.mod; # Model file (incl data)

solve;

display _objname, _obj; # Objective function value

display _varname, _var; # Variable values

display _conname, _con.slack, _con.dual;

# Slacks and dual variable values

ILPproblem.run

Run AMPL in a terminal window as follows.

ampl < ILPproblem.run

When the problem is solved, the following output is obtained.

obj = 11.1053;

x[1] -0.0526316

x[2] 1.68421;

slack dual

con1 2.6205 0

con2 -8.88178e-16 4.47368;

The solution is x1 = −0.0526316, x2 = 1.68421 with the objective function valueequal to 11.1053. The KKT- (Lagrange-) multipliers are 0 for constraint 1 and 4.47368 forconstraint 2. The slack in constraint 1 is 2.6205, and (practically) zero in constraint 2.

29

Page 30: labinfo (1fuiu

Report: Computer exercise 3 – Integer programming

Names: ......................................................... .........................................................

Group: ..........................

1. Number of variables of P1: . . . . . . . . . . . . . . . . . . . . . . . . Floc5: . . . . . . . . . . . . . . . . . . . . . . . .

Number of constraints of P1: . . . . . . . . . . . . . . . . . . . . . . .Floc5: . . . . . . . . . . . . . . . . . . . . . . .

Number of constraints of P2: . . . . . . . . . . . . . . . . . . . . . . .Floc5: . . . . . . . . . . . . . . . . . . . . . . .

2.

1 2 4 5

Problem Cost Nodes Cost Cost Nodes

floc1

floc2

floc3

floc4

floc5

3. Optimal y-solutions of the LP-relaxations:

Floc1/P1: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .P2: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Floc2/P1: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Floc2/P2: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Floc3/P1: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Floc3/P2: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Floc4/P1: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Floc4/P2: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Floc5/P1: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Floc5/P2: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

30

Page 31: labinfo (1fuiu

Report: Computer exercise 2 – Nonlinear optimization

Names: ......................................................... .........................................................

Group: ..........................

Part A

2a) Optimal solution: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

2b) Optimal multipliers: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

2d) Is the solution a global maximum? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3b) Solutions for: (0,4): . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

(4,0): . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

(-4,4): . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3c) Are you sure that any of the points is a global minimum? . . . . . . . . . . . . . . . . . . . . . . . . .

Part B

1a) Towards which point(s) do the methods converge? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1b) Is the obtained point a global minimum? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1c) What is the type of problems, for which the Newton method always converges to theminimum in one iteration (for any starting point)?

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

2a) Towards which point(s) do the methods converge? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

2b) Is the function convex? Is the obtained point a global optimum?

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

31

Page 32: labinfo (1fuiu

3a) Towards which point(s) does the steepest descent method converge?

(-20,20): . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

(20,20): . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

(20,-20): . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

(10,5): . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3b) Why does not Newton work? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3d) Towards which point(s) does the Newton-Marquard method converge?

(-20,20): . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

(20,20): . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

(20,-20): . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

(10,5): . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4a) Stationary points: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4b) Why does not Newton work? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

5) Comments? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

32

Page 33: labinfo (1fuiu

Report: Computer exercise 1 – LP

Names: .......................................................... ..........................................................

Group: ..........................

Part 1

1. Primal optimal solution: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Dual optimal solution: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Objective function value: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Basic variables: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Calculation of reduced cost and conclusion: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Actual change in objective function value: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

−2 −1 0 1 2 3 4 5 6 7 8 9−2

−1

0

1

2

3

4

5

6

7

8

9

X1

X2

(1)

(2)

(3)

(4)(5)

Figure 4: Mark every iteration point on this figure.

33

pratish
Text Box
Pratish Ray
pratish
Text Box
Rodgers Gambara
pratish
Text Box
B
pratish
Text Box
[x1 x2 x3]=[10 0 10]
pratish
Text Box
[x1 x2 x3]=[10 0 10]
pratish
Text Box
Dual optimal solution= {y4, y1, y3}={0.67, 1, 0.33} [y1 y2 y3]=[1 0 0.33]
pratish
Text Box
Objective function Value z*=50
pratish
Text Box
Basic Variables: {x3, x5, x1}
pratish
Text Box
New variable=> new optimum = YES.
pratish
Text Box
Optimal Solution => {x3,x7,x1}={14 ,4 ,2} Change in value =z*new-z*=4
Page 34: labinfo (1fuiu

2. Optimal solution: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Shadow price (dual variable) for constraint (4): . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Predicted and actual change when b4 changes from 7 to 8: . . . . . . . . . . . . . . . . . . . . . . . .

Predicted and actual change when b4 changes from 7 to 4? . . . . . . . . . . . . . . . . . . . . . . . .

How does the quality of the prediction (exact or not) depend on whether the optimalbasis changes or not with the change of b4?

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Interval for b4 with no change of the optimal basis: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Part 2:

Model 1

1. Formulation of the Sylt&Mos optimization problem.

Variable definition:

Objective function:

Constraints:

2. Optimal solution (z∗ and x∗): . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

34

pratish
Text Box
Optimal z*= 59.33 Basic: {x1, x4, x3, x2, x7}
pratish
Text Box
Shadow Price=4.67
pratish
Text Box
Change of b4 (RHS) from 7 to 8 Change of z=4.67 Exactly equal to the shadow price because change of RHS=1 and the optimal solution doesn't change
pratish
Text Box
Change of z= 19.33 : z_prediction shadow price=3*4.67=14 It is different from the predicted shadow price because the optimal solution changes.
pratish
Text Box
Quality remains exact if the optimal solution doesn't change. As long as the movement of constraint 4 doesn't create a degenerate point (on other side) the optimal solution is the same.
pratish
Text Box
RHS from 5 to 13.4. This is on calculation of points where (3) intersects the horizontal axis & where (3) intersects (5).(Considering strict equality) The points are (5,0) & (7.8,5.6).
pratish
Text Box
Each variable specifies a unit jar. There are 4 cross-combinations made by 'B'lueberries and 'L'ingonberries packed in 'S'mall & 'L'arge jars. So naming the respective variables as XBL (Blue Large), XBS (Blue Small), XLS (Lingon Small), XLL (Lingon Large)
pratish
Text Box
Profit z = Sum of (Selling price - Cost Price) Maximise profit : 13XBS + 16 XBL + 11 XLS + 17 XLL
pratish
Text Box
1)Limitation in supply of Blueberries : 1.5XBL + 0.8 XBS <= 20000; 2)Limitation in supply of Lingonberries : 1.5 XLL + 0.8 XLS <= 25000; 3)Limitation in production of Small Jars: XBL + XLL <=350 * 40; 4) Limitation in production of Large Jars: XBS + XLS <= 650*40;
pratish
Text Box
Objective Value z*=574000; Optimal Solution= {XBS,XLL,XLS} (Blueberry Small, Lingonberry both)
Page 35: labinfo (1fuiu

3. (a) Optimal production: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

(b) Profit: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

(c) Are all berries used? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

(d) Are both machines fully used? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

(e) I would prefer: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Model 2

1. Formulate the cargo plane problem as an LP-problem.

Variable definition:

Objective function:

Constraints:

2. Optimal solution (z∗ and x∗): . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

35

pratish
Text Box
XBS=25000 Kg, XLS= 1000 Kg, XLL= 14000
pratish
Text Box
Objective Value z*=574000;
pratish
Text Box
No, all blueberries are used but all lingonberries aren't.
pratish
Text Box
Both machines are fully used. There is also excessive Lingonberries left over and both machines have marginal values: 17 & 11 for small and large machine resp.
pratish
Text Box
Blueberries, because they are more cost effective and have a shadow price of 2.5 Beside, Lingonberries are left over.
pratish
Pencil
pratish
Pencil
pratish
Text Box
There are two dimensions to be considered: the type of Cargo and the place for storing the Cargo. Following is the table for variable definition Front Center Rear Cargo1 X1F X1C X1R Cargo2 X2F X2C X2R Cargo3 X3F X3C X3R Cargo4 X4F X4C X4R
pratish
Pencil
pratish
Text Box
Maximise Profit: z*= 310* ΣX1j + 380* ΣX2j + 350* ΣX3j + 285* ΣX4j where j=F,C R
pratish
Text Box
4 Constraints relating to Weight of Cargo types (supply): ΣX1j<=18; ΣX2j<=15; ΣX3j<=23; where we calculated sum of F, C & R e.g. X1F+X1R+X1C ΣX4j<=12; 3 Constraints relating to Wieght Capacity of Flight Cargo holds ΣXiF<=10; ΣXiC<=16; where we calculated sum of 1,2,3 & 4 e.g X1F+X2F+X3F+X4F ΣXiR<=8; 3 Constraints relating to Volume Capacity of Flight Cargo holds 480*X1F + 650*X2F + 580*X3F + 390*X4F <= 6800; 480*X1C + 650*X2C + 580*X3C + 390*X4C <= 8700; 480*X1R + 650*X2R + 580*X3R + 390*X4R <= 5300; Ratio balance weight: ΣXiC - 1.6* ΣXiF=0; ΣXiC - 2* ΣXiR=0;
pratish
Pencil
pratish
Text Box
Objective: z = 12151.57895
pratish
Text Box
Optimal Solution: {X2F,X3C,X4C,X2R,X3R} ={10,12.94, 3.05, 5, 3}