tomlab v2.0 user’s guide - · pdf filetomlab v2.0 user’s guide ......

188
TOMLAB v2.0 User’s Guide KennethHolmstr¨om Applied Optimization and Modeling Group (TOM) 1 Center for Mathematical Modeling Department of Mathematics and Physics M¨alardalenUniversity P.O. Box 883, SE-721 23 V¨ aster˚ as, Sweden Research Report in MATHEMATICS / APPLIED MATHEMATICS Technical Report IMa-TOM-2000-01 October 14, 2000 1 Information about TOMLAB available at the Applied Optimization and Modeling TOM home page URL: http://www.ima.mdh.se/tom. 1

Upload: lylien

Post on 04-Feb-2018

237 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

TOMLAB v2.0 User’s Guide

Kenneth Holmstrom

Applied Optimization and Modeling Group (TOM) 1

Center for Mathematical ModelingDepartment of Mathematics and Physics

Malardalen UniversityP.O. Box 883, SE-721 23 Vasteras, Sweden

Research Report in MATHEMATICS / APPLIED MATHEMATICSTechnical Report IMa-TOM-2000-01

October 14, 2000

1Information about TOMLAB available at the Applied Optimization and Modeling TOM home page URL:http://www.ima.mdh.se/tom.

1

Page 2: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Contents

1 The TOMLAB Optimization Environment 7

1.1 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

1.2 The Design of TOMLAB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

1.2.1 Global Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

1.3 Solver Routines in TOMLAB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

1.4 Menu Programs in TOMLAB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

1.5 Low Level Routines and Test Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

1.5.1 Utility Test Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34

1.6 The Graphical User Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34

1.6.1 The Advanced Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

2 Solving Linear, Quadratic and Integer Programming Problems 39

2.1 Linear Programming Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

2.1.1 A Quick Linear Programming Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

2.1.2 Several Linear Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41

2.1.3 Solving LP Similar to Optimization Toolbox 2.0 . . . . . . . . . . . . . . . . . . . . . . . . 42

2.1.4 Large Sets of Linear Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43

2.1.5 Editing Problems into an Existing Setup File - LP Example . . . . . . . . . . . . . . . . . 44

2.1.6 More on Solving Linear Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46

2.2 Quadratic Programming Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48

2.2.1 A Quick Quadratic Programming solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49

2.2.2 Several Quadratic Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50

2.2.3 Solving QP similar to Optimization Toolbox 2.0 . . . . . . . . . . . . . . . . . . . . . . . . 51

2.2.4 Large Sets of Quadratic Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52

2.2.5 Another Direct Approach to a QP Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . 53

2.2.6 Editing Problems into an Existing Setup File - QP Example . . . . . . . . . . . . . . . . . 54

2.2.7 More on Solving Quadratic Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55

2.3 Mixed-Integer Programming Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55

2.3.1 Large Sets of Mixed-Integer Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59

2.3.2 More on Solving Mixed-Integer Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59

2.4 Performance Tests on Linear Programming Solvers . . . . . . . . . . . . . . . . . . . . . . . . . . . 60

3 Solving Unconstrained, Constrained and Global optimization Problems 67

3.1 Defining the Problem in Matlab m-files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67

3.2 Editing Problems into an Existing Setup File - Unconstrained Optimization Example . . . . . . . 70

3.3 Defining Box-bounded Global Optimization Problems . . . . . . . . . . . . . . . . . . . . . . . . . 72

3.4 Defining Constrained Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73

3.5 Defining Global Mixed-Integer Nonlinear Programming Problems . . . . . . . . . . . . . . . . . . . 75

3.6 Defining Problems in Own Problem Definition Files . . . . . . . . . . . . . . . . . . . . . . . . . . 76

3.7 Special Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76

3.8 How to Solve Nonlinear Optimization Problems Using TOMLAB . . . . . . . . . . . . . . . . . . . 77

2

Page 3: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

3.9 Using the Driver Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77

3.10 Direct Call to an Optimization Routine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79

4 Solving Nonlinear Least Squares and Parameter Estimation Problems 81

4.1 Defining Nonlinear Least Squares Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81

4.2 Defining Exponential Sum Fitting Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82

4.3 Defining Problems in Own Problem Definition Files . . . . . . . . . . . . . . . . . . . . . . . . . . 84

5 Special Notes and Features 86

5.1 User Supplied Problem Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86

5.2 User Given Stationary Point . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87

5.3 Printing Utilities and Print Levels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87

5.4 Approximation of Derivatives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88

5.5 Partially Separable Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90

5.6 Recursive solver calls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91

5.7 Usage of routines from Optimization Toolbox 1.x . . . . . . . . . . . . . . . . . . . . . . . . . . . 91

5.8 Using Matlab 5.0 or 5.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91

6 The TOMLAB Routines - Detailed Descriptions 92

6.1 Optimization Routines in TOMLAB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92

6.1.1 clsSolve . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92

6.1.2 conSolve . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93

6.1.3 cutplane . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95

6.1.4 DualSolve . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97

6.1.5 gblSolve . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98

6.1.6 gclSolve . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99

6.1.7 glbSolve . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101

6.1.8 glcSolve . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103

6.1.9 LineSearch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104

6.1.10 intpol2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106

6.1.11 intpol3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106

6.1.12 lpSolve . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107

6.1.13 mipSolve . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108

6.1.14 nlpSolve . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110

6.1.15 preSolve . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111

6.1.16 qpe . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112

6.1.17 qpBiggs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112

6.1.18 qplm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113

6.1.19 qpSolve . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113

6.1.20 sTrustr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115

6.1.21 itrr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116

6.1.22 ucSolve . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117

6.2 Driver Routines in TOMLAB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118

3

Page 4: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

6.2.1 clsRun . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118

6.2.2 conRun . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119

6.2.3 glbRun . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120

6.2.4 glcRun . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121

6.2.5 lpRun . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122

6.2.6 lsRun . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123

6.2.7 mipRun . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124

6.2.8 qpRun . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125

6.2.9 ucRun . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126

6.3 Utility Functions in TOMLAB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127

6.3.1 cpTransf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127

6.3.2 PrintResult . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128

6.3.3 PrintSolvers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129

6.3.4 runtest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129

6.3.5 systest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130

7 TOMLAB LDO 130

7.1 Optimization Algorithms and Solvers in TOMLAB LDO . . . . . . . . . . . . . . . . . . . . . . . . 130

7.1.1 Linear Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130

7.1.2 Transportation Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131

7.1.3 Network Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132

7.1.4 Mixed-Integer Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132

7.1.5 Dynamic Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133

7.1.6 Lagrangian Relaxation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133

7.1.7 Utility Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133

7.2 How to Solve Optimization Problems Using TOMLAB LDO . . . . . . . . . . . . . . . . . . . . . . 134

7.2.1 How to Solve Linear Programming Problems . . . . . . . . . . . . . . . . . . . . . . . . . . 134

7.2.2 How to Solve Transportation Programming Problems . . . . . . . . . . . . . . . . . . . . . 135

7.2.3 How to Solve Network Programming Problems . . . . . . . . . . . . . . . . . . . . . . . . . 135

7.2.4 How to Solve Integer Programming Problems . . . . . . . . . . . . . . . . . . . . . . . . . . 137

7.2.5 How to Solve Dynamic Programming Problems . . . . . . . . . . . . . . . . . . . . . . . . . 137

7.2.6 How to Solve Lagrangian Relaxation Problems . . . . . . . . . . . . . . . . . . . . . . . . . 139

7.3 Printing Utilities and Print Levels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140

7.4 Optimization Routines in TOMLAB LDO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140

7.4.1 akarmark . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140

7.4.2 balas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141

7.4.3 dijkstra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142

7.4.4 dpinvent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142

7.4.5 dpknap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143

7.4.6 karmark . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144

7.4.7 ksrelax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145

7.4.8 labelcor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145

4

Page 5: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

7.4.9 lpdual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146

7.4.10 lpkarma . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147

7.4.11 lpsimp1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147

7.4.12 lpsimp2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148

7.4.13 maxflow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149

7.4.14 modlabel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149

7.4.15 NWsimplx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150

7.4.16 salesman . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151

7.4.17 TPsimplx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152

7.4.18 urelax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153

7.5 Optimization Subfunction Utilities in TOMLAB LDO . . . . . . . . . . . . . . . . . . . . . . . . . 153

7.5.1 a2frstar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153

7.5.2 gsearch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154

7.5.3 gsearchq . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154

7.5.4 mintree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155

7.5.5 TPmc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155

7.5.6 TPnw . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156

7.5.7 TPvogel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156

7.5.8 z2frstar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157

8 Interfaces 158

8.1 The MEX-file Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158

8.2 The Matlab Optimization Toolbox Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158

8.3 The CUTE Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158

8.4 The AMPL Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159

A Description of Algorithms in TOMLAB 160

A.1 clsSolve . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160

A.1.1 Convergence criterias . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162

A.1.2 Stop criterias . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163

A.1.3 Computation of Search Direction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163

A.1.4 Update Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163

A.2 cutplane . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164

A.3 glbSolve . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165

A.3.1 conhull . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166

A.3.2 next . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166

A.3.3 pred . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166

A.4 LineSearch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167

A.4.1 Bracketing Phase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167

A.4.2 Sectioning Phase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167

A.4.3 intpol2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168

A.4.4 intpol3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168

A.5 ucSolve . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169

5

Page 6: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

A.5.1 Convergence criterias . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172

A.5.2 Stop criterias . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172

A.5.3 Computation of Search Direction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172

A.5.4 Update Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172

B Description of Algorithms in TOMLAB LDO 174

B.1 akarmark . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174

B.2 dijkstra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174

B.3 dpinvent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175

B.4 dpknap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176

B.5 gsearch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176

B.6 gsearchq . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176

B.7 karmark . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177

B.8 ksrelax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177

B.9 labelcor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178

B.10 lpdual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178

B.11 lpkarma . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179

B.12 lpsimp1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180

B.13 lpsimp2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180

B.14 maxflow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181

B.15 modlabel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182

B.16 mintree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182

B.17 TPmc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182

B.18 TPnw . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183

B.19 TPsimplx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183

B.20 TPvogel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184

B.21 urelax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185

6

Page 7: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

1 The TOMLAB Optimization Environment

This Users Guide describes the TOMLAB v2.0 optimization environment. TOMLAB is a general purpose, openand integrated development environment in Matlab for research, teaching and practical solution of optimizationproblems. TOMLAB has grown out of our need for advanced, robust and reliable tools to be used in our develop-ment of algorithms and software for the solution of many different types of applied optimization problems.

There are many good tools available in the area of numerical analysis and optimization, but because of the differentlanguages and systems, as well as a lack of standardization, it is time consuming and complicated task to use thesetools. Often one has to rewrite the problem formulation, rewrite the function specifications, or make some newinterface routine to make everything work. Therefore the first obvious and basic design principle in TOMLABis: Define your problem once, run all available solvers. The system takes care of all interface problems, whetherbetween languages or due to different demands on the problem specification.

In the process of optimization one sometimes want to graphically view the problem and the solution process,especially for ill-conditioned nonlinear problems. Sometimes it is not clear what solver is best for the particulartype of problem and tests on different solvers can be of use. In teaching one wants to view the details of thealgorithms and look more carefully at the different steps. An unexperienced user or a student might want somevery easy way to solve the problem, liking to use a menu system or a graphical user interface. When developingnew algorithms tests on thousands of problems are necessary to fully access the pros and cons of the new algorithm.

All these problems and many more are easily solved with the TOMLAB optimization environment. TOMLABgives you easy access to a large set of standard test problems, optimization solvers and utilities. Furthermore, youcan easily define your own problems and try to solve them using any solver. However, to be able to efficientlydeal with all different objectives on a useful tool, it was necessary to make an very advanced design, and use newconcepts and way of thinking.

The rest of this chapters discusses the design of TOMLAB, the different problems possible to solve, the differentmenu systems and the graphical user interface (GUI). The low-level routines needed for the solution of nonlinearproblems and sets of test problems are also discussed.

Some users may want to skip the rest of this chapter and come to a quick solution of their particular problem.Especially when solving linear or quadratic programming problems it is easy to directly run the system and solvethe particular problem. In the chapters 2, 3 and 4 the definition and solution of each class of problem are discussed,illustrated with test examples that are part of the TOMLAB distribution. Special system features which helpsthe solution process are discussed in Section 5. Chapter 6 contains detailed descriptions of all relevant functionsin TOMLAB. Solvers, driver routines and utility routines are presented.

In the following subsections, the basic design of TOMLAB v2.0 is presented. In Section 1.2, its design and basicstructure are discussed. Section 1.3 - Section 1.5 gives an overview of the implemented solver and utility routines.The menu system is presented in Section 1.4 and the Graphical User Interface in Section 1.6.

All routines in the basic TOMLAB are integrated together in a standardized way, and callable from GUI, thedifferent menu systems, and the different driver routines. TOMLAB also includes a large collection of optimizationsolvers that are single routines. They are all solvers for linear and discrete optimization and collected togetherin the TOMLAB LDO (Linear and Discrete Optimization) toolbox. Included in TOMLAB LDO are also testroutines for all solvers. Chapter 7 describes the problems possible to solve and the different solvers and utilities.

The aim is that TOMLAB should provide interfaces to all relevant optimization software in the areas that TOMLABcovers. By use of the TOMLAB MEX-file interfaces it is possible to call general-purpose solvers implemented inFortran or C. In Section 8 the current set of interfaces are described. For algorithm testing the interface to theCUTE test problem data base is of interest. And for the user having problems defined in the AMPL modelinglanguage, the AMPL interface might be of interest.

TOMLAB v2.0 is also call compatible with the Matlab Optimization Toolbox 2.0. If the user wants to use thistoolbox, the directory optim must be removed from the path.

TOMLAB has been discussed in several papers and at several conferences. The main paper on TOMLAB v1.0 is[34]. TOMLAB allows you to deal with nonlinear programming and parameter estimation, presented in [36], andwith linear and discrete optimization, presented in [37]. Global optimization routines are also implemented, one isdescribed in [35]. In all these papers TOMLAB was divided into two toolboxes, the NLPLIB TB and the OPERATB. This was impractical because of the integration of Linear and Mixed Integer Programming into the GUI andthe other menu and driver tools. The graphical user interface (GUI) is described in [18].

7

Page 8: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

1.1 Background

Many scientists and engineers are using Matlab as a modeling and analysis tool, but for the solution of optimizationproblems, the support is weak. That was one motive for starting the development of TOMLAB;

To solve optimization problems, traditionally the user has been forced to write a Fortran code that calls somestandard solver written as a Fortran subroutine. For nonlinear problems, the user must also write subroutinescomputing the objective function value and the vector of constraint function values. The needed derivativesare either explicitly coded, computed by using numerical differences or derived using automatic differentiationtechniques.

In recent years several modeling languages are developed, like AIMMS [8], AMPL [25], ASCEND [48], GAMS [9, 14]and LINGO [1]. The modeling system acts as a preprocessor. The user describes the details of his problem in a veryverbal language; an opposite to the concise mathematical description of the problem. The problem description fileis normally modified in a text editor, with help from example files solving the same type of problem. Much effortis directed to the development of more user friendly interfaces. The model system processes the input descriptionfile and calls any of the available solvers. For a solver to be accessible in the modeling system, special types ofinterfaces are developed.

The modeling language approach is suitable for many management and decision problems, but may not alwaysbe the best way for engineering problems, which often are nonlinear with a complicated problem description.Until recently, the support for nonlinear problems in the modeling languages has been crude. This is now rapidlychanging [19].

For people with a mathematical background, modeling languages often seems to be a very tedious way to define anoptimization problem. There has been several attempts to find languages more suitable than Fortran or C/C++to describe mathematical problems, like the compact and powerful APL language [39, 49]. Nowadays, languageslike Matlab has a rapid growth of users. Matlab was originally created [45] as a preprocessor to the standardFortran subroutine libraries in numerical linear algebra, LINPACK [17] and EISPACK [53] [26], much the sameidea as the modeling languages discussed above.

Matlab of today is an advanced and powerful tool, with graphics, animation and advanced menu design possibilitiesintegrated with the mathematics. The Matlab language has made the development of toolboxes possible, whichserves as a direct extension to the language itself. Using Matlab as an environment for solving optimizationproblems offers much more possibilities for analysis than just the pure solution of the problem. The increasedquality of the Matlab MEX-file interfaces makes it possible to run Fortran and C-programs on both PC and Unixsystems. And the MIDEVA system that converts the Matlab m-file code into C++ and compiles it makes thetime penalty of using an interpretative system like Matlab much less.

The concept of TOMLAB is to integrate all different systems, getting access to the best of all worlds. TOMLABshould be seen as a complement to existing model languages, for the user needing more power and flexibility thangiven by a modeling system.

1.2 The Design of TOMLAB

In this section we discuss the design of TOMLAB. As the scope of TOMLAB is large and broad, there is a clearneed of a well-designed system. It is also necessary to use the power of the Matlab language, to make the systemflexible and easy to use and maintain. We have used the concept of structure arrays and made heavy use of boththe ability in Matlab to execute Matlab code defined as string expressions and to execute functions specified by astring.

Currently TOMLAB v2.0 consists of about 80000 lines of m-file code in more than 420 files with algorithms,utilities and predefined problems. This motivates a well-defined naming convention and design.

TOMLAB solves a number of different types of optimization problems. Currently, we have defined the types listedin Table 1. The global variable probType is the current type to be solved. An optimization solver is defined to be oftype solvType, where solvType is any of the probType entries in Table 1. It is clear that a solver of a certain solvTypeis able to solve a problem defined to be of another type. For example, a constrained nonlinear programming solvershould be able to solve unconstrained problems and constrained nonlinear least squares problems.

Define probSet to be a set of defined optimization problems to be solved. Each probSet belongs to a certain classof optimization problems of type probType. Each probSet is physically stored in one file. In Table 2 the currently

8

Page 9: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Table 1: The different types of optimization problems treated in TOMLAB.

probType Number Description of the type of problemuc 1 Unconstrained optimization (incl. bound constraints).qp 2 Quadratic programming.con 3 Constrained nonlinear optimization.ls 4 Nonlinear least squares problems (incl. bound constraints).exp 5 Exponential fitting problems.cls 6 Constrained nonlinear least squares problems.mip 7 Mixed-Integer programming.lp 8 Linear programming.glb 9 Box-bounded global optimization.glc 10 Global mixed-integer nonlinear programming.

defined problem sets are listed, and new probSet sets are easily added.

Table 2: Defined test problem sets in TOMLAB. probSets marked with ∗ are not part of the standard distribution

probSet probType Description of test problem setuc 1 Unconstrained test problems.qp 2 Quadratic programming test problems.con 3 Constrained test problems.ls 4 Nonlinear least squares test problems.exp 5 Exponential fitting problems.cls 6 Linear constrained nonlinear least squares problems.mip 7 Mixed-integer programming problems.lp 8 Linear programming problems.glb 9 Box-bounded global optimization test problems.glc 10 Global MINLP test problems.mgh 4 More, Garbow, Hillstrom nonlinear least squares problems.amp 3 AMPL test problems as nl-files.nls∗ 6 Nonlinear constrained nonlinear least squares problems.chs∗ 3 Hock-Schittkowski constrained test problems.uhs∗ 1 Hock-Schittkowski unconstrained test problems.cto∗ 3 CUTE constrained test problems as dll-files.ctl∗ 3 CUTE large constrained test problems as dll-files.uto∗ 1 CUTE unconstrained test problems as dll-files.utl∗ 1 CUTE large unconstrained test problems as dll-files.

A flow-sheet of the process of optimization in TOMLAB is shown in Figure 1. Normally, a single optimizationproblem is solved running any of the menu systems (one for each solvType), or using the Graphical User Interface(GUI). When several problems are to be solved, e.g. in algorithmic development, it is inefficient to use an interactivesystem. This is symbolized with the Advanced User box in the figure, which directly runs the Optimization Driver.The Interface Routines in Figure 1 are used to convert computational results to the form expected by differentsolvers.

A set of Matlab m-files are needed to implement the chain of function calls for all solver types and problem sets,i.e. for the menu systems, driver routines etc. Table 3 shows the naming convention. The names of the problemsetup routine and the low level routines are constructed as two parts. The first part being the abbreviation of therelevant probSet, see Table 2, and the second part denotes the computed task, shown in Table 4. An example,illustrating the constrained nonlinear programming case (solvType = con, probSet = con) is shown in Figure 2.

The problem setup routine has two modes of operation; either return a string matrix with the names of theproblems in the probSet or a structure with all information about the selected problem. The structure, namedProb, is shown in Table 5. Using a structure makes it easy to add new items without too many changes in the rest

9

Page 10: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

✁User

✁User

Menu system / GUI

Optimization Driver

TOMLAB solver Optimization Toolbox Solver MEX-file Solver

✁Advanced User

Interface Routines

TOMLAB Gateway routines

Low Level Routines

❘ ✙

MEX-file interface

Setup Problem✲

nlp f, nlp g, nlp H, nlp c, nlp dc, nlp d2c, nlp r, nlp J, nlp d2r

Compute f(x), g(x), H(x), c(x), ∂c(x)/dx,∑

i λi∂2ci(x)/dx2

For NLLS residual r(x), Jacobian J(x),∑

i ri(x)∂2ri(x)/dx2

Define names of functionscomputing f(x), g(x) etc.

Figure 1: The process of optimization in TOMLAB.

10

Page 11: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

✁User

✁User

conOpt / GUI

conRun

conSolve (TOMLAB) fmincon (OPTIM) MINOS NPSOL NPOPT

✁Advanced User

Interface: nlp fc, nlp gdc, nlp fg, nlp cdcS, nlp cdc

TOMLAB Gateway Routines

Low Level Routines

❘ ✙

MEX: minos, npsol or npopt

con prob✲

✛Define names of functions: con f,

con g, con H, con c, con dc, con d2c

E.g.: Gateway Routine Prob.p f=’nlp f’ computes f(x).Call: f = feval(Prob.p f, x, Prob)

In nlp f: f = feval(Prob.USER.f, x, Prob),where Prob.USER.f=’con f’

Either choose pre-defined problemfrom menu or silent setup

Figure 2: Solution of constrained nonlinear problems in TOMLAB.

11

Page 12: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Table 3: Names of main m-file functions in TOMLAB.

Generic name Purpose ( solvType is �, e.g. �=con)�Opt Menu program.�Run Multi-solver optimization driver routine.�Def Routine defining optimization parameters.�Solve Solver.�Assign Utility to help defining an optimization problem.�VarDef Utility defining problem relevant parameters�ProbSet Utility setting variables in Prob structure

Table 4: Names on the low level m-files in TOMLAB.

Generic name Purpose ( � is any probSet, e.g. �=amp)� prob Define string matrix with problems and a structure prob for each

problem.� f Compute objective function f(x).� g Compute the gradient vector g(x).� H Compute the Hessian matrix H(x).� c Compute the vector of constraint functions c(x).� dc Compute the matrix of constraint normals, ∂c(x)/dx.� d2c Compute the 2nd part of 2nd derivative matrix of the Lagrangian

function,∑

i λi∂2ci(x)/dx2.

� r Compute the residual vector r(x).� J Compute the Jacobian matrix J(x).� d2r Compute the 2nd part of the Hessian matrix,

∑i ri(x)∂

2ri(x)/dx2

of the system. The menu systems and the GUI are using the string matrix for user selection of which problem tobe solved.

There are default values for everything that is possible to set defaults for, and all routines are written in a waythat makes it possible for the user to just set an input argument empty and get the default.

The results of the optimization attempts are stored in a structure array named Result. The currently definedfields in the structure are shown in Table 16. The use of structure arrays make advanced result presentation andstatistics possible.

The field xState describes the state of each of the variables. In Table 17 the different values are described. Thedifferent conditions for linear constraints are defined by the state variable in field bState. In Table 18 the differentvalues are described.

To conclude, the system design is flexible and easy to expand in many different ways.

12

Page 13: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Table 5: Information stored in the problem structure Prob. Fields defining sub-structures are defined in Table 6

Field DescriptionName Problem name.P Problem number.probType TOMLAB problem type, see Table 1.probFile Name of m-file in which problem are defined.xName Name of each decision variable.cName Name of each general constraint.optParam Structure with special fields for optimization parameters, see Table 7.Solver Structure with fields Name and Alg. Name is the name of the solver and Alg

is the solver algorithm to be used. See the solver descriptions Section 6.1.SolverLP Solver to solve LP sub problems. Used by SolveLP.SolverDLP Solver to solve Dual LP sub problems. Used by SolveDLP.SolverQP Solver to solve QP sub problems. Used by SolveQP.SolverPhase1 Solver to solve Phase1 LP sub problems. Used by SolvePhase1.uP User supplied parameters for the problem.uPName Problem name connected to the user supplied parameters.A Constraint matrix for linear constraints, one constraint per row.b L Lower bounds on the linear constraints.b U Upper bounds on the linear constraints.c L Lower bounds on the general constraints.c U Upper bounds on the general constraints.x L Lower bounds on the variables.x U Upper bounds on the variables.x 0 Starting point.N Problem dimension (number of variables).f Low Lower bound on function value. Used in line search by Fletcher, default,

−realmax = −1.7977E308.x opt Optimal point x∗ (if known).f opt Optimal objective function value f(x∗).AutoDiff If true, use automatic differentiation.NumDiff Numerical approximation of derivatives. If set to 1, classical approach with

forward or backward differences together with automatic step selection will beused. If set to 2, 3 or 4 the spline routines csapi, csaps or spaps in SPLINEToolbox will be used. If set to 5, derivatives will be estimated by use ofcomplex variables.

p f Name of gateway routine computing the objective function f(x).p g Name of gateway routine computing the gradient vector g(x).p H Name of gateway routine computing the Hessian matrix H(x).p c Name of gateway routine computing the vector of constraint functions c(x).p dc Name of gateway routine computing the matrix of constraint normals

∂c(x)/dx.p d2c Name of gateway routine computing the 2nd part of 2nd derivative matrix of

the Lagrangian function,∑

i λi∂2c(x)/dx2.

p r Name of gateway routine computing the residual vector r(x).p J Name of gateway routine computing the Jacobian matrix J(x).p d2r Name of gateway routine computing the second part of the Hessian for a

nonlinear least squares problem, i.e.m∑i=1

ri(x)∂2ri(x)∂xj∂xk

.

x min Lower plot region parameters.x max Upper plot region parameters.

13

Page 14: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Table 6: The fields defining sub-structures in the problem structure Prob.

Field DescriptionExpFit Structure with special fields for exponential fitting problems, see Table 8.QP Structure with special fields for linear and quadratic problems, see Table 9.NLLS Structure with special fields for nonlinear least squares, see Table 11.MIP Structure with special fields for mixed-integer programming, see Table 10.PartSep Structure with special fields for partially separable functions, see Table 12.GLOBAL Structure with special fields for global optimization, see Table 13.USER Structure with user defined names of the m-files computing the objective,

gradient, Hessian etc. See Table 14. These routines are called from the corre-sponding gateway routine

14

Page 15: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Table 7: Information stored in the structure Prob.optParam

Field Descriptionalg Optimization Algorithm. Dependent on type of problem. Default 0.method Solver sub-method technique. Default 0.PriLev Print level in optimization solver, default 1.IterPrint Flag for one-row-per-iteration printout during optimizationeps x Convergence tolerance in optimal solution x, distance between suc-

cessive x, ‖xk+1 − xk‖, default 10−8.eps f Convergence tolerance on f . Also used when testing on the directed

derivative, default 10−8.eps dirg Convergence tolerance on the directed derivative, default 10−8.eps c Constraint violation convergence tolerance, default 10−6.LineAlg Line search algorithm. 0 = quadratic interpolation, 1 = cubic in-

terpolation, 2 = curvilinear quadratic interpolation, 3 = curvilinearcubic interpolation. Default LineAlg = 0.

GradCheck Set to 1 if you want to check user-supplied gradients, default 0.MaxIter Maximum number of iterations, default 500.DiffGradMinChange Minimum change in variables for finite difference gradients, default

10−8.DiffGradMaxChange Maximum change in variables for finite difference gradients, default

0.1.InitStepLength Initial step length, default 1 or less.eps g Gradient (or reduced gradient) convergence tolerance, default 10−6.eps Rank Rank test tolerance, default 10−10.wait Flag if to use pause statements after output, default 0.eps absf Convergence tolerance on absolute function value, default realmin.PreSolve Flag if presolve analysis is to be applied on linear constraints, default

0.QN InitMatrix Initial matrix for Quasi-Newton, may be set by the user. When

QN InitMatrix is empty, the identity matrix is used.LineSearch Structure with special fields for the line search, see Table 15.Penalty Penalty parameter for constrained problems.xTol If x ∈ [x L, x L+ bTol] or [x U − bTol, x U ], fix x on bound.bTol Feasibility tolerance for linear constraints.cTol Feasibility tolerance for nonlinear constraints.fTol Accuracy in the computation of the function value, default eps0.9.size x Size at optimum for the variables x, used in the convergence tests.

Default 1.size f Size at optimum for the function f , used in the convergence tests.

Default 1.size c Size at optimum for the constraints c, used in the convergence tests.

Default 1.LowIts Number of iterations with low reduction before convergence.NOT release all Set to 1 if not to release more than one variable at the time.subalg Optimization sub algorithm. Dependent on type of problem. Default

0.splineSmooth Smoothness parameter sent to the SPLINE Toolbox routine csaps.m

when computing numerical approximations of the gradient and theJacobian. Default 0.4.

splineTol Tolerance parameter sent to the SPLINE Toolbox routine spaps.mwhen computing numerical approximations of the gradient and theJacobian. Default 10−3.

15

Page 16: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Table 8: Information stored in the structure Prob.ExpFit

Field Descriptionp Number of exponential terms, default 2.wType Weighting type, default 1.eType Type of exponential terms, default 1.infCR Information criteria for selection of best number of terms, default 0.dType Differentiation formula, default 0.geoType Type of equation, default 0.qType Length q of partial sums, default 0.sigType Sign to use in (P ±√

Q)/D in exp geo for p = 3, 4, default 0.lambda Vector of dimension p, intensities.alpha Vector of dimension p, weights.x0Type Type of starting value algorithm.sumType Type of exponential sum.t eqdist Flag if data is equidistant in time.

Table 9: Information stored in the structure Prob.QP

Field DescriptionF Constant matrix F in 1

2x′Fx+ c′x

c Cost vector c in 12x

′Fx+ c′xB Logical vector of the same length as the number of variables. A zero

corresponds to a variable in the basis.y Dual parameters y.Q Orthogonal matrix Q in QR-decomposition.R Upper triangular matrix R in QR-decomposition.E Pivoting matrix E in QR-decomposition. Stored sparse.DualLimit Stop limit on the dual objective.UseCrash True if to use a crash basis (hot start).CrashFile If nonempty and UseCrash true, read basis from this file.CrashFreq How often to save a crash basis.CrashN The number of crash basis files.

Table 10: Information stored in the structure Prob.MIP

Field Descriptionn I Which variables are integer valuedVarWeight Priority vector for each variable.

16

Page 17: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Table 11: Information stored in the structure Prob.NLLS

Field DescriptionweightType Weighting type:

0 No weighting.1 Weight with data in Yt. If Y t = 0, the weighting is 0, i.e.

deleting this residual element.2 Weight with weight vector or matrix in weightY. If weightY is

a vector then weighting by weigthY.∗r (element wise multipli-cation). If weightY is a matrix then weighting by weigthY ∗ r(matrix multiplication).

3 nlp r calls the routine weigthtY (must be a string with theroutine name) to compute the residuals.

weightY Either empty, a vector, a matrix or a string, see weightType.t Time vector t.Yt Matrix with observations Y (t).UseYt If UseY t = 0 compute residual as f(x, t) − Y (t) (default), other-

wise Y (t) should be treated separately and the residual routines justreturn f(x, t).

SepAlg If SepAlg = 1, use separable non linear least squares formulation,default 0.

Table 12: Information stored in the structure Prob.PartSep

Field DescriptionpSepFunc Number of partially separable functions.index Index for the partially separable function to compute, i.e. if i =

index, compute fi(x). If index = 0, compute the sum of all, i.e.

f(x) =M∑i=1

fi(x).

17

Page 18: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Table 13: Information stored in the structure Prob.GLOBAL

Field Descriptioniterations Number of iterations, default 50.MaxEval Number of function evaluations, default 500.Integers Set of integer variables.epsilon Global/local weight parameter, default 10−4.K The Lipschitz constant. Not used.tolerance Error tolerance parameter. Not used.C Matrix with all rectangle centerpoints.D Vector with distances from centerpoint to the vertices.L Matrix with all rectangle side lengths in each dimension.F Vector with function values.d Row vector of all different distances, sorted.d min Row vector of minimum function value for each distance.Split Split(i, j) is the number of splits along dimension i of rectangle j.T T (i) is the number of times rectangle i has been trisected.G Matrix with constraint values for each point.ignoreidx Rectangles to be ignored in the rectangle selection proceedure.I L I L(i, j) is the lower bound for rectangle j in integer dimension I(i).I U I U(i, j) is the upper bound for rectangle j in integer dimension I(i).feasible Flag indicating if a feasible point has been found.f min Best function value found at a feasible point.s 0 s 0 is used as s(0).s s(j) is the sum of observed rates of change for constraint j.t t(i) is the total number of splits along dimension i.

Table 14: Information stored in the structure Prob.USER

Field Descriptionf Name of m-file computing the objective function f(x).g Name of m-file computing the gradient vector g(x). If Prob.USER.g

is empty then numerical derivatives will be used.H Name of m-file computing the Hessian matrix H(x).c Name of m-file computing the vector of constraint functions c(x).dc Name of m-file computing the matrix of constraint normals ∂c(x)/dx.d2c Name of m-file computing the 2nd part of 2nd derivative matrix of

the Lagrangian function,∑

i λi∂2c(x)/dx2.

r Name of m-file computing the residual vector r(x).J Name of m-file computing the Jacobian matrix J(x).d2r Name of m-file computing the 2nd part of the Hessian for nonlinear

least squares problem, i.e.m∑i=1

ri(x)∂2ri(x)∂xj∂xk

.

18

Page 19: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Table 15: Information stored in the structure Prob.optParam.LineSearch

Field Descriptionsigma Line search accuracy; 0 < sigma < 1. sigma = 0.9 inaccurate line

search. sigma = 0.1 accurate line search, default 0.9.rho Determines the ρ line, default 0.01.tau1 Determines how fast step grows in phase 1, default 9.tau2 How near end point of [a, b], default 0.1.tau3 Choice in [a, b] phase 2, default 0.5.eps1 Minimal length for interval [a, b], default 10−7.eps2 Minimal reduction, default 10−12.MaxIter Maximum number of line search iterations.

19

Page 20: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Table 16: Information stored in the global Matlab structure Result.

Field DescriptionIter Number of major iterations.ExitFlag 0 if convergence to local min. Otherwise errors.Inform Information parameter, type of convergence.f k Function value at optimum.g k Gradient value at optimum.H k Hessian value at optimum.B k Quasi-Newton approximation of the Hessian at optimum.x 0 Starting point.f 0 Function value at start i.e. f(x 0).x k Optimal point.v k Lagrange multipliers.r k Residual at optimum.J k Jacobian matrix at optimum.c k Value of constraints at optimum.cJac Constraint Jacobian at optimum.xState State of each variable, described in Table 17 .bState State of each linear constraint, described in Table 18.cState State of each general constraint.optParam Structure with special fields for optimization parameters, see Table 7.Name Problem name.P Problem number.p dx Matrix where each column is a search direction.alphaV Matrix where row i stores the step lengths tried for the i:th iteration.x min Lowest x-values in optimization. Used for plotting.x max Highest x-values in optimization. Used for plotting.F X F X is a global matrix with rows: [iter no f(x)].GLOBAL Structure with special fields for global optimization, see Table 19.SepNLLS General result variable with fields z and Jz. Used when running sepa-

rable nonlinear least squares problemsSolver Solver used.SolverAlgorithm Solver algorithm used.CPUtime CPU time used.REALtime Real time elapsed.Nflops Number of floating point operations.probType TOMLAB problem type.solvType TOMLAB solver type.FuncEv Number of function evaluations needed.GradEv Number of gradient evaluations needed.ConstrEv Number of constraint evaluations needed.ResEv Number of residual evaluations needed.JacEv Number of Jacobian evaluations needed.Prob Problem structure, see Table 5.plotData Structure with plotting parameters.

Table 17: The state variable xState for the variable.

Value Description0 A free variable.1 Variable on lower bound.2 Variable on upper bound.3 Variable is fixed, lower bound is equal to upper bound.

20

Page 21: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Table 18: The state variable bState for each linear constraint.

Value Description0 Inactive constraint.1 Linear constraint on lower bound.2 Linear constraint on upper bound.3 Linear equality constraint.

Table 19: Information stored in the structure Result.GLOBAL

Field DescriptionC Matrix with all rectangle centerpoints in original coordinates.D Vector with distances from centerpoint to the vertices.L Matrix with all rectangle side lengths in each dimension.F Vector with function values.d Row vector of all different distances, sorted.d min Row vector of minimum function value for each distance.Split Split(i, j) is the number of splits along dimension i of rectangle j.T T (i) is the number of times rectangle i has been trisected.G Matrix with constraint values for each point.ignoreidx Rectangles to be ignored in the rectangle selection procedure.I L I L(i, j) is the lower bound for rectangle j in integer dimension I(i).I U I U(i, j) is the upper bound for rectangle j in integer dimension I(i).feasible Flag indicating if a feasible point has been found.f min Best function value found at a feasible point.s 0 s 0 is used as s(0).s s(j) is the sum of observed rates of change for constraint j.t t(i) is the total number of splits along dimension i.

21

Page 22: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

1.2.1 Global Variables

The use of globally defined variables in TOMLAB is well motivated. For example to avoid unnecessary evaluations,storage of sparse patterns, internal communication, computation of elapsed CPU time etc.

Even though global variables is efficient to use in many cases, it will be trouble with recursive algorithms andrecursive calls. Therefore, the routines globalSave and globalGet are used. The globalSave routine saves all globalvariables in a structure glbSave(depth) and then initialize all of of them as empty. By using the depth variable,an arbitrarily number of recursions are possible. The other routine globalGet retrieves all global variables in thestructure glbSave(depth).

The global variables used in TOMLAB are listed in Table 20 and 21.

Table 20: The global variables used in TOMLAB

Name DescriptionMAXCOLS Number of screen columns. Default 120.MAXMENU Number of menu items showed on one screen. Default 50.MAX c Maximum number of constraints to be printed.MAX x Maximum number of variables to be printed.MAX r Maximum number of residuals to be printed.CUTEPATH The path ending with \cute.CUTEDLL Name of CUTE DLL file.DLLPATH Full path to the CUTE DLL file.CUTE g Gradient.CUTE H Hessian.CUTE Hx Value of x when computing CUTE H.CUTE dc Constraint normals.CUTE Equal Binary vector, element i equals 1 if constraint i is an equality con-

straint.CUTE Linear Binary vector, element i equals 1 if constraint i is a linear constraint.n f Counter for the number of function evaluations.n g Counter for the number of gradient evaluations.n H Counter for the number of Hessian evaluations.n c Counter for the number of constraint evaluations.n dc Counter for the number of constraint normal evaluations.n d2c Counter for the number of evaluations of the 2nd part of 2nd deriva-

tive matrix of the Lagrangian function.n r Counter for the number of residual evaluations.n J Counter for the number of Jacobian evaluations.n d2r Counter for the number of evaluations of the 2nd part of the Hessian

for a nonlinear least squares problem .NLP x Value of x when computing NLP f.NLP f Function value.NLP xg Value of x when computing NLP g.NLP g Gradient value.NLP xH Value of x when computing NLP H.NLP H Hessian value.NLP xc Value of x when computing NLP c.NLP c Constraints value.NLP pSepFunc Number of partially separable functions.NLP pSepIndex Index for the separated function computed.

22

Page 23: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Table 21: The global variables used in TOMLAB

Name DescriptionLS A Problem dependent information sent from residual routine to Jaco-

bian routine.LS x Value of x when computing LS rLS r Residual value.LS xJ Value of x when computing LS JLS J Jacobian value.SEP z Separated variables z.SEP Jz Jacobian for separated variables z.wNLLS Weighting of least squares residuals (internal variable in nlp r and

nlp J).alphaV Vector with all step lengths α for each iteration.BUILDP Flag.F X Matrix with function values.pLen Number of iterations so far.p dx Matrix with all search directions.X max The biggest x-values for all iterations.X min The smallest x-values for all iterations.X NEW Last x point in line search. Possible new x k.X OLD Last known base point xkprobType Defines the type of optimization problem.solvType Defines the solver type.answer Used by the GUI for user control options.instruction Used by the GUI for user control options.question Used by the GUI for user control options.plotData Structure with plotting parameters.Prob Problem structure, see Table 5.Result Result structure, see Table 16.runNumber Vector index when Result is an array of structures.TIME0 Used to compute CPU time and real time elapsed.TIME1 Used to compute CPU time and real time elapsedcJPI Used to store sparsity pattern for the constraint Jacobian when au-

tomatic differentiation is used.HPI Used to store sparsity pattern for the Hessian when automatic dif-

ferentiation is used.JPI Used to store sparsity pattern for the Jacobian when automatic dif-

ferentiation is used.glbSave Used to save global variables in recursive calls to TOMLAB.

23

Page 24: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

1.3 Solver Routines in TOMLAB

In Table 22 the optimization solvers in TOMLAB are listed. The solver for unconstrained optimization, ucSolve,the constrained nonlinear least squares solver clsSolve, and the constrained solver conSolve, are all implementinga set of algorithms.

Table 22: Optimization solvers in TOMLAB.

Function Description Section PageucSolve Unconstrained optimization with simple bounds on the parameters.

Implements Newton, quasi-Newton and conjugate-gradient methods.6.1.22 117

sTrustr Solver for constrained convex optimization of partially separable func-tions, using a structural trust region algorithm.

6.1.20 115

glbSolve Box-bounded global optimization, using only function values. 6.1.7 101gblSolve Stand-alone version of glbSolve. Runs independently of TOMLAB. 6.1.5 98glcSolve Global mixed-integer nonlinear programming, using no derivatives. 6.1.8 103gclSolve Stand-alone version of glcSolve. Runs independently of TOMLAB. 6.1.6 99clsSolve Constrained nonlinear least squares. Handles simple bounds and

linear equality and inequality constraints using an active-set strat-egy. Implements Gauss-Newton, and hybrid quasi-Newton and Gauss-Newton methods.

6.1.1 92

conSolve Constrained nonlinear minimization solver using two different sequen-tial quadratic programming methods.

6.1.2 93

nlpSolve Constrained nonlinear minimization solver using filter SQP. 6.1.14 110lpSolve Solves a general linear program. 6.1.12 107DualSolve Solves a linear program with a dual feasible starting point. 6.1.4 97qpSolve Solves a general quadratic program. 6.1.19 113mipSolve Solves a mixed-integer program using a branch-and-bound algorithm. 6.1.13 108cutplane Solves a mixed-integer program using a cutting plane algorithm. 6.1.13 108qpBiggs Solves a general quadratic program. 6.1.17 112qpe Solves a qp problem, restricted to equality constraints, using a null

space method.6.1.16 112

qplm Solves a qp problem, restricted to equality constraints, using La-grange’s method.

6.1.18 113

LineSearch Line search algorithm by Fletcher. 6.1.9 104preSolve Presolve analysis on linear constraints and simple bounds. 6.1.15 111

Table 22 lists the TOMLAB internal solvers. To get a list of all available solvers, including Fortran, C and MatlabOptimization Toolbox solvers, for a certain solvType the user just calls the routine PrintSolvers with solvType asargument. solvType should either be a string (’uc’, ’con’ etc.) or the corresponding solvType number, see Table 1.As an example, assume you want a list of all available solvers of solvType con. Then

PrintSolvers(’con’)

gives the printing output

----------------------------------------------------Solver solvType Number Multi-Solver Driver----------------------------------------------------nlpSolve 3 conRunconSolve 3 conRunsTrustr 3 conRunconstr 3 conRunminos 3 conRunnpsol 3 conRunnpopt 3 conRun

24

Page 25: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

and if PrintSolvers is called with no given argument then all available solvers for all different solvType is printed.

The routine ucSolve solves unconstrained optimization problems with simple bounds on the parameters (uc),i.e. solves the problem

minx

f(x)

s/t xL ≤ x ≤ xU ,

(1)

where x, xL, xU ∈ Rn and f(x) ∈ R. ucSolve includes several of the most popular search step methods for

unconstrained optimization. Bound constraints are treated as described in Gill et. al. [29]. The search stepmethods for unconstrained optimization included in ucSolve are: the Newton method, the quasi-Newton BFGSand inverse BFGS method, the quasi-Newton DFP and inverse DFP method, the Fletcher-Reeves and Polak-Ribiereconjugate-gradient method, and the Fletcher conjugate descent method. For the Newton and the quasi-Newtonmethods the code is using a subspace minimization technique to handle rank problems, see Lindstrom [43]. Thequasi-Newton codes also use safe guarding techniques to avoid rank problem in the updated matrix.

Another solver suitable for unconstrained problems is the structural trust region algorithm sTrustr, combined withan initial trust region radius algorithm. The code is based on the algorithms in [16] and [51], and treats partiallyseparable functions. Safeguarded BFGS or DFP are used for Quasi-Newton update, if not the analytical Hessianis used.

The routine glbSolve implements an algorithm for box-bounded global optimization (glb), i.e. problems ofthe form (1) that have finite simple bounds on all the variables. glbSolve implements the DIRECT algorithm [40],which is a modification of the standard Lipschitzian approach that eliminates the need to specify a Lipschitzconstant. In glbSolve no derivative information is used. For global mixed-integer nonlinear programming(glc), glcSolve implements an extended version of DIRECT, see [41], that handles problems with both nonlinearand integer constraints. There are also stand-alone versions of both glbSolve and glcSolve named gblSolve andgclSolve respectively. These stand-alone versions runs independently of TOMLAB.

For global optimization problems with expensive function evaluations the routine ego that implements the EfficientGlobal Optimization (EGO) algorithm [42]. The idea of the EGO algorithm is to first fit a response surface to datacollected by evaluating the objective function at a few points. Then, EGO balances between finding the minimumof the surface and improving the approximation by sampling where the prediction error may be high.

The constrained nonlinear optimization problem (con) is defined as

minx

f(x)

s/txL ≤ x ≤ xU ,bL ≤ Ax ≤ bUcL ≤ c(x) ≤ cU

(2)

where x, xL, xU ∈ Rn, f(x) ∈ R, A ∈ R

m1×n, bL, bU ∈ Rm1 and cL, c(x), cU ∈ R

m2 . For general constrainednonlinear optimization a sequential quadratic programming (SQP) method by Schittkowski [52] is implemented inthe routine conSolve. conSolve also includes an implementation of the Han-Powell SQP method. There are also aroutine nlpSolve implementing the Filter SQP by Fletcher and Leyffer presented in [24].

Another constrained solver in TOMLAB is the structural trust region algorithm sTrustr, described above. Cur-rently, sTrustr only solves problems where the feasible region defined by the constraints is convex.

lpSolve solves a general linear program (lp) defined as

minx

f(x) = cTx

s/txL ≤ x ≤ xU ,bL ≤ Ax ≤ bU

(3)

where c, x, xL, xU ∈ Rn, A ∈ R

m1×n, and bL, bU ∈ Rm1 .

25

Page 26: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

When a dual feasible point is known in (3) it is efficient to use the dual simplex algorithm implemented in DualSolve.

To solve mixed linear inequality integer programs, the problem (3) with the addition that some variables musttake integer values, two algorithms are implemented. The first implementation, mipSolve, is a branch-and-boundalgorithm from Nemhauser and Wolsey [47, chap. 8]. The second implementation, cutplane, is a cutting-planealgorithm using Gomory cuts. Both routines are using the linear programming routines in TOMLAB (lpSolve andDualSolve), to solve relaxed subproblems.

A quadratic program (qp) is defined as

minx

f(x) = 12x

TFx+ cTx

s/txL ≤ x ≤ xU ,bL ≤ Ax ≤ bU

(4)

where c, x, xL, xU ∈ Rn, F ∈ R

n×n, A ∈ Rm1×n, and bL, bU ∈ R

m1 . Quadratic programs are solved with a standardactive-set method [44], implemented in the routine qpSolve. qpSolve explicitly treats both inequality and equalityconstraints, as well as lower and upper bounds on the variables (simple bounds). It converges to a local minimumfor indefinite quadratic programs. TOMLAB also includes a similar routine qpBiggs, which is using a more simplealgorithm for negative definite quadratic problems.

TOMLAB includes two algorithms for solving quadratic programs restricted to equality constraints (EQP); a nullspace method (qpe) and Lagrange’s method (qplm).

The constrained nonlinear least squares problem (cls) is defined as

minx

f(x) = 12r(x)

T r(x)

s/txL ≤ x ≤ xU ,bL ≤ Ax ≤ bUcL ≤ c(x) ≤ cU

(5)

where x, xL, xU ∈ Rn, r(x) ∈ R

N , A ∈ Rm1×n, bL, bU ∈ R

m1 and cL, c(x), cU ∈ Rm2 . x, xL, xU ∈ R

n andr(x) ∈ R

N .

In TOMLAB the nonlinear least squares solver clsSolve treats problems with bound constraints in a similar wayas the routine ucSolve. This strategy is combined with an an active-set strategy to handle linear equality andinequality constraints [10].

clsSolve includes four optimization methods for nonlinear least squares problems: the Gauss-Newton method, theAl-Baali-Fletcher [4] and the Fletcher-Xu [22] hybrid method, and the Huschens TSSM method [38]. If rankproblems occur, the solver is using subspace minimization. The line search algorithm used is the same as forunconstrained problems.

TOMLAB is using the structure variable optParam, see Table 7, with optimization parameters. For each type ofoptimization problem, there is a corresponding definition routine which calls optParamDef and defines the defaultparameter values for optParam. Dependent on probType, it is any of ucDef, qpDef, conDef, lsDef or clsDef.

The line search algorithm LineSearch, used by the solvers conSolve, clsSolve and ucSolve, is a modified versionof an algorithm by Fletcher [23, chap. 2]. The line search algorithm uses quadratic and cubic interpolation, seeSection 6.1.9.

The routine preSolve is running a presolve analysis on a system of linear equalities, linear inequalities and simplebounds. An algorithm by Gondzio [31], somewhat modified, is implemented in preSolve. See [10] for a moredetailed presentation.

1.4 Menu Programs in TOMLAB

There are nine menu programs defined in TOMLAB see Table 23, one for each type of optimization problem(probType). TOMLAB also includes a graphical user interface (GUI) described in Section 1.6, which has the samefunctionality as all the menu programs.

Each menu program calls a corresponding driver routine, having the same probType, viz. either of ucRun, qpRun,conRun, lsRun, clsRun, mipRun, lpRun, glbRun or glcRun,

26

Page 27: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Table 23: Menu programs.

Function DescriptiontomlabGUI Graphical User Interface (GUI) for nonlinear optimization. Handles all types of nonlinear

optimization problems.ucOpt Menu for unconstrained optimization.glbOpt Menu for box-bounded global optimization.glcOpt Menu for global mixed-integer nonlinear programming.lpOpt Menu for linear programming.mipOpt Menu for mixed-integer programming.qpOpt Menu for quadratic programming.conOpt Menu for constrained optimization.lsOpt Menu for nonlinear least squares problems.clsOpt Menu for constrained nonlinear least squares problems.

The ucOpt menu is shown in Figure 3. The other menus look the same, possibly with some extra items corre-sponding to options needed for the relevant problem and solver type. In the following of this section, the mostimportant standard menu choices are commented.

The Choice of Problem File and Problem button selects the problem setup file and the problem to be solved.Correspondingly, the Choice of optimization algorithm button selects the optimization algorithm to be used.

From the Optimization Parameter Menu, parameters needed for the solution can be changed. The user selects newvalues or simply uses the default values. See Figure 4. The parameters are those stored in the optParam structure,see Table 7. The Output print levels button selects the level of output to be displayed in the Matlab CommandWindow during the solution procedure. The Optimization Parameter Menu also allows the user to choose thedifferentiation strategy he wants to use.

Pushing the Optimize button, the relevant routines are called to solve the problem.

When the problem is solved, it is possible to make different types of plots to illustrate the solution procedure.Pushing the Plot Menu button, a menu choosing type of plot will appear. A overview of the available plottingoptions are given in connection with the Graphical User Interface described in Section 1.6.

The menu routines are started by just typing the name of the routine (e.g. ucOpt) at the Matlab prompt. In Section7.2.1 we illustrate how to use the menu system for linear programming problems (lpOpt). The menu routines inTOMLAB work in a similar way.

Calling any of the menu routines in TOMLAB (e.g. ucOpt) by typing Result = ucOpt will return a structure arraycontaining the Result structures of all the runs made. As an example, to display the results from the third run,enter the command Result(3). To display the solution found in the third run, enter the command Result(3).x k.The information stored in the structure are given in Table 16.

1.5 Low Level Routines and Test Problems

We define the low level routines as the routines that compute the objective function value, the gradient vector,the Hessian matrix (second derivative matrix), the residual vector (for NLLS problems), the Jacobian matrix (forNLLS problems), the vector of constraint functions, the matrix of constraint normals and the second part of thesecond derivative of the Lagrangian function. The last three routines are only needed for constrained problems.

The names of these routines are defined in the structure fields Prob.USER.f, Prob.USER.g, Prob.USER.H etc. Itis the task of the problem setup routines in TOMLAB (routines with names of the type * prob) to set the namesof the low level m-files. This is done by a call to the routine mFiles with the names as arguments. As an example,see the last part of the code of con prob below.

...

...Prob=mFiles(Prob,’con_f’,’con_g’,’con_H’,’con_c’,’con_dc’,’con_d2c’);

27

Page 28: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Figure 3: The main menu in ucOpt.

ProbSet;......

Only the low level routines relevant for a certain type of optimization problem need to be coded. There are dummyroutines for the others. Numerical differentiation is automatically used for gradient, Jacobian and constraintgradient if the corresponding user routine is nonpresent or left out when calling mFiles.

TOMLAB is using gateway routines (nlp f, nlp g, nlp H, nlp c, nlp dc, nlp d2c, nlp r, nlp J, nlp d2r). These namesare put in Prob.p f, Prob.p g etc. by TOMLAB automatically. These routines extract the search directions andline search steps, count iterations, handle separable functions, keep track of the kind of differentiation wantedetc. They also handle the separable NLLS case and NLLS weighting. By the use of global variables, unnecessaryevaluations of the user supplied routines are avoided.

To get a picture of how the low-level routines are used in the system, consider Figure 5 and 6. In Figure 5, weillustrate the chain of calls when computing the objective function value in ucSolve for a nonlinear least squaresproblem defined in mgh prob, mgh r and mgh J. In Figure 6, we illustrate the chain of calls when computing thenumerical approximation of the gradient (by use of the routine fdng) in ucSolve for an unconstrained problemdefined in uc prob and uc f.

Information about a problem is stored in the structure variable Prob, described in Table 5. This variable is anargument to all low level routines. In the field element Prob.uP, problem specific information needed to evaluatethe low level routines are stored. A more detailed description of how to define new problems is given in sections2, 3 and 4.

28

Page 29: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Different solvers all have different demand on how information should be supplied, i.e. the function to optimize, thegradient vector, the Hessian matrix etc. To be able to code the problem only once, and then use this formulationto run all types of solvers, interface routines that returns information in the format needed for the relevant solverwere developed.

Table 24 describes the low level test functions and the corresponding problem setup routines needed for thepredefined constrained optimization (con) problems. For the predefined unconstrained optimization (uc) problems,the global optimization (glb, glc) problems and the quadratic programming problems (qp) similar routines areneeded.

Table 24: Generally constrained nonlinear (con) test problems.

Function Descriptioncon prob Initialization of con test problems.con f Compute the objective function f(x) for con test problems.con g Compute the gradient g(x) for con test problems.con H Compute the Hessian matrix H(x) of f(x) for con test problems.con c Compute the constraint residuals c(x) for con test problems.con dc Compute the derivative of the constraint residuals for con test problems.con fm Compute merit function θ(xk).con gm Compute gradient of merit function θ(xk).

The problem of fitting positive sums of positively weighted exponential functions to empirical data may be formu-lated either as a nonlinear least squares problem or a separable nonlinear least squares problem. Some empiricaldata series are predefined and artificial data series may also be generated. Algorithms to find starting values fordifferent number of exponential terms are implemented. Table 25 shows the relevant routines.

Table 25: Exponential fitting test problems.

Function Descriptionexp ArtP Generate artificial exponential sum problems.expInit Find starting values for the exponential parameters λ.exp prob Defines a exponential fitting type of problem, with data series (t, y). The file includes

data from several different empirical test series.Helax prob Defines 335 medical research problems supplied by Helax AB, Uppsala, Sweden, where

an exponential model is fitted to data. The actual data series (t, y) are stored on one fileeach, i.e. 335 data files, 8MB large, and are not distributed. A sample of five similar filesare part of exp prob.

exp r Compute the residual vector ri(x), i = 1, ...,m. x ∈ Rn

exp J Compute the Jacobian matrix ∂ri/dxj , i = 1, ...,m, j = 1, ..., n.exp d2r Compute the 2nd part of the second derivative for the nonlinear least squares exponential

fitting problem.exp c Compute the constraints λ1 < λ2 < ... on the exponential parameters λi, i = 1, ..., p.exp dc Compute matrix of constraint normals for constrained exponential fitting problem.exp d2c Compute second part of second derivative matrix of the Lagrangian function for con-

strained exponential fitting problem. This is a zero matrix, because the constraints arelinear.

exp q Find starting values for exponential parameters λi, i = 1, ..., p.exp p Find optimal number of exponential terms, p.

Table 26 describes the low level routines and the initialization routines needed for the predefined constrainednonlinear least squares (cls) test problems. Similar routines are needed for the nonlinear least squares (ls) testproblems (here no constraint routines are needed).

Table 27 describes the low level test functions and the corresponding problem setup routines needed for thepredefined unconstrained and constrained optimization problems from the CUTE data base [11, 12].

29

Page 30: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Table 26: Constrained nonlinear least squares (cls) test problems.

Function Descriptioncls prob Initialization of cls test problems.cls r Compute the residual vector ri(x), i = 1, ...,m. x ∈ R

n for cls test problems.cls J Compute the Jacobian matrix Jij(x) = ∂ri/dxj , i = 1, ...,m, j = 1, ..., n for cls test

problems.cls c Compute the vector of constraint functions c(x) for cls test problems.cls dc Compute the matrix of constraint normals ∂c(x)/dx for for cls test problems.cls d2c Compute the second part of the second derivative of the Lagrangian function for cls test

problems.ls f General routine to compute the objective function value f(x) = 1

2r(x)T r(x) for nonlinear

least squares type of problems.ls g General routine to compute the gradient g(x) = J(x)T r(x) for nonlinear least squares

type of problems.ls H General routine to compute the Hessian approximation H(x) = J(x)T ∗J(x) for nonlinear

least squares type of problems.

There are some options in the menu programs to display graphical information for the selected problem. Fortwo-dimensional nonlinear unconstrained problems, the menu programs support graphical display of the relevantoptimization problem as mesh or contour plots. In the contour plot, the iteration steps are displayed. For higher-dimensional problems, iterations steps are displayed in two-dimensional subspaces. Special plots for nonlinear leastsquares problems, such as plotting model against data, are available. The plotting utility also includes plot ofconvergence rate, plot of circles approximating points in the plane for the Circle Fitting Problem etc.

30

Page 31: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Table 27: Test problems from CUTE data base.

Function Descriptionctools Interface routine to constrained CUTE test problems.utools Interface routine to unconstrained CUTE test problems.cto prob Initialization of constrained CUTE test problems.ctl prob Initialization of large constrained CUTE test problems.cto f Compute the objective function f(x) for constrained CUTE test problems.cto g Compute the gradient g(x) for constrained CUTE test problems.cto H Compute the Hessian H(x) of f(x) for constrained CUTE test problems.cto c Compute the vector of constraint functions c(x) for constrained CUTE test problems.cto dc Compute the matrix of constraint normals for constrained CUTE test problems.cto d2c Compute the second part of the second derivative of the Lagrangian function for con-

strained CUTE test problems.uto prob Initialization of unconstrained CUTE test problems.utl prob Initialization of large unconstrained CUTE test problems.uto f Compute the objective function f(x) for unconstrained CUTE test problems.uto g Compute the gradient g(x) for unconstrained CUTE test problems.uto H Compute the Hessian H(x) of f(x) for unconstrained CUTE test problems.

31

Page 32: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Figure 4: Setting optimization parameters in ucOpt.

ucSolve ✲✛

nlp f ✲✛

ls f ✲✛

nlp r ✲✛

mgh r

Figure 5: The chain of calls when computing the objective function value in ucSolve for a nonlinear least squaresproblem defined in mgh prob, mgh r and mgh J.

32

Page 33: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

ucSolve ✲✛

nlp g ✲✛

fdng ✲✛

nlp f ✲✛

uc f

Figure 6: The chain of calls when computing the numerical approximation of the gradient in ucSolve for anunconstrained problem defined in uc prob and uc f.

33

Page 34: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

1.5.1 Utility Test Routines

The utility routines listed in Table 28 run tests on a large set of test problems.

Table 28: System test routines.

Function Description Section Pageruntest Runs all selected problems defined in a problem file for a given solver. 6.3.4 129systest Runs big test for each probType in TOMLAB. 6.3.5 130

The runtest routine may also be useful for a user running a large set of optimization problems, if the user does notneed to send special information in the Prob structure for each problem.

1.6 The Graphical User Interface

The Graphical User Interface is started by calling the Matlab m-file tomlabGUI.m, i.e. by entering the commandtomlabGUI at the Matlab prompt. The GUI has two modes; Normal and Advanced. At start the GUI is in Normalmode, shown in Figure 7.

Figure 7: The GUI in Normal mode.

There are one axes area, four menus; Subject, Problem, Algorithm and Plot, and six push buttons; Defaults,Advanced, Plot, Info, Run and Close.

There are also eleven edit controls where it is possible to enter parameter values used by the solution algorithm.To the right of the axes area, starting values for two dimensional problems can be given. How to define starting

34

Page 35: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

values for problems with more than two decision variables is discussed in Section 1.6.1. The edit controls labeled’Axes’ set the axes in the contour plot and the mesh plot. The edit controls below the axes area are used to set theoptimization parameters sent to the solver. These parameters are the maximum number of iterations (MaxIter),the line search accuracy σ (Sigma), the termination tolerance on the change in the decision variables (EpsX), thetermination tolerance on the function value (EpsF) and the termination tolerance on the gradient (EpsG). If asolver for constrained optimization is selected, a twelfth edit control (EpsC) is shown. This edit control sets thetermination tolerance on the constraint violation.

In the axes area plots and information given as text are displayed.

The Subject menu is used to select subject, i.e. which type of problem to be solved. There are currently sixmain problem types; unconstrained optimization, quadratic programming, constrained optimization, nonlinearleast squares, exponential sum fitting and constrained nonlinear least squares.

From the Problem menu, the user selects the problem to be solved. Presently, there are about 15 to 50 predefinedtest problems for each problem type. The user can easily define his own problems and try to solve them using anysolver, see sections 2, 3 and 4.

The Algorithm menu is used to select solver. It can either be a TOMLAB internal solver, a solver in the MatlabOptimization Toolbox or a general-purpose solver implemented in Fortran or C.

Changing type of optimization problem in the Subject menu, will change the menu entries in the Problem menuand Algorithm menu.

From the Plot menu, the type of plot to be drawn is selected. The different types are contour plot, mesh plot,plot of function values and plot of convergence rate. The contour plot and the mesh plot can be displayed eitherin the axes area or in a new figure. The plot of function values and convergence rate are always displayed in a newfigure. For least squares problems and exponential fitting problems it is possible to plot the residuals, the startingmodel and the obtained model.

When pushing the Defaults button, the default values for every parameter are displayed in the edit controls. Ifpushing the button again, the parameters will disappear. Before solving a problem, the user can change any ofthe values. If leaving an edit control empty, the default values are used.

The Advanced button and the Advanced mode is described in Section 1.6.1.

Pushing the Plot button gives a plot of the current problem. In the contour plot, known local minima, known localmaxima and known saddle points are shown. It is possible to make a contour plot and a mesh plot without firstsolving the problem. After the problem is solved, a contour plot shows the search direction and trial step lengthsfor each iteration. A contour plot of the classical Rosenbrock banana function, together with the iteration searchsteps and with marks for the line search trials displayed, is shown in Figure 8.

A contour plot for a constrained problem and a plot of the data and the obtained model for a nonlinear leastsquares problem are given in Figure 9. In the contour plot, (inequality) constraints are depicted as dots. Startingfrom the infeasible point (x1, x2) = (−5.0, 2.5), the solution algorithm first finds a point inside the feasible region.The algorithm then iteratively finds new points. For several of the search directions, the full step is too long andviolates one of the constraints. Marks show the line search trials. Finally, the algorithm converges to the optimalsolution (x∗1, x

∗2) = (−9.5474, 1.0474).

The Info button gives some information about the current problem, e.g. the number of variables.

When the user has chosen a solver and a problem, he then pushes the Run button to solve it. When the algorithmhas converged, information about the solution procedure are displayed. This information will include the solutionfound, the function value at the solution, the number of iterations used, the number of function evaluations, thenumber of gradient evaluations, the number of floating point operations used and the computation time. If noalgorithm is selected as in Figure 7, the Run button has the same function as the Plot button.

To close the GUI, push the Close button.

1.6.1 The Advanced Mode

When pushing the Advanced button, the GUI will change to Advanced mode. The axes area is replaced by moreedit controls and menus, see Figure 10.

Furthermore, the Advanced button is renamed to Figure button. To change from Advanced mode to Normal

35

Page 36: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Figure 8: A contour plot with the search directions and marks for the line search trials for each iteration.

mode, push the Figure button.

There are some new edit controls in the Advanced mode. FLow, the best guess on a lower bound for the optimalfunction value, is used by TOMLAB solver algorithms using the Fletcher line search algorithm [23]. The parameterEpsR is the rank test tolerance in the subspace minimization technique used when determining the search directionin some of the algorithms.

For problems with more than two decision variables, starting values for decision variable x3 to xn are given in theedit control named ’Starting Values x3 - xn’. Starting values for x1 and x2 are given in the edit controls labeled’Starting Values’. To make a contour plot or a mesh plot for problems with more than two decision variables, theuser selects the two-dimensional subspace to plot. The indices of the decision variables defining the subspace aregiven in the edit controls called ’Variables At Axis When n > 2’. The view for a mesh plot is changed using theedit controls ’Mesh View’.

There are six new menus in the Advanced mode. The first menu selects method to compute first and secondderivatives. Except for using an analytical expression, these can be computed either by automatic differentiationusing the ADMAT Toolbox, distributed by Arun Verma at http://simon.cs.cornell.edu/home/verma/AD, or byfive different approaches for numerical differentiation. Three of them requires the Spline Toolbox to be installed.The second menu determines if a quadratic or a cubic interpolation shall be used in the line search algorithm.

Two menus are used to select the level of output from the optimization driver and the optimization solver. Alloutput printed during the optimization are displayed in the Matlab Command Window. If the ’Pause EachIteration’ check box is selected, the TOMLAB solvers are using the pause statement to halt after each iteration.The menu ’Init File’ selects the file defining the current set of problems. Changing the set of problems willautomatically modify the Problem menu. The menu named ’Method’ differs between problem types. Using anunconstrained solver, a least squares solver or an exponential fitting solver, the menu selects method to compute

36

Page 37: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

−10 −9 −8 −7 −6 −5 −40.5

1

1.5

2

2.5

3Problem Exponential problem 1. 2 ineq Contour plot

Variable 1

Var

iabl

e 2

0 50 100 150 200 250 300 350 4000

5

10

15

20

25

30

35

40

45Problem # 3. Gisela

Time t

y(t)

, f(x

*,t)

[sol

id],

f(x0

,t) [d

ashd

ot]

Figure 9: A contour plot for a constrained problem and a plot of data and model for a nonlinear least squaresproblem.

the search direction. In the constrained case, the Method menu gives the quadratic programming solver to be usedin SQP algorithms.

If the check box ’Hold Previous Run’ is selected, all information about the runs are stored. Making a contour plot,the step and trial step lengths for all solution attempts are drawn. This option is useful, e.g. when comparing theperformance of different algorithms or checking how the choice of starting point affects the solution procedure.

For some predefined test problems, it is possible to set parameter values when initializing the problem. Theseparameters can for example be the size of the problem, the number of residuals or the number of constraints.Questions about the parameters will appear when selecting the check box named ’User Control’. If the ’UserControl’ check box is not selected, default values will be used.

When selecting an exponential fitting problem, two new menus and a new edit control will appear. The numberof exponential terms in the approximating model and which of four types of residual weighting to be used aredetermined by the user. Furthermore, there is a choice whether to solve the weighted least squares fitting problemusing an ordinary or separable nonlinear least squares algorithm.

In the Advanced mode there are three new push buttons. If a contour plot is displayed in the axes area and theuser pushes the button named ’x0’, it is possible to select starting point for the current algorithm using the mouse.Pushing the ’ReOpt’ button, the current problem is re-optimized with the starting point defined as the solutionfound in the previous solution attempt.

Entering a name in the edit control labeled ’Define’ and pushing the Save button, two files will be generated; oneMatlab mat-file and one Matlabm-file. The name should not include any extension. For example, entering thename test in the edit control, the files test.mat and test.m will be generated. The files are saved in the currentdirectory. In the mat-file parameters are stored, and in the m-file all commands needed to make a stand-alone runwithout using the GUI are defined. The parameter values are those currently used by the GUI.

If entering a name in the ’Define’ edit control and pushing the Defaults button, the default values for all parameterswill be loaded from the current mat-file.

When a problem is solved, the user can access the results from the Matlab Command Window, stored in the globalstructure Result. If the user has not run the TOMLAB initialization command tomlabInit , he must enter thecommand global Result at the Matlab prompt to declare Result as a global structure. To display the full structure,enter Result at the prompt. To display a specific field in the structure, e.g. the solution found, enter Result.x k.All information stored in the structure are given in Table 16. When the check box ’Hold Previous Run’ is selected,Result becomes a structure array. As an example, to display the results from the third run, enter the commandResult(3). To display the solution found in the third run, enter the command Result(3).x k.

The user could also access the plotting parameter structure plotData in the same way as described for the Resultstructure above.

37

Page 38: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Figure 10: The GUI in Advanced mode.

38

Page 39: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

2 Solving Linear, Quadratic and Integer Programming Problems

This section describes how to define and solve linear and quadratic programming problems, and mixed-integer linearprograms using TOMLAB. Several examples are given on how to proceed, depending on if a quick solution iswanted, or more advanced tests are needed. TOMLAB is also compatible with Math Works Optimization TB v2.0,and it is shown how to run TOMLAB using their syntax.

All test example and output files are part of the standard distribution of TOMLAB, and all tests can be run bythe user. There is a file RunAllTests that goes through and runs all tests. The diary command is used to savescreen output and the resulting files are stored with the extension out, and having the same name as the test file.

2.1 Linear Programming Problems

The general formulation in TOMLAB for a linear programming problem is

minx

f(x) = cTx

s/txL ≤ x ≤ xU ,bL ≤ Ax ≤ bU

(6)

where c, x, xL, xU ∈ Rn, A ∈ R

m1×n, and bL, bU ∈ Rm1 . Equality constraints are defined by setting the lower

bound equal to the upper bound, i.e. for constraint i: bL(i) = bU (i).

Linear programs are normally solved using the TOMLAB routine lpSolve that implements a revised simplexalgorithm. It is also possible to use the active-set QP method routine qpSolve or a general nonlinear solver likenlpSolve or conSolve. Using a MEX-file interface, the SOL routines MINOS or QPOPT are suitable for linearprogramming problems. To choose alternative solvers, the multi-driver routine lpRun is called.

To illustrate the solution of LPs consider the simple linear programming test problem

minx1,x2

f(x1, x2) = −7x1 − 5x2

s/t x1 + 2x2 ≤ 64x1 + x2 ≤ 12x1, x2 ≥ 0

(7)

named LP Example.

The following statements define this problem in Matlab

File: tomlabv2/usersguide/lpExample.m

Name = ’lptest’;c = [-7 -5]’;A = [ 1 2

4 1 ];b_U = [ 6 12 ]’;x_L = [ 0 0 ]’;x_min = [ 0 0 ]’;x_max = [10 10 ]’;

% b_L, x_U and x_0 have default values and need not be defined.b_L = [-inf -inf]’;x_U = [];x_0 = [];

2.1.1 A Quick Linear Programming Solution

The quickest way to solve this problem is to define the following Matlab statements

File: tomlabv2/usersguide/lpTest1.m

39

Page 40: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

lpExample;

Prob = lpAssign(c, A, b_L, b_U, x_L, x_U, x_0, ’lpExample’);

Result = lpSolve(Prob);

PrintResult(Result);

Result = qpSolve(Prob);

PrintResult(Result);

%For Mideva - needs to know function names%# call lp_f lp_g lp_H

Result = nlpSolve(Prob);

PrintResult(Result);

lpAssign is used to define the standard Prob structure, which TOMLAB always uses to store all information abouta problem. The three last parameters could be left out. The upper bounds will default be Inf, and the problemname is only used in the printout in PrintResult to make the output nicer to read. If x 0, the initial value, is leftout, an initial point is found by lpSolve solving a Phase I linear programming problem. In this test the given x 0is empty, so a Phase I problem must be solved.

The first four statements defines, solves and prints the result. Additional rows shows how easy it is to use othersolvers in TOMLAB to solve the LP problem, once it is defined in the general TOMLAB structure format. Thesolution of this problem gives the following output to the screen

File: tomlabv2/usersguide/lpTest1.out

=== * * * ================================================== * * *Problem 1: User Problem 1 f_k -26.571428571428569000

f(x_0) 0.000000000000000000

Solver: lpSolve. EXIT=0.Simplex method. Minimum reduced cost.

FuncEv 3 GradEv 0 Iter 3Starting vector x:x_0: 0.000000 0.000000Optimal vector x:x_k: 2.571429 1.714286Lagrange multipliers v. Vector length 4:v_k: 0.000000e+000 0.000000e+000 -1.857143e+000 -1.285714e+000Diff x-x0:

2.571429e+000 1.714286e+000Gradient g_k:g_k: -7.000000e+000 -5.000000e+000Projected gradient gPr: :gPr: 0.000000e+000 0.000000e+000

=== * * * ================================================== * * *

=== * * * ================================================== * * *Problem 1: User Problem 1 f_k -26.571428571428569000

40

Page 41: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

f(x_0) 0.000000000000000000

Solver: qpSolve. EXIT=0. INFORM=1.Active set strategy

Iter 3Starting vector x:x_0: 0.000000 0.000000Optimal vector x:x_k: 2.571429 1.714286Lagrange multipliers v. Vector length 4:v_k: 0.000000e+000 0.000000e+000 1.857143e+000 1.285714e+000Diff x-x0:

2.571429e+000 1.714286e+000Gradient g_k:g_k: -7.000000e+000 -5.000000e+000Projected gradient gPr: :gPr: 0.000000e+000 0.000000e+000

=== * * * ================================================== * * *

=== * * * ================================================== * * *Problem 1: User Problem 1 f_k -26.571428571428573000

f(x_0) 0.000000000000000000

Solver: nlpSolve. EXIT=0. INFORM=4.Fletcher-Leyffer Filter SQP

Iter 1Starting vector x:x_0: 0.000000 0.000000Optimal vector x:x_k: 2.571429 1.714286Lagrange multipliers v. Vector length 4:v_k: 0.000000e+000 0.000000e+000 1.857143e+000 1.285714e+000Diff x-x0:

2.571429e+000 1.714286e+000Gradient g_k:g_k: -7.000000e+000 -5.000000e+000Projected gradient gPr: :gPr: 0.000000e+000 0.000000e+000

=== * * * ================================================== * * *

2.1.2 Several Linear Programs

If the user wants to solve more than one LP, or maybe the same LP but under different conditions, then it ispossible to define the problems in the TOMLAB setup format. This gives full access to all different solvers, menus,driver routines and the GUI.

Using the same example (7) to illustrate this feature gives the Matlab statements

File: tomlabv2/usersguide/lpTest2.m

lpExample;

41

Page 42: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

lpAssign(c, A, b_L, b_U, x_L, x_U, x_0, ’lpExample’, ...’lptest’, 1, [], x_min, x_max);

AddProblemFile(’lptest’,’Users Guide LP test problems’,’lp’);

lpRun;

In this example more parameters are used in the call to lpAssign, which tells lpAssign to define a new TOMLABproblem setup file called lptest. The last two extra parameters x min and x max defines initial plotting axis andare efficient when the user wants to see plots in the GUI and menu programs. Otherwise these parameters are notneeded. The default is to use the lower and upper bounds on the variables, if they have finite values.

The lptest problem file is included as a test file by the call to AddProblemFile and further set as the default filefor LP problems. Calling lpRun without parameters runs the first test problem in the default LP file, i.e. the firstproblem in file lptest, which is the problem just defined. Thus, the output will be exactly the same as in the firstexample in Section 2.1.1.

In the call to lpAssign the parameter after the file name lptest, called nProblem, controls which of two types ofdefinition files are created (See help lpAssign ). Setting this parameter as empty or one, as in this case, defines aprogram structure in the file lptest in which the user easily can insert more test problems. Note the comments inthe created file, which guides the user in how to define a new problem. There are two places to edit. The name ofthe new problem must be added to the probList string matrix definition on row 17-21, and then the actual problemdefinition from row 61 and afterwards. The new problem definition can be loaded by execution of a script, byreading from a stored file or the user can explicitly write the Matlab statements to define the problem in the filelptest.m. For more information on how to edit a setup file, see the Section 2.1.5. The other type of LP definitionfile created by lpAssign is discussed in detail in Section 2.1.4.

When doing this automatic problem setup file generation lpAssign stores the problem in a mat-file with a namecombined by three items: the name of the problem file (lptest), the string ’ P’ and the problem number given asthe input parameter next after the problem file name. In this case lpAssign defines the file lpprob P1.mat.

2.1.3 Solving LP Similar to Optimization Toolbox 2.0

TOMLAB v2.0 is also call compatible with Math Works Optimization TB v2.0. This means that you can use ex-actly the same syntax, but the solver is a TOMLAB solver instead. For linear programs the Math Works Optimization TB v2.0solver is linprog. The TOMLAB linprog solver adds one extra input argument, the Prob structure, and one ex-tra output argument, the Result structure. Both extra parameters are optional, but means that the additionalfunctionality of the TOMLAB LP solver is accessible.

An example of the use of the TOMLAB linprog solver to solve test problem (7) illustrates the basic usage

File: tomlabv2/usersguide/lpTest4.m

lpExample;

% linprog needs linear inequalities and equalities to be given separately% If the problem has both linear inequalities (only upper bounded)% and equalities we can easily detect which ones doing the following calls

ix = b_L==b_U;E = find(ix);I = find(~ix);

[x, fVal, ExitFlag, Out, Lambda] = linprog(c, A(I,:),b_U(I),...A(E,:), b_U(E), x_L, x_U, x_0);

42

Page 43: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

% If the problem has linear inequalites with different lower and upper bounds% the problem can be transformed using the TOMLAB routine cpTransf.% See the example file tomlabv2\examples\testlinprog.m for an example.

fprintf(’\n’);fprintf(’\n’);disp(’Run TOMLAB linprog on LP Example’);fprintf(’\n’);xprinte(A*x-b_U, ’Constraints Ax-b_U ’);xprinte(Lambda.lower, ’Lambda.lower: ’);xprinte(Lambda.upper, ’Lambda.upper: ’);xprinte(Lambda.eqlin, ’Lambda.eqlin: ’);xprinte(Lambda.ineqlin, ’Lambda.ineqlin: ’);xprinte(x, ’x: ’);format compactdisp(’Output Structure’)disp(Out)fprintf(’Function value %30.20f. ExitFlag %d\n’,fVal,ExitFlag);

The results from this test show the same results as previous runs

File: tomlabv2/usersguide/lpTest4.out

linprog (lpSolve): Optimization terminated successfully

Run TOMLAB linprog on LP Example

Constraints Ax-b_U 0.000000e+000 0.000000e+000Lambda.lower: 0.000000e+000 0.000000e+000Lambda.upper: 0.000000e+000 0.000000e+000Lambda.eqlin:Lambda.ineqlin: -1.857143e+000 -1.285714e+000x: 2.571429e+000 1.714286e+000Output Structure

iterations: 3algorithm: ’Simplex method. Minimum reduced cost.’

cgiterations: 0Function value -26.57142857142856900000. ExitFlag 1

2.1.4 Large Sets of Linear Programs

It is easy to setup a problem definition file for a large set of test problems. This feature is illustrated by runninga test where the test problem is disturbed by random noise. The vector c in the objective function are disturbed,and the new problems are defined and stored in the TOMLAB setup file format. To avoid too much output restrictthe large number of test problems to be three.

File: tomlabv2/usersguide/lpTest3.m

LargeNumber=3;

lpExample;

n=length(c);

43

Page 44: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

for i=1:LargeNumbercNew =c + 0.1*(rand(n,1)-0.5); % Add random disturbances to vector c

if i==1% lpAssign defines lplarge.m for LargeNumber testproblems% and stores the first problem in lplarge_P1.matk=[1,LargeNumber];

elsek=i; % lpAssign stores the ith problem in the lplarge_Pi.mat problem file

end

lpAssign(cNew, A, b_L, b_U, x_L, x_U, [], Name,’lplarge’, k);end

% Define lplarge as the default file for LP problems in TOMLAB.

AddProblemFile(’lplarge’,’Large set of randomized LP problems’,’lp’);

runtest(’lpSolve’,0,’lplarge’,1:LargeNumber,0,0,1);

Each problem gets a unique name. In the first iteration, i = 1, lpAssign defines a setup file with three testproblems, and defines the first test problem, stored in lplarge P1.mat. In the other iterations lpAssign just definesthe other mat-files. All together three mat-files are defined: lplarge P1.mat, lplarge P2.mat and lplarge P3.mat.

AddProblemFile adds the new lplarge problem as the default LP test problem in TOMLAB. The runtest testprogram utility runs the selected problems, in this case all three defined. The second zero argument is used if theactual solver has several algorithmic options. In this case the zero refers to the default option in lpSolve, to usethe minimum cost rule as the variable selection rule. The last arguments are used to lower the default output andavoid a pause statement after each problem is solved. The results are shown in the following file listing.

File: tomlabv2/usersguide/lpTest3.out

Solver: lpSolve. Algorithm 0=== * * * ================================================== * * *Problem 1: lptest - 1 f_k -26.501771581492278000=== * * * ================================================== * * *Problem 2: lptest - 2 f_k -26.546357769596234000=== * * * ================================================== * * *Problem 3: lptest - 3 f_k -26.425877951614158000

2.1.5 Editing Problems into an Existing Setup File - LP Example

The step wise description below shows how to edit new problems into an existing LP setup file. The exampleshows how to add one new problem in lp prob.m, the default file for LP problems in TOMLAB. As test examplewe choose the same test example as in the previous sections, problem (7), here called lptest1.

1. Copy File: tomlabv2/testprob/lp prob to e.g. lpnew prob.m in your working directory.

2. Edit lpnew prob.m. Add the problem name, lptest1, to the menu choice:

...

...,’Winston Ex. 4.12 B4. Max || ||. Rewritten’...,’lptest1’...); % MAKE COPIES OF THE PREVIOUS ROW AND CHANGE TO NEW NAMES

if isempty(P)

44

Page 45: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

return;end......

3. There are twelve problems defined in lp prob.m, making thirteen the new problem number. Define theconstraint matrix A, the upper bounds for the constraints b U , the cost vector c as below. If the constraintswould be of equality type then you just define the lower bounds for the constraints b L equal to b U .

...

...elseif P == 13

Name = ’lptest1’;c = [-7 -5]’;A = [ 1 2

4 1 ];b_U = [ 6 12 ]’;x_L = [ 0 0 ]’;x_min = [ 0 0 ]’;x_max = [10 10 ]’;

elsedisp(’lp_prob: Illegal problem number’)pauseName=[];

end......

4. Note that because the file name is changed, the new name must be substituted. There are three places wherethe name should be changed, the function definition in the beginning of the file, the disp statement aboveand the place shown in the following text

...

...if ask==-1 & ~isempty(Prob)

if isstruct(Prob)if ~isempty(Prob.P)

if P==Prob.P & strcmp(Prob.probFile,’lpnew_prob’), return; endend

endend......

5. Save the file properly.

6. Run

AddProblemFile(’lpnew_prob’,’lp_prob with extra user problems’,’lp’);

You could also define the optional parameters B, f min and x 0 as described in the problem definition descriptionin lp prob.m. If B and x 0 are not given, as in this case, a Phase I linear program is solved to an initial feasiblesolution point.

Now lpnew prob.m is one of the TOMLAB setup files and all problems in lpnew prob.m are accessible from the GUI,the menu systems, and the driver routines. The edited file is found in File: tomlabv2/usersguide/lpnew prob .

45

Page 46: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

2.1.6 More on Solving Linear Programs

When the problem is defined using a TOMLAB setup file approach, it is then possible to run the graphical userinterface, menu programs and the multi-solver driver routines. For LP problems the the menu routine lpOpt orthe driver routine lpRun are possible to use. Type Result = lpOpt; or just lpOpt; at the Matlab prompt and themain menu in Figure 11 will be displayed.

Figure 11: The main menu in lpOpt.

Pushing the Choice of Problem File and Problem button followed by the uppermost button will display the menuin Figure 12. Note that lptest1 is added as the last problem.

Push the lptest1 button to choose problem (7) and you will be back in the main menu. Now you can selectoptimization solver by pushing the Choice of optimization algorithm button and choose the routine you wantto use to solve the problem. Back to the main menu you can change the default settings of the optimizationparameters, the output printing level, any convergence tolerance etc. Pushing the Optimize button will run thedriver routine lpRun and the result will be displayed in the Matlab command window. Finally, choose End andthe menu will disappear.

Instead of using the menu system you can solve the problem by a direct call to lpRun from the Matlab promptor as a command in an m-file. This approach could be of great interest in an testing environment. The moststraightforward way of doing it (when the problem is defined in lpnew prob.m) is to give the following call fromthe Matlab prompt:

probNumber = 13;Result = lpRun([], [], [], [], [], probNumber);

46

Page 47: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Figure 12: The problem choice menu in lpOpt.

The arguments not given to lpRun is set to default values, see the lpRun routine description Section 6.2.5 page122. Let us also show how you can give a call by specifying some of the other arguments. Assume that you wantto solve the problem with the following requirements:

• Start in the point (1, 1).

• No printing output neither in the driver routine nor in the solver.

• Use Math Works Optimization TB v1.5 solver lp.

Then the call to lpRun should be:

Solver = ’lp’;Prob = probInit(’lpnew_prob’,13);PriLev = 0;Prob.x_0 = [1;1];Prob.optParam.PriLev = 0;

Result = lpRun(Solver, Prob, [], PriLev);

To have the result of the optimization displayed call the routine PrintResult:

47

Page 48: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

PrintResult(Result);

Figure 13: The problem file choice menu in lpOpt.

Assume that the problem to be solved is defined in another TOMLAB setup file, say ownlp prob.m, which is notthe default setup file. Now, when you push the Choice of Problem File and Problem button in the main menu oflpOpt, Figure 11, a menu similar to Figure 13 is displayed. Choose ownlp My Own Linear Programming Problemsand proceed as described above.

The following example shows how to call lpRun to solve the first problem in ownlp prob.m. Assume the samerequirements as itemized above.

Solver = ’lp’;probFile = ’ownlp_prob’;Prob = probInit(probFile,1);PriLev = 0;Prob.x_0 = [1;1];Prob.optParam.PriLev = 0;

Result = lpRun(Solver, Prob, [], PriLev, probFile);

2.2 Quadratic Programming Problems

The general formulation in TOMLAB for a quadratic programming problem is

minx

f(x) = 12x

TFx+ cTx

s/txL ≤ x ≤ xU ,bL ≤ Ax ≤ bU

(8)

where c, x, xL, xU ∈ Rn, F ∈ R

n×n, A ∈ Rm1×n, and bL, bU ∈ R

m1 . Equality constraints are defined by setting thelower bound equal to the upper bound, i.e. for constraint i: bL(i) = bU (i). Fixed variables are handled the sameway.

Quadratic programs are normally solved with a standard active-set method implemented in qpSolve, which explic-itly treats both inequality and equality constraints, as well as lower and upper bounds on the variables (simplebounds). It converges to a local minimum for indefinite quadratic programs. It is also possible to choose a generalconstrained solver or the SOL routine QPOPT using a MEX-file interface. QPOPT from SOL is in TOMLABcalled QPOPTSOL, because of the name conflict with the menu program for QP in TOMLAB called qpOpt. Tochoose alternative solvers, the multi-driver routine qpRun is called.

48

Page 49: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

To illustrate the solution of QPs consider the simple quadratic programming test problem

minx

f(x) = 4x21 + x1x2 + 4x2

2 + 3x1 − 4x2

s/t x1 + x2 ≤ 5x1 − x2 = 0x1 ≥ 0x2 ≥ 0,

(9)

named QP Example. The following statements define this problem in Matlab

File: tomlabv2/usersguide/qpExample.m

Name = ’QP Example’; % File qpExample.mF = [ 8 2 % Matrix F in 1/2 * x’ * F * x + c’ * x

2 8 ];c = [ 3 -4 ]’; % Vector c in 1/2 * x’ * F * x + c’ * xA = [ 1 1 % Constraint matrix

1 -1 ];b_L = [-inf 0 ]’; % Lower bounds on the linear constraintsb_U = [ 5 0 ]’; % Upper bounds on the linear constraintsx_L = [ 0 0 ]’; % Lower bounds on the variablesx_U = [ inf inf ]’; % Upper bounds on the variablesx_0 = [ 0 1 ]’; % Starting pointx_min = [-1 -1 ]; % Plot region lower bound parametersx_max = [ 6 6 ]; % Plot region upper bound parameters

2.2.1 A Quick Quadratic Programming solution

The quickest way to solve this problem is to define the following Matlab statements

File: tomlabv2/usersguide/qpTest1.m

qpExample;

Prob = qpAssign(F, c, A, b_L, b_U, x_L, x_U, x_0, ’qpExample’);

Result = qpSolve(Prob);

PrintResult(Result);

The solution of this problem gives the following output to the screen

File: tomlabv2/usersguide/qpTest1.out

=== * * * ================================================== * * *Problem 1: User Problem 1 f_k -0.025000000000000022

sum(|constr|) 0.000000000000000007f(x_k) + sum(|constr|) -0.025000000000000015

f(x_0) 0.000000000000000000

Solver: qpSolve. EXIT=0. INFORM=1.Active set strategy

Iter 4Starting vector x:

49

Page 50: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

x_0: 0.000000 0.000000Optimal vector x:x_k: 0.050000 0.050000Lagrange multipliers v. Vector length 4:v_k: 0.000000e+000 0.000000e+000 0.000000e+000 3.500000e+000Diff x-x0:

5.000000e-002 5.000000e-002Gradient g_k:g_k: 3.500000e+000 -3.500000e+000Projected gradient gPr: :gPr: 8.881784e-016 -8.881784e-016Eigenvalues of Hessian at x_keig: 6.000000 10.000000

=== * * * ================================================== * * *

qpAssign is used to define the standard Prob structure, which TOMLAB always uses to store all information abouta problem. The three last parameters could be left out. The upper bounds will default be Inf, and the problemname is only used in the printout in PrintResult to make the output nicer to read. If x 0, the initial value, is leftout, a initial point is found by qpSolve solving a Phase I linear programming problem calling the TOMLAB lpSolvesolver. In fact, the output shows that the given x0 = (0,−1)T was rejected because it was infeasible, and insteada Phase I solution lead to the initial point x0 = (0, 0)T .

2.2.2 Several Quadratic Programs

If the user wants to solve more than one QP, or maybe the same QP but under different conditions, then it ispossible to define the problems in the TOMLAB setup format. This gives full access to all different solvers, menus,driver routines and the GUI.

We use the same example (9) to illustrate this feature

File: tomlabv2/usersguide/qpTest2.m

qpExample;

qpAssign(F, c, A, b_L, b_U, x_L, x_U, x_0, ’qpExample’, ...’qptest’,1,[],x_min,x_max);

AddProblemFile(’qptest’,’Users Guide QP test problems’,’qp’);

qpRun;

The output will be exactly the same as in the first example. The qptest is set as the default file, so calling qpRunwithout parameters runs the first test problem in qptest, i.e. the problem we just defined. In this example moreparameters are used in the call to qpAssign, which tells qpAssign to define a new TOMLAB problem setup filecalled qptest. The last two extra parameters x min and x max defines initial plotting axis and are efficient whenthe user wants to see plots in the GUI and menu programs. Otherwise these parameters are not needed. Thedefault is to use the lower and upper bounds on the variables, if they have finite values.

The qptest problem file is included as a test file by the call to AddProblemFile and further set as the default filefor QP problems. Calling qpRun without parameters runs the first test problem in the default QP file, i.e. thefirst problem in file qptest, which is the problem just defined. Thus, the output will be exactly the same as in thefirst example in Section 2.2.1.

In the call to qpAssign the parameter after the file name qptest, called nProblem, controls which of two types ofdefinition files are created (See help qpAssign ). Setting this parameter as empty or one, as in this case, defines an

50

Page 51: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

open structure in qptest where the user easily can insert more test problems. Note the comments in the created file,which guides the user in how to define a new problem. There are two places to edit. The name of the new problemmust be added to the probList string matrix definition on row 17-21, and then the actual problem definition fromrow 61 and afterwards. The new problem definition can be loaded by execution of a script, by reading from astored file or the user can explicitly write the Matlab statements to define the problem in the file qptest.m. Formore information on how to edit a QP setup file, see the Section 2.2.6. The other type of QP definition file createdby qpAssign is discussed in detail in Section 2.2.4.

When doing this automatic problem setup file generation qpAssign stores the problem in a mat-file with a namecombined by three items, the name of the problem file (qptest), the string ’ P’ and the problem number given asthe input parameter next after the problem file name. In this case qpAssign defines the file qpprob P1.mat.

2.2.3 Solving QP similar to Optimization Toolbox 2.0

TOMLAB v2.0 is also call compatible with Math Works Optimization TB v2.0. This means that you can use ex-actly the same syntax, but the solver is a TOMLAB solver instead. For quadratic programs the Math Works Optimization TB v2.0solver is quadprog. The TOMLAB quadprog solver adds one extra input argument, the Prob structure, and oneextra output argument, the Result structure. Both extra parameters are optional, but means that the additionalfunctionality of the TOMLAB QP solver is accessible.

An example of the use of the TOMLAB quadprog solver to solve test problem (9) illustrates the basic usage

File: tomlabv2/usersguide/qpTest4.m

qpExample;

% quadprog needs linear equalities and equalities to be given separately% If the problem has both linear inequalities (only upper bounded)% and equalities we can easily detect which ones doing the following calls

ix = b_L==b_U;E = find(ix);I = find(~ix);

[x, fVal, ExitFlag, Out, Lambda] = quadprog(F, c, A(I,:),b_U(I),...A(E,:), b_U(E), x_L, x_U, x_0);

% If A has linear inequalites with different lower and upper bounds% the problem can be transformed using the TOMLAB routine cpTransf.% See the example file tomlabv2\examples\testquadprog.m for an example.

fprintf(’\n’);fprintf(’\n’);disp(’Run TOMLAB quadprog on QP Example’);fprintf(’\n’);xprinte(A*x-b_U, ’Constraints Ax-b_U ’);xprinte(Lambda.lower, ’Lambda.lower: ’);xprinte(Lambda.upper, ’Lambda.upper: ’);xprinte(Lambda.eqlin, ’Lambda.eqlin: ’);xprinte(Lambda.ineqlin, ’Lambda.ineqlin: ’);xprinte(x, ’x: ’);format compactdisp(’Output Structure’)disp(Out)fprintf(’Function value %30.20f. ExitFlag %d\n’,fVal,ExitFlag);

The restricted problem formulation in Math Works Optimization TB v2.0 sometimes makes it necessary to trans-

51

Page 52: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

form the problem. See the comments in the above example and the test problem file tomlabv2/examples/testquadprog.m. The results from this test show the same results as previous runs

File: tomlabv2/usersguide/qpTest4.out

Run TOMLAB quadprog on QP Example

Constraints Ax-b_U -4.900000e+000 -6.938894e-018Lambda.lower: 0.000000e+000 0.000000e+000Lambda.upper: 0.000000e+000 0.000000e+000Lambda.eqlin: -3.500000e+000Lambda.ineqlin: 0.000000e+000x: 5.000000e-002 5.000000e-002Output Structure

iterations: 4algorithm: ’Active set strategy’

cgiterations: []firstorderopt: []

Function value -0.02500000000000002200. ExitFlag 1

2.2.4 Large Sets of Quadratic Programs

It is easy to setup a problem definition file for a large set of test problems. This feature is illustrated by running atest where the test problem is disturbed by random noise. The matrix F and the vector c in the objective functionare disturbed, and the new problems are defined and stored in the TOMLAB setup file format. To avoid too muchoutput restrict the large number of test problems to be three.

File: tomlabv2/usersguide/qpTest3.m

LargeNumber=3;

qpExample;

n=length(c);

for i=1:LargeNumbercNew =c + 0.1*(rand(n,1)-0.5); % Generate random disturbances to vector cFNew =F + 0.1*(rand(n,n)-0.5); % Generate random disturbances to matrix F

if i==1% qpAssign defines qplarge.m for LargeNumber testproblems% and stores the first problem in qplarge_P1.matk=[1,LargeNumber];

elsek=i; % qpAssign stores the ith problem in the qplarge_Pi.mat problem file

end

qpAssign(FNew, cNew, A, b_L, b_U, x_L, x_U, [], Name,’qplarge’, k);end

% Define qplarge as the default file for QP problems in TOMLAB.

AddProblemFile(’qplarge’,’Large set of randomized QP problems’,’qp’);

runtest(’qpSolve’,0,’qplarge’,1:LargeNumber,0,0,1);

52

Page 53: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Each problem gets a unique name. In the first iteration, i = 1, qpAssign defines a setup file with three testproblems, and defines the first test problem, stored in qplarge P1.mat. In the other iterations qpAssign just definesthe other mat-files. All together three mat-files are defined: qplarge P1.mat, qplarge P2.mat and qplarge P3.mat.

AddProblemFile adds the new qplarge problem as the default QP test problem in TOMLAB. The runtest testprogram utility runs the selected problems, in this case all three defined. The second zero argument is used ifthe actual solver has several algorithmic options. In this case the zero refers to the default option, and the onlyoption, in qpSolve. The last arguments are used to lower the default output and avoid a pause statement aftereach problem is solved. The results are shown in the following file listing.

File: tomlabv2/usersguide/qpTest3.out

Solver: qpSolve. Algorithm 0

Call TOMLAB routine qpSolve=== * * * ================================================== * * *Problem 1: QP Example - 1 f_k -0.027601113262707047

sum(|constr|) 0.000000000000000007f(x_k) + sum(|constr|) -0.027601113262707040

Call TOMLAB routine qpSolve=== * * * ================================================== * * *Problem 2: QP Example - 2 f_k -0.021761545333908644

sum(|constr|) 0.000000000000000007f(x_k) + sum(|constr|) -0.021761545333908637

Call TOMLAB routine qpSolve=== * * * ================================================== * * *Problem 3: QP Example - 3 f_k -0.023593882783075164

sum(|constr|) 0.000000000000000007f(x_k) + sum(|constr|) -0.023593882783075157

2.2.5 Another Direct Approach to a QP Solution

The following example shows yet another way to define and solve the quadratic programming problem (9) by adirect call to the routine qpSolve. The approach is define a default Prob structure calling ProbDef, and then justinsert values into the fields.

Prob = ProbDef;

Prob.QP.F = [ 8 2 % Hessian.2 8 ];

Prob.QP.c = [ 3 -4 ]’; % Constant vector.Prob.x_L = [ 0 0 ]’; % Lower bounds on the variablesProb.x_U = [inf inf]’; % Upper bounds on the variablesProb.x_0 = [ 0 1 ]’; % Starting point

Prob.A = [ 1 1 % Constraint matrix1 -1 ];

Prob.b_L = [-inf 0 ]’; % Lower bounds on the constraintsProb.b_U = [ 5 0 ]’; % Upper bounds on the constraints

Result = qpSolve(Prob);

53

Page 54: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

A similar approach is possible when solving all types of problems in TOMLAB.

2.2.6 Editing Problems into an Existing Setup File - QP Example

The step wise description below shows how to edit new problems into an existing QP setup file. The exampleshows how to add one new problem in qp prob.m, the default file for QP problems in TOMLAB, As test examplewe choose the same test example as in the previous sections, problem (9), named QP EXAMPLE.

1. Copy File: tomlabv2/testprob/qp prob to e.g. qpnew prob.m in your working directory.

2. Edit qpnew prob.m. Add the problem name, QP Example, to the menu choice:

...

...,’Bazaara IQP 9.29b pg 405. F singular’...,’Bunch and Kaufman Indefinite QP’...,’QP EXAMPLE’...); % MAKE COPIES OF THE PREVIOUS ROW AND CHANGE TO NEW NAMES

if isempty(P)return;

end......

3. There are fourteen problems defined in qp prob.m, making fifteen the new problem number. Add the followingin qpnew prob.m after the last already existing problem:

...

...elseif P==15

Name=’QP EXAMPLE’;F = [ 8 2 % Hessian

2 8 ];c = [ 3 -4 ]’;A = [ 1 1 % Constraint matrix

1 -1 ];b_L = [-inf 0 ]’; % Lower bounds on the constraintsb_U = [ 5 0 ]’; % Upper bounds on the constraintsx_L = [ 0 0 ]’; % Lower bounds on the variablesx_U = [ inf inf ]’; % Upper bounds on the variablesx_0 = [ 0 1 ]’; % Starting pointx_min=[-1 -1 ]; % Plot region parametersx_max=[ 6 6 ]; % Plot region parameters

elsedisp(’qp_prob: Illegal problem number’)pauseName=[];

end......

4. Note that because the file name is changed, the new name must be substituted. There are three places wherethe name should be changed, the function definition in the beginning of the file, the disp statement aboveand the place shown in the following text

54

Page 55: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

...

...if ask==-1 & ~isempty(Prob)

if isstruct(Prob)if ~isempty(Prob.P)

if P==Prob.P & strcmp(Prob.probFile,’qpnew_prob’), return; endend

endend......

5. Save the file properly.

6. Run

AddProblemFile(’qpnew_prob’,’qp_prob with extra user problems’,’qp’);

Now qpnew prob.m is one of the TOMLAB setup files and all problems in qpnew prob.m are accessible from theGUI, the menu systems, and the driver routines. The edited file is found in File: tomlabv2/usersguide/qpnew prob.

2.2.7 More on Solving Quadratic Programs

When the problem is defined using a TOMLAB setup file approach, it is then possible to run the graphical userinterface, menu programs and the multi-solver driver routines. For QP problems the the menu routine qpOpt orthe driver routine qpRun are possible to use. Type Result = qpOpt; or just qpOpt; at the Matlab prompt. Theusage is very similar to the solution of Linear Programs, see the discussion and figures in Section 2.2.7.

2.3 Mixed-Integer Programming Problems

This section describes how to solve mixed-integer programming problems efficiently using TOMLAB. The generalformulation in TOMLAB for a mixed-integer program (MIP) is

minx

f(x) = cTx

s/txL ≤ x ≤ xU ,bL ≤ Ax ≤ bU , xj ∈ N ∀j ∈I

(10)

where c, x, xL, xU ∈ Rn, A ∈ R

m1×n, and bL, bU ∈ Rm1 . The variables x ∈ I, the index subset of 1, ..., n are

restricted to be integers. Equality constraints are defined by setting the lower bound equal to the upper bound,i.e. for constraint i: bL(i) = bU (i).

Mixed-integer programs are normally solved using the TOMLAB routine mipSolve that implements a standardbranch-and-bound algorithm, see Nemhauser and Wolsey [47, chap. 8]. When dual feasible solutions are available,mipSolve is using the TOMLAB dual simplex solver DualSolve to solve subproblems, which is significantly fasterthan using an ordinary linear programming solver, like the TOMLAB lpSolve. Another alternative solver is thecutting plane routine cutplane. Available is also a MEX-file interface to XPRESS/MP. To choose alternativesolvers, the multi-driver routine mipRun is called.

mipSolve also implements user defined priorities for variable selection, and different tree search strategies. For 0/1- knapsack problems a round-down primal heuristic is included.

To illustrate the solution of MIPs consider the simple knapsack 0/1 test problem Weingartner 1, which has 28binary variables and two knapsacks. The problem is defined

minx

cTx

s/t0 ≤ x ≤ 1,

Ax = b,

(11)

55

Page 56: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

where b = (600, 600)T ,

c = −( 1898 440 22507 270 14148 3100 4650 30800 615 4975 1160 4225 510 11880479 440 490 330 110 560 24355 2885 11748 4550 750 3720 1950 10500 )T

and the A matrix is

45 0 85 150 65 95 30 0 170 0 40 25 20 0 0 25 0 0 25 0165 0 85 0 0 0 0 10030 20 125 5 80 25 35 73 12 15 15 40 5 10 10 12 10 9 0 2060 40 50 36 49 40 19 150

The following statements define this problem in Matlab

File: tomlabv2/usersguide/mipExample.m

Name=’Weingartner 1 - 2/28 0-1 knapsack’;% Problem formulated as a minimum problemA = [ 45 0 85 150 65 95 30 0 170 0 ...

40 25 20 0 0 25 0 0 25 0 ...165 0 85 0 0 0 0 100 ; ...30 20 125 5 80 25 35 73 12 15 ...15 40 5 10 10 12 10 9 0 20 ...60 40 50 36 49 40 19 150];

b_U = [600;600]; % // 2 knapsack capacitiesc = [1898 440 22507 270 14148 3100 4650 30800 615 4975 ...1160 4225 510 11880 479 440 490 330 110 560 ...24355 2885 11748 4550 750 3720 1950 10500]’; % 28 weights

% Make problem on standard form for mipSolve

[m,n]=size(A);

A=[A eye(m,m)];% Change sign to make minimum problemc=[-c;zeros(m,1)];

[mm nn]=size(A);x_L=zeros(nn,1);x_U=[ones(n,1);b_U];x_0=[zeros(n,1);b_U];

fprintf(’Knapsack problem. Variables %d. Knapsacks %d\n’,n,m);fprintf(’Making standard form with %d variables\n’,nn);

% All original variables should be integer, but also slacks in this caseIntVars=nn; % Could also be set as: IntVars=1:nn;

n = length(c);b_L = b_U;

x_min=x_L;x_max=x_U;

f_opt=-141278;f_Low=-1E7; % f_Low <= f_optimal must hold

The quickest way to solve this problem is to define the following Matlab statements

56

Page 57: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

File: tomlabv2/usersguide/mipTest1.m

mipExample;

nProblem = 7; % Use the same problem number as in mip_prob.mfIP = []; % Do not use any prior knowledgexIP = []; % Do not use any prior knowledgesetupFile = []; % Just define the Prob structure, not any permanent setup filex_opt = []; % The optimal integer solution is not knownVarWeight = []; % No variable priorities, largest fractional part will be usedKNAPSACK = 0; % First run without the knapsack heuristic

Prob = mipAssign(c, A, b_L, b_U, x_L, x_U, x_0, Name, setupFile, nProblem,...IntVars, VarWeight, KNAPSACK, fIP, xIP, ...f_Low, x_min, x_max, f_opt, x_opt);

% Depth First, then Breadth search (Default is Depth First)Prob.Solver.Alg=2;

% Must increase number of iterations from default 500Prob.optParam.MaxIter=5000;

Result = mipSolve(Prob);

% Add priorities on the variables

VarWeight = c;

Prob = mipAssign(c, A, b_L, b_U, x_L, x_U, x_0, Name, setupFile, nProblem,...IntVars, VarWeight, KNAPSACK, fIP, xIP, ...f_Low, x_min, x_max, f_opt, x_opt);

% NOTE. Because Prob is already defined, one could skip the call to mipAssign% and instead directly just set:% Prob.MIP.VarWeight=c;% and run mipSolve

% Depth First, then Breadth search (Default is Depth First)Prob.Solver.Alg=2;

% Must increase number of iterations from default 500Prob.optParam.MaxIter=5000;

Result = mipSolve(Prob);

% Use the knapsack heuristic, but not priorities

KNAPSACK = 1;VarWeight = [];

Prob = mipAssign(c, A, b_L, b_U, x_L, x_U, x_0, Name, setupFile, nProblem,...IntVars, VarWeight, KNAPSACK, fIP, xIP, ...f_Low, x_min, x_max, f_opt, x_opt);

% NOTE. Because Prob is already defined, one could skip the call to mipAssign% and instead directly just set:

57

Page 58: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

% Prob.MIP.KNAPSACK=1;% Prob.MIP.VarWeight=[];% and run mipSolve

% Depth First, then Breadth search (Default is Depth First)Prob.Solver.Alg=2;

Result = mipSolve(Prob);

% Now use both the knapsack heuristic and priorities

VarWeight = c;KNAPSACK = 1;

Prob = mipAssign(c, A, b_L, b_U, x_L, x_U, x_0, Name, setupFile, nProblem,...IntVars, VarWeight, KNAPSACK, fIP, xIP, ...f_Low, x_min, x_max, f_opt, x_opt);

% NOTE. Because Prob is already defined, one could skip the call to mipAssign% and instead directly just set:% Prob.MIP.KNAPSACK=1;% Prob.MIP.VarWeight=c;% and run mipSolve

% Depth First, then Breadth search (Default is Depth First)Prob.Solver.Alg=2;

Result = mipSolve(Prob);

To make it easier to see all variable settings, the first lines define the needed variables. Several of them arejust empty arrays, and could be directly set as empty in the call to mipAssign. mipAssign is used to define thestandard Prob structure, which TOMLAB always uses to store all information about a problem. After mipAssignhas defined the structure Prob it is then easy to set or change fields in the structure. The solver mipSolve is usingthree different strategies to search the branch-and-bound tree. The default is the Depth first strategy, which isalso the result if setting the field Solver.Alg as zero. Setting the field as one gives the Breadth first strategy andsetting it as two gives the the Depth first, then breadth search strategy. In the example our choice is the laststrategy. The number of iterations might be high, so we must increase the maximal number of iterations, the fieldoptParam.MaxIter.

Our test shows two ways to improve the convergence of MIP problems. One is to define a priority order in whichthe different non-integer variables are selected as variables to branch on. The field MIP.VarWeight is used toset priority numbers for each variable. Note that the lower the number, the higher the priority. In our test casethe coefficients of the objective function is used as priority weights. The other way to improve convergence is touse a heuristic. For binary variables a simple knapsack heuristic is implemented in mipSolve. Setting the fieldMIP.KNAPSACK as true instructs mipSolve to use the heuristic.

Running the four different tests on the knapsack problem gives the following output to the screen

File: tomlabv2/usersguide/mipTest1.out

mipTest1Knapsack problem. Variables 28. Knapsacks 2Making standard form with 30 variablesBranch and bound. Depth First, then Breadth.

--- Branch & Bound converged!!! ITER = 892

Optimal Objective function = -141278.0000000002900000x: 0 0 1 -0 1 1 1 1 0 1 0 1 1

58

Page 59: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

0 0 0 0 1 0 1 0 1 1 0 1 05 6

B: 0 0 -1 0 -1 -1 -1 -1 1 -1 0 -1 -1 -1 0 0 0 0 -1 0 -1 0 -1 -1 0 0 0 0 0 0Branch and bound. Depth First, then Breadth. Priority Weighting.

--- Branch & Bound converged!!! ITER = 470

Optimal Objective function = -141277.9999999998300000x: 0 0 1 -0 1 1 1 1 0 1 0 1 1

0 0 0 0 1 0 1 0 1 1 0 1 05 6

B: 0 0 -1 0 -1 -1 -1 -1 0 -1 0 -1 -1 -1 0 0 0 0 -1 0 -1 0 -1 -1 0 0 0 0 0 0Branch and bound. Depth First, then Breadth. Knapsack Heuristic.

Found new BEST Knapsack. Nodes left 0. Nodes deleted 0.Best IP function value -139508.0000000000000000Found new BEST Knapsack. Nodes left 1. Nodes deleted 0.Best IP function value -140768.0000000000000000Found new BEST Knapsack. Nodes left 4. Nodes deleted 0.Best IP function value -141278.0000000000000000

--- Branch & Bound converged!!! ITER = 138

Optimal Objective function = -141278.0000000002900000x: 0 0 1 -0 1 1 1 1 0 1 0 1 1 1 0

0 0 0 1 0 1 0 1 1 0 1 0 0 5 6B: 0 0 -1 0 -1 -1 -1 -1 1 -1 0 -1 -1 -1 0 0 0 0 -1 0 -1 0 -1 -1 0 0 0 0 0 0Branch and bound. Depth First, then Breadth. Knapsack Heuristic. Priority Weighting.

Found new BEST Knapsack. Nodes left 0. Nodes deleted 0.Best IP function value -139508.0000000000000000Found new BEST Knapsack. Nodes left 1. Nodes deleted 0.Best IP function value -140768.0000000000000000Found new BEST Knapsack. Nodes left 4. Nodes deleted 0.Best IP function value -141278.0000000000000000

--- Branch & Bound converged!!! ITER = 94

Optimal Objective function = -141278.0000000000000000x: 0 0 1 0 1 1 1 1 0 1 0 1 1 1 0

0 0 0 1 0 1 0 1 1 0 1 0 0 5 6B: 1 1 -1 1 -1 -1 -1 -1 1 -1 0 -1 -1 -1 1 1 1 1 -1 1 -1 0 -1 -1 1 0 0 1 1 1diary off

Note that there is a large difference in the number of iterations if the additional heuristic and priorities are used.Similar results are obtained if running the other two tree search strategies.

2.3.1 Large Sets of Mixed-Integer Programs

It is easy to setup a problem definition file for a large set of mixed-integer problems. The approach is similar tothe one for Linear Programs discussed in Section 2.1.4, the main difference is that mipAssign is used instead oflpAssign.

2.3.2 More on Solving Mixed-Integer Programs

When the problem is defined using a TOMLAB setup file approach, it is then possible to run the graphical userinterface, menu programs and the multi-solver driver routines. For MIP problems the the menu routine mipOpt or

59

Page 60: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

the driver routine mipRun are possible to use. Type Result = mipOpt; or just mipOpt; at the Matlab prompt andthe main menu will be displayed. The use of the menu system is similar to the LP menu system, see Section 2.1.6.

Instead of using the menu system you can solve the problem by a direct call to mipRun from the Matlab promptor as a command in an m-file. This approach could be of great interest in an testing environment. The moststraightforward way of doing it (when the problem is defined in mipnew prob.m) is to give the following call fromthe Matlab prompt:

probNumber = 7;Result = mipRun([], [], [], [], [], probNumber);

The arguments not given to mipRun is set to default values, see the mipRun routine description Section 6.2.7 page124. Assume the problem should be solved with the following requirements:

• No printing output neither in the driver routine nor in the solver.

• Use solver mipSolve.

Then the call to mipRun should be:

Solver = ’mipSolve’;Prob = probInit(’mipnew_prob’,7);PriLev = 0;Prob.optParam.PriLev = 0;

Result = mipRun(Solver, Prob, [], PriLev);

To have the result of the optimization displayed call the routine PrintResult:

PrintResult(Result);

Assume that the problem to be solved is defined in another TOMLAB setup file, say ownmip prob.m, which is notthe default setup file. The following example shows how to callmipRun to solve the first problem in ownmip prob.m.Assume the same requirements as itemized above.

Solver = ’mipSolve’;probFile = ’ownmip_prob’;Prob = probInit(probFile,1);PriLev = 0;Prob.x_0 = [1;1];Prob.optParam.PriLev = 0;

Result = mipRun(Solver, Prob, [], PriLev, probFile);

2.4 Performance Tests on Linear Programming Solvers

We have made tests to compare the efficiency of different solvers on medium size LP problems. The solver lpSolve,two algorithms implemented in the solver linprog from Optimization Toolbox 2.0 [15] and the commercial Fortransolvers MINOS and QPOPT are compared. In all test cases the solvers converge to the same solution. The resultsare presented in five tables

Table 29, Table 30, Table 31, Table 32 and Table 33. The problem dimensions and all elements in (18) are chosenrandomly. Since the simplex algorithm in linprog does not return the number of iterations as output, these figurescould not be presented. lpSolve has been run with two selection rules; Bland’s cycling prevention rule and theminimum cost rule. The minimum cost rule is the obvious choice, because lpSolve handles most cycling caseswithout problems, and also tests on cycling, and switches to Bland’s rule in case of emergency (does not seem tooccur). But it was interesting to see how much slower Bland’s rule was.

60

Page 61: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

The results in Table 29 show that problems with about 200 variables and 150 inequality constraints are solved bylpSolve fast and efficient. When comparing elapsed computational time for 20 problems, it is clear that lpSolve ismuch faster then the corresponding simplex algorithm implemented in the linprog solver. In fact lpSolve, with theminimum cost selection rule, is more than five times faster, a remarkable difference. lpSolve is also more than twiceas fast as the other algorithm implemented in linprog, a primal-dual interior-point method aimed for large-scaleproblems [15]. There is a penalty about a factor of three to choose Bland’s rule to prevent cycling in lpSolve. Thesolvers written in Fortran, MINOS and QPOPT, of course run much faster, but the iteration count show thatlpSolve converges as fast as QPOPT and slightly better than MINOS. The speed-up is a factor of 35 when runningQPOPT using the MEX-file interface.

Table 29: Computational results on randomly generated medium size LP problems for four different routines. Iteris the number of iterations and Time is the elapsed time in seconds on a Dell Latitude CPi 266XT running Matlab5.3. The lpS solver is the TOMLAB lpSolve, and it is run with both Bland’s selection rule (iterations Itb, timeTb) and with the minimum cost selection rule (iterations Itm, time Tm). The linprog solver in the OptimizationToolbox 2.0 implements two different algorithms, a medium-scale simplex algorithm (time Tm) and a large-scaleprimal-dual interior-point method (iterations Itl, time Tl). The number of variables, n, the number of inequalityconstraints, m, the objective function coefficients, the linear matrix and the right hand side are chosen randomly.The last row shows the mean value of each column.

n m lpS lpS Minos qpopt linprog lpS lpS Minos qpopt linprog linprog

Itb Itm Iter Iter Itl Tb Tm Time T ime Tm Tl

128 32 37 12 10 11 16 1.05 0.61 0.33 0.31 9.06 1.14129 60 8 10 10 9 17 0.63 0.59 0.24 0.21 9.20 2.07125 45 8 9 16 7 14 0.57 0.59 0.35 0.32 8.20 1.3481 65 27 5 7 4 12 1.30 0.54 0.23 0.21 3.51 1.38102 40 25 9 12 8 12 1.00 0.60 0.39 0.33 5.26 1.0196 33 13 7 6 8 11 0.65 0.41 0.34 0.32 4.72 0.84110 61 29 10 9 9 15 1.38 0.66 0.25 0.33 6.34 1.73113 27 25 8 161 8 10 0.87 0.50 0.41 0.34 6.72 0.77127 58 16 9 13 8 14 0.91 0.58 0.26 0.34 8.58 1.8285 58 10 7 7 7 14 0.68 0.59 0.25 0.21 3.70 1.45103 31 15 7 9 6 12 0.69 0.52 0.35 0.33 5.39 0.87101 41 22 9 11 9 11 0.87 0.56 0.36 0.22 5.20 0.9883 41 9 6 7 7 12 0.54 0.36 0.38 0.33 3.55 0.98118 39 28 9 8 8 13 0.89 0.57 0.36 0.34 7.23 1.1492 33 13 8 8 7 12 0.63 0.53 0.23 0.33 4.33 0.90110 46 21 7 15 6 13 0.81 0.46 0.25 0.34 6.37 1.2682 65 25 6 6 5 15 1.21 0.51 0.38 0.22 3.41 1.63104 29 6 6 10 4 11 0.47 0.36 0.23 0.34 5.52 0.8583 48 28 8 10 10 13 1.13 0.50 0.24 0.35 3.53 1.1590 50 8 4 4 3 11 0.44 0.35 0.24 0.23 4.13 1.18

103 45 19 8 17 7 13 0.84 0.52 0.30 0.30 5.70 1.23

In Table 30 a similar test is shown, running 20 problems with about 100 variables and 50 inequality constraints.The picture is the same, but the time difference, a factor of five, between lpSolve and the Fortran solvers are notso striking for these lower dimensional problems. lpSolve is now more than nine times faster than the simplexalgorithm in linprog and twice as fast as the primal-dual interior-point method in linprog.

A similar test on larger dense problems, running 20 problems with about 500 variables and 240 inequality con-straints, shows no benefit in using the primal-dual interior-point method in linprog, see Table 33. In that testlpSolve is more than five times faster, and 15 times faster than the simplex algorithm in linprog. Still it is about35 times faster to use the MEX-file interfaces.

In conclusion, looking at the summary for all tables collected in Table 34, for dense problems the commercial LPsolvers in Optimization Toolbox offers no advantage compared to the TOMLAB solvers. It is clear that if speed iscritical, the availability of Fortran solvers callable from Matlab using the MEX-file interfaces in TOMLAB is veryimportant, but still the TOMLAB Matlab solvers are very compatible in speed.

61

Page 62: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Table 30: Computational results on randomly generated medium size LP problems for four different routines. Iteris the number of iterations and Time is the elapsed time in seconds on a Dell Latitude CPi 266XT running Matlab5.3. The lpS solver is the TOMLAB lpSolve, and it is run with both Bland’s selection rule (iterations Itb, timeTb) and with the minimum cost selection rule (iterations Itm, time Tm). The linprog solver in the OptimizationToolbox 2.0 implements two different algorithms, a medium-scale simplex algorithm (time Tm) and a large-scaleprimal-dual interior-point method (iterations Itl, time Tl). The number of variables, n, the number of inequalityconstraints, m, the objective function coefficients, the linear matrix and the right hand side are chosen randomly.The last row shows the mean value of each column.

n m lpS lpS Minos qpopt linprog lpS lpS Minos qpopt linprog linprog

Itb Itm Iter Iter Itl Tb Tm Time T ime Tm Tl

228 132 32 10 17 12 22 3.41 1.56 0.49 0.39 38.66 11.51191 164 20 9 9 10 18 3.12 1.85 0.49 0.26 24.91 12.50212 155 63 16 30 16 19 7.90 2.76 0.54 0.41 33.36 12.57185 158 53 25 16 16 18 6.86 4.00 0.38 0.43 23.88 11.29222 168 35 12 0 12 21 5.38 2.56 0.64 0.42 40.13 17.78207 162 10 8 6 7 21 1.91 1.69 0.51 0.27 33.74 15.66229 130 42 12 21 19 21 4.31 1.81 0.42 0.44 44.53 11.69213 136 56 6 21 6 19 6.02 1.19 0.51 0.39 36.54 11.07227 146 95 19 33 20 23 10.91 2.94 0.45 0.45 44.84 15.82192 150 25 6 13 5 16 3.22 1.26 0.53 0.27 27.07 10.79195 155 12 8 9 7 22 2.19 1.76 0.52 0.39 27.40 14.76221 160 30 12 10 11 22 4.66 2.41 0.59 0.43 36.95 18.00183 144 61 9 9 10 20 7.08 1.62 0.37 0.39 22.34 11.22200 165 19 10 0 14 19 3.27 2.22 0.61 0.42 27.94 14.43199 137 16 6 7 5 19 2.04 1.04 0.48 0.39 28.67 9.90188 154 18 8 9 7 17 2.59 1.57 0.53 0.39 25.19 10.81202 159 25 13 0 11 17 3.82 2.50 0.60 0.44 30.28 12.37223 155 103 16 20 17 24 12.50 2.95 0.56 0.44 39.54 18.06196 121 17 7 16 6 18 1.81 1.08 0.37 0.40 27.59 7.94202 133 47 10 12 12 20 4.71 1.34 0.38 0.41 30.03 10.09

206 149 39 11 13 11 20 4.89 2.01 0.50 0.39 32.18 12.91

62

Page 63: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Table 31: Computational results on randomly generated medium size LP problems for four different routines. Iteris the number of iterations and Time is the elapsed time in seconds on a Dell Latitude CPi 266XT running Matlab5.3. The lpS solver is the TOMLAB lpSolve, and it is run with both Bland’s selection rule (iterations Itb, timeTb) and with the minimum cost selection rule (iterations Itm, time Tm). The linprog solver in the OptimizationToolbox 2.0 implements two different algorithms, a medium-scale simplex algorithm (time Tm) and a large-scaleprimal-dual interior-point method (iterations Itl, time Tl). The number of variables, n, the number of inequalityconstraints, m, the objective function coefficients, the linear matrix and the right hand side are chosen randomly.The last row shows the mean value of each column.

n m lpS lpS Minos qpopt linprog lpS lpS Minos qpopt linprog linprog

Itb Itm Iter Iter Itl Tb Tm Time T ime Tm Tl

328 192 174 26 33 34 24 34.73 6.59 0.70 0.76 121.57 50.52326 212 65 10 24 12 20 14.67 3.28 0.82 0.57 116.00 49.87325 185 15 15 33 15 33 4.19 4.31 0.78 0.55 112.43 63.63327 186 21 11 14 13 26 4.49 2.86 0.75 0.55 112.95 49.85327 192 22 6 8 6 19 5.01 1.92 0.73 0.48 113.05 40.58285 181 9 7 11 7 21 2.33 1.98 0.64 0.44 80.13 30.33323 219 24 10 15 11 22 6.44 3.39 0.88 0.56 110.42 59.27284 201 45 10 10 9 24 9.46 3.21 0.71 0.35 81.13 44.80285 199 22 9 14 8 21 4.85 2.62 0.71 0.33 78.64 39.07296 228 33 11 10 13 23 9.00 3.78 0.77 0.39 89.67 59.23310 185 28 14 19 16 25 5.62 3.30 0.73 0.54 96.93 43.75311 219 23 12 12 17 22 6.53 4.13 0.78 0.60 97.05 53.90280 206 58 23 28 17 20 12.20 5.80 0.76 0.40 75.66 38.22319 204 17 11 11 12 23 4.41 3.45 0.64 0.54 106.16 52.84287 202 8 6 6 5 17 2.43 1.79 0.75 0.34 78.26 32.93328 202 44 9 11 10 18 9.32 2.72 0.76 0.53 117.09 41.86307 213 85 12 34 12 30 19.35 3.97 0.86 0.51 98.97 70.47285 199 29 11 11 9 24 6.43 3.27 0.71 0.47 78.32 44.30315 194 22 10 8 9 20 5.14 3.00 0.73 0.52 102.28 41.73310 181 38 6 7 5 22 6.95 1.80 0.71 0.46 96.99 36.93

308 200 39 11 16 12 23 8.68 3.36 0.75 0.50 98.18 47.20

63

Page 64: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Table 32: Computational results on randomly generated medium size LP problems for four different routines. Iteris the number of iterations and Time is the elapsed time in seconds on a Dell Latitude CPi 266XT running Matlab5.3. The lpS solver is the TOMLAB lpSolve, and it is run with both Bland’s selection rule (iterations Itb, timeTb) and with the minimum cost selection rule (iterations Itm, time Tm). The linprog solver in the OptimizationToolbox 2.0 implements two different algorithms, a medium-scale simplex algorithm (time Tm) and a large-scaleprimal-dual interior-point method (iterations Itl, time Tl). The number of variables, n, the number of inequalityconstraints, m, the objective function coefficients, the linear matrix and the right hand side are chosen randomly.The last row shows the mean value of each column.

n m lpS lpS Minos qpopt linprog lpS lpS Minos qpopt linprog linprog

Itb Itm Iter Iter Itl Tb Tm Time T ime Tm Tl

428 232 8 6 7 5 24 3.02 2.47 0.97 0.57 248.88 90.83421 234 22 5 11 4 22 7.54 2.64 0.86 0.54 232.29 84.15397 242 19 9 8 10 26 7.13 4.30 0.93 0.52 196.02 101.09388 226 30 10 11 10 24 9.19 3.80 0.89 0.51 187.35 78.37381 248 23 6 11 5 29 8.28 3.31 0.99 0.54 176.07 109.18402 228 80 16 28 22 25 22.21 5.94 1.03 0.86 207.52 84.60383 241 41 7 10 7 22 13.30 3.79 0.93 0.57 180.90 83.62421 236 94 21 19 15 34 27.94 7.80 1.06 0.80 234.26 131.09402 253 23 8 8 7 22 8.58 4.01 0.89 0.62 206.50 95.63395 260 24 8 8 7 23 8.95 3.95 0.94 0.48 197.14 100.85404 224 73 7 13 6 21 20.85 3.11 0.83 0.47 208.55 70.67393 267 44 11 15 9 25 16.64 5.86 1.09 0.65 192.59 116.73393 247 15 8 9 7 19 5.56 3.67 0.86 0.63 191.53 77.74384 245 79 14 27 20 25 24.59 6.10 1.08 0.79 185.63 97.19385 254 75 9 16 9 21 25.06 5.30 1.06 0.67 177.95 88.69409 226 58 8 9 8 23 15.76 3.56 0.82 0.63 210.86 78.32410 263 38 15 20 19 29 14.66 7.27 0.98 0.74 214.83 130.13403 250 117 12 27 20 20 36.56 5.35 1.06 0.87 201.18 81.53426 238 15 4 5 3 20 5.20 2.05 0.99 0.44 239.71 80.46409 250 57 10 13 10 24 19.00 5.01 1.21 0.72 210.15 101.34

402 243 47 10 14 10 24 15.00 4.46 0.98 0.63 204.99 94.11

64

Page 65: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Table 33: Computational results on randomly generated medium size LP problems for four different routines. Iteris the number of iterations and Time is the elapsed time in seconds on a Dell Latitude CPi 266XT running Matlab5.3. The lpS solver is the TOMLAB lpSolve, and it is run with both Bland’s selection rule (iterations Itb, timeTb) and with the minimum cost selection rule (iterations Itm, time Tm). The linprog solver in the OptimizationToolbox 2.0 implements two different algorithms, a medium-scale simplex algorithm (time Tm) and a large-scaleprimal-dual interior-point method (iterations Itl, time Tl). The number of variables, n, the number of inequalityconstraints, m, the objective function coefficients, the linear matrix and the right hand side are chosen randomly.The last row shows the mean value of each column.

n m lpS lpS Minos qpopt linprog lpS lpS Minos qpopt linprog linprog

Itb Itm Iter Iter Itl Tb Tm Time T ime Tm Tl

528 232 35 7 7 6 28 12.33 3.50 1.28 0.86 453.03 124.19482 252 33 9 7 8 25 12.02 4.26 1.00 0.71 346.37 120.24503 251 72 15 38 17 35 25.45 6.79 1.49 1.01 387.91 170.35507 259 142 18 46 27 28 50.68 8.55 1.43 1.33 397.67 147.41487 240 48 17 33 19 26 16.69 7.02 1.29 1.03 346.64 114.96506 251 46 8 11 8 24 16.92 4.19 1.13 0.78 394.38 119.71504 256 35 9 16 8 36 14.73 4.97 1.26 0.81 395.37 183.20489 255 36 28 27 28 26 14.39 11.87 1.32 1.30 355.66 129.45514 228 9 4 4 3 32 3.24 1.80 1.05 0.51 399.44 133.82524 245 64 11 27 14 28 21.99 5.34 1.26 1.00 439.31 135.32506 255 112 22 28 23 23 40.12 10.07 1.12 1.21 385.12 117.49497 224 50 11 14 12 31 15.51 4.57 1.11 0.86 362.38 121.94482 249 27 16 17 20 30 10.24 6.75 1.15 1.08 339.27 138.16485 249 18 6 21 5 20 6.36 2.87 1.35 0.55 340.35 95.15509 223 84 22 35 17 35 23.51 7.55 1.17 1.04 390.88 142.31506 224 38 12 11 14 33 11.89 4.65 1.09 0.94 383.13 132.21511 241 115 10 36 9 26 36.51 4.32 1.29 0.69 390.78 122.23497 230 78 23 43 12 26 23.60 8.27 1.29 0.75 362.08 109.30514 226 84 21 42 26 31 25.10 7.90 1.57 1.47 407.94 126.53511 268 59 10 30 9 28 24.74 5.76 1.43 0.94 385.56 161.65

503 243 59 14 25 14 29 20.30 6.05 1.26 0.94 383.16 132.28

Table 34: Computational results on randomly generated medium size LP problems for four different routines. Iteris the number of iterations and Time is the elapsed time in seconds on a Dell Latitude CPi 266XT running Matlab5.3. The lpS solver is the TOMLAB lpSolve, and it is run with both Bland’s selection rule (iterations Itb, timeTb) and with the minimum cost selection rule (iterations Itm, time Tm). The linprog solver in the OptimizationToolbox 2.0 implements two different algorithms, a medium-scale simplex algorithm (time Tm) and a large-scaleprimal-dual interior-point method (iterations Itl, time Tl). The number of variables, n, the number of inequalityconstraints, m, the objective function coefficients, the linear matrix and the right hand side are chosen randomly.Each row presents the mean of a test of 20 test problems with mean sizes shown in the first two columns.

n m lpS lpS Minos qpopt linprog lpS lpS Minos qpopt linprog linprog

Itb Itm Iter Iter Itl Tb Tm Time T ime Tm Tl

103 45 19 8 17 7 13 0.84 0.52 0.30 0.30 5.70 1.23

206 149 39 11 13 11 20 4.89 2.01 0.50 0.39 32.18 12.91

308 200 39 11 16 12 23 8.68 3.36 0.75 0.50 98.18 47.20

402 243 47 10 14 10 24 15.00 4.46 0.98 0.63 204.99 94.11

503 243 59 14 25 14 29 20.30 6.05 1.26 0.94 383.16 132.28

65

Page 66: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

66

Page 67: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

3 Solving Unconstrained, Constrained and Global optimization Prob-lems

This section describes how to define and solve unconstrained and constrained optimization problems, as wellas different types of global optimization problems. Several examples are given on how to proceed, depend-ing on if a quick solution is wanted, or more advanced tests are needed. TOMLAB is also compatible withMath Works Optimization TB v2.0, and it is shown how to run TOMLAB using their syntax.

All test example and output files are part of the standard distribution of TOMLAB, and all tests can be run bythe user. There is a file RunAllTests that goes through and runs all tests. The diary command is used to savescreen output and the resulting files are stored with the extension out, and having the same name as the test file.

Throughout this section the famous test problem Rosenbrock’s banana,

minx

f(x) = α(x2 − x2

1

)2 + (1− x1)2

s/t

−10 ≤ x1 ≤ 2−10 ≤ x2 ≤ 2

x1 − x2 ≤ 1−x2

1 − x2 ≤ 1

(12)

is used to illustrate the solution of unconstrained, constrained and global optimization problems. The standardvalue is α = 100. In this formulation simple bounds are added on the variables, and also constraints in illustrativepurpose. This problem is called RB BANANA in the following descriptions to avoid mixing it up with problemsalready defined in the problem definition files.

3.1 Defining the Problem in Matlab m-files

TOMLAB demands that the general nonlinear problem is defined in Matlab m-files, and not given as an input textstring. A file defining the function to be optimized must always be supplied. For linear constraints the constraintcoefficient matrix and the right hand side vector are given directly. Nonlinear constraints are defined in a separatefile. First order derivatives and second order derivatives, if available, are stored in separate files, both functionderivatives and constraint derivatives.

TOMLAB is compatible with Math Works Optimization TB v2.0, which in various ways demands both functions,derivatives and constraints to be returned by the same function. TOMLAB handle all this by use of interfaceroutines, hidden for the user. The user must then always use the Math Works Optimization TB v2.0 type of calls,not the TOMLABfunction calls, and access to the GUI, menus and driver routines are not possible.

It is generally recommended to use the TOMLAB format instead, because having defined the files in this format,all Math Works Optimization TB v2.0 and Math Works Optimization TB v1.5 solvers are accessible through theTOMLAB multi-solver driver routines.

The most simple way to write the m-file to compute the function value is shown for Example 12 assuming α = 100:

File: tomlabv2/usersguide/rbbs f.m

% crbb_f - function value for Constrained Rosenbrocks Banana%% function f = crbb_f(x)

function f = crbb_f(x)

f = 100*(x(2)-x(1)^2)^2 + (1-x(1))^2;

Running TOMLAB it is recommended to use a more general format for the m-files, adding one extra parameter,the Prob problem definition structure. TOMLAB will handle the simpler format also, but the more advancedfeatures of TOMLAB are not possible to use.

If using this extra parameter, then any information needed in the low-level function computation routine maybe sent as fields in this structure. For single parameter values, like the above α parameter in the example, the

67

Page 68: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

field Prob.uP is recommended, and for matrices, vectores and structures sub fields to the field Prob.USER isrecommended.

Using the above convention, then the new m-file for Example 12 is defined as

File: tomlabv2/usersguide/rbb f.m

% rbb_f - function value for Rosenbrocks Banana, Problem RB BANANA%% function f = rbb_f(x, Prob)

function f = rbb_f(x, Prob)

if isempty(Prob.uP)alpha = 100;

elsealpha = Prob.uP(1);

end

f = alpha*(x(2)-x(1)^2)^2 + (1-x(1))^2;

The value in the field Prob.uP is the α value. It is defined before calling the solver, either in a TOMLAB setup file,or directly before the call by explicit setting the Prob structure. In a similar way the gradient routine is defined as

File: tomlabv2/usersguide/rbb g.m

% rbb_g - gradient vector for Rosenbrocks Banana, Problem RB BANANA%% function g = rbb_g(x, Prob)

function g = rbb_g(x, Prob)

if isempty(Prob.uP)alpha = 100;

elsealpha = Prob.uP(1);

end

g = [-4*alpha*x(1)*(x(2)-x(1)^2)-2*(1-x(1)); 2*alpha*(x(2)-x(1)^2)];

If the gradient routine is not supplied, TOMLAB will use finite differences (or automatic differentiation) if thegradient vector is needed for the particular solver. In this case it is also easy to compute the Hessian matrix, whichgives the following code

File: tomlabv2/usersguide/rbb H.m

% rbb_H - Hessian matrix for Rosenbrocks Banana, Problem RB BANANA%% function H = crbb_H(x, Prob)

function H = crbb_H(x, Prob)

if isempty(Prob.uP)alpha = 100;

elsealpha = Prob.uP(1);

end

68

Page 69: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

H = [ 12*alpha*x(1)^2-4*alpha*x(2)+2 , -4*alpha*x(1);-4*alpha*x(1) , 2*alpha ];

If the Hessian routine is not supplied, TOMLAB will use finite differences (or automatic differentiation) if theHessian matrix is needed for the particular solver. Often a positive-definite approximation of the Hessian matrixis estimated during the optimization , and the second derivative routine is then not used.

If using the constraints defined for Example 12 then a constraint routine needs to defined for the single nonlinearconstraint, in this case

File: tomlabv2/usersguide/rbb c.m

% rbb_c - nonlinear constraint vector for Rosenbrocks Banana, Problem RB BANANA%% function c = crbb_c(x, Prob)

function c = crbb_c(x, Prob)

cx = -x(1)^2 - x(2);

The constraint gradient matrix is also of interest and is defined as

File: tomlabv2/usersguide/rbb dc.m

% rbb_dc - nonlinear constraint gradient matrix% for Rosenbrocks Banana, Problem RB BANANA%% function dc = crbb_dc(x, Prob)

function dc = crbb_dc(x, Prob)

dc = [-2*x(1);-1];

If the constraint gradient routine is not supplied, TOMLAB will use finite differences (or automatic differentiation)to estimate the constraint gradient matrix if it is needed for the particular solver.

The solver nlpSolve is also using the second derivatives of the constraint vector. The result is returned as aweighted sum of the second derivative matrices with respect to each constraint vector element, the weights beingthe Lagrange multipliers supplied as input to the routine. For the example problem the routine is defined as

File: tomlabv2/usersguide/rbb d2c.m

% rbb_d2c - The second part of the Hessian to the Lagrangian function for the% nonlinear constraints for Rosenbrocks Banana, Problem RB BANANA,i.e.%% lam’ * d2c(x)%% in%% L(x,lam) = f(x) - lam’ * c(x)% d2L(x,lam) = d2f(x) - lam’ * d2c(x) = H(x) - lam’ * d2c(x)%% function d2c=crbb_d2c(x, lam, Prob)

function d2c=crbb_d2c(x, lam, Prob)

69

Page 70: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

% The only nonzero element in the second derivative matrix for the single% constraint is the (1,1) element, which is a constant -2.

d2c = lam(1)*[-2 0; 0 0];

In the following sections it is described how to setup problems in TOMLAB and use the defined m-files.

3.2 Editing Problems into an Existing Setup File - Unconstrained OptimizationExample

The step wise description below shows how to edit new problems into an existing unconstrained optimization (UC)setup file. The example shows how to add one new problem in uc prob.m, the default file for UC problems inTOMLAB, As test example the problem (12) defined as an unconstrained problem is used, ignoring the linear andnonlinear constraints. The code given in the routines File: tomlabv2/usersguide/rbb f.m

1. Copy File: tomlabv2/testprob/uc prob to e.g. ucnew prob.m in your working directory. Also copy File:tomlabv2/testprob/uc f , File: tomlabv2/testprob/uc g and File: tomlabv2/testprob/uc H to the workingdirectory, and change the names to ucnew f.m, ucnew g.m and ucnew H.m.

2. Add the problem name to the menu choice in ucnew prob.m:

...

...,’Fletcher Q.2.6’...,’Fletcher Q.3.3’...,’RB BANANA’...

); % MAKE COPIES OF THE PREVIOUS ROW AND CHANGE TO NEW NAMES

if isempty(P)return;

end......

3. There are seventeen problems defined in ucnew prob.m, making eighteen the new problem number. Add thefollowing in ucnew prob.m after the last already existing problem (the optional parameters are not necessaryto define):

...

...elseif P == 18

Name =’RB BANANA’;x_0 = [-1.2 1]’; % Starting values for the optimization.x_L = [-10;-10]; % Lower bounds for x.x_U = [2;2]; % Upper bounds for x.x_opt = [1 1]; % Known optimal point (optional).f_opt = 0; % Known optimal function value (optional).f_min = 0; % Lower bound on function (optional).x_max = [ 1.3 1.3]; % Plot region parameters.x_min = [-1.1 -0.2]; % Plot region parameters.% The following lines show how to use the advanced user parameter% definition facility in TOMLAB.uP = checkuP(Name,Prob); % Check if given uP is for this problem% Ask the following question if flag set to ask questions

70

Page 71: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

uP(1) = askparam(ask,’Give the nonlinear factor in Rosenbrocks banana: ’,...0,[],100,uP);

% CHANGE: elseif P == 18% CHANGE: Add an elseif entry and the other variable definitions needed......

4. Note that because the file name is changed, the new name must be substituted. There are three places wherethe name should be changed, the function definition in the beginning of the file, a disp statement and mostimportant the place shown in the following text

...

...if ask==-1 & ~isempty(Prob)

if isstruct(Prob)if ~isempty(Prob.P)

if P==Prob.P & strcmp(Prob.probFile,’ucnew_prob’), return; endend

endend......

5. The names of the m-files are also changed and must be changed on two rows

...

...% Define the m-files that compute the function value, the gradient vector% and the Hessian matrix

%MIDEVA%# call ucnew_f ucnew_g ucnew_H

Prob=mFiles(Prob,’ucnew_f’,’ucnew_g’,’ucnew_H’);......

6. The function value, gradient vector and Hessian routine must now be edited. The function names shouldalso be renamed, but Matlab does not care what you call the routine, only what the file name is, so it isoptional to change the name of each function. Make the following addition in ucnew f.m:

...

...elseif P == 17 % Fletcher Q.3.3

f = 0.5*(x(1)^2+x(2)^2)*exp(x(1)^2-x(2)^2);elseif P == 18 % RB BANANA

f = Prob.uP(1)*(x(2)-x(1)^2)^2 + (1-x(1))^2;end......

7. Make the following addition in uc g.m:

...

...elseif P == 17 % Fletcher Q.3.3

%f = 0.5*(x(1)^2+x(2)^2)*exp(x(1)^2-x(2)^2);

71

Page 72: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

e = exp(x(1)^2-x(2)^2);g = e*[x(1)*(1+x(1)^2+x(2)^2); x(2)*(1-x(1)^2-x(2)^2)];

elseif P == 18 % RB BANANAg = Prob.uP(1)*[-4*x(1)*(x(2)-x(1)^2)-2*(1-x(1)); 2*(x(2)-x(1)^2) ];

end......

8. Make the following addition in uc H.m:

...

...elseif P == 17 % Fletcher Q.3.3

%f = 0.5*(x(1)^2+x(2)^2)*exp(x(1)^2-x(2)^2);%g = e*[x(1)*(1+x(1)^2+x(2)^2); x(2)*(1-x(1)^2-x(2)^2)];e = exp(x(1)^2-x(2)^2);H = [1+5*x(1)^2+2*x(1)^2*x(2)^2+x(2)^2+2*x(1)^4, ...

-2*x(1)*x(2)*(x(1)^2+x(2)^2);0 , 1-x(1)^2+2*x(1)^2*x(2)^2-5*x(2)^2+2*x(2)^4 ];

H(2,1)=H(1,2);H = e*H;

elseif P == 18 % RB BANANAH = Prob.uP(1)*[ 12*x(1)^2-4*x(2)+2 , -4*x(1);

-4*x(1) , 2 ];end......

9. Save all the files properly.

10. Run

AddProblemFile(’ucnew_prob’,’uc_prob with extra user problems’,’uc’);

Now ucnew prob.m is one of the TOMLAB setup files and all problems in ucnew prob.m are accessible from the GUI,the menu systems, and the driver routines. The edited setup file is found in File: tomlabv2/usersguide/ucnew prob. In the same directory the function, gradient and Hessian routines are found.

3.3 Defining Box-bounded Global Optimization Problems

Box-bounded global optimization problems are defined in the same way as unconstrained optimization problems.Since no derivative information is used, glb prob and glb f are the only problem definition files that need to bemodified.

To define (12) as a box-bounded global optimization problem follow the step wise instructions below (for allinstructions we assume that you edit the copied files in a text editor). Note that in this example the lower variablebounds are changed to xL = (−2,−2)T . The reason for that is just to speed up the global search for the readerwho wants to run this example.

1. Copy the files glb prob.m and glb f.m to your working directory.

2. Add the problem name to the menu choice in glb prob.m:

...

...,’HGO 468:2’...,’Spiral’...,’RB BANANA’...

72

Page 73: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

); % MAKE COPIES OF THE PREVIOUS ROW AND CHANGE TO NEW NAMES

if isempty(P)return;

end......

3. Add the following in glb prob.m after the last already existing problem (the optional parameters are notnecessary to define):

...

...elseif P == 29

Name=’RB BANANA’;x_L = [-2;-2]; % Lower bounds for x.x_U = [ 2; 2]; % Upper bounds for x.x_opt = [1 1]; % Known optimal point (optional).f_opt = 0; % Known optimal function value (optional).n_global = 1; % Number of global minima (optional).n_local = 1; % Number of local minima (optional).K = []; % Lipschitz constant, not used.x_max = [ 2 2]; % Plot region parameters.x_min = [-2 -2]; % Plot region parameters.

% CHANGE: elseif P == 30% CHANGE: Add an elseif entry and the other variable definitions needed......

4. Make the following addition in glb f.m:

...

...elseif P == 29 % RB BANANA

f = 100*(x(2)-x(1)^2)^2 + (1-x(1))^2;end......

5. Save all the files properly.

3.4 Defining Constrained Problems

To illustrate how to define a constrained problem, we add the constraints

x1 − x2 ≤ 1 (13)

and−x2

1 − x2 ≤ 1 (14)

to (12). Constraint (13) is of linear type and will thereby be defined separately from the nonlinear constraint (14).

The problem will be defined by following the step wise instructions below (for all instructions we assume that youedit the copied files in a text editor):

1. Copy the files con prob.m, con f.m, con g.m, con H.m, con c.m, con dc.m and con d2c.m to the workingdirectory.

73

Page 74: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

2. Modify the files con prob.m, con f.m, con g.m and con H.m in the same way as described for for the uncon-strained case in Section 3.2.

3. Extend the problem definition in con prob.m with the constraint parameters:

...

...elseif P == 15

Name=’RB BANANA’;x_0 = [-1.2 1]’; % Starting values for the optimization.x_L = [-10;-10]; % Lower bounds for x.x_U = [2;2]; % Upper bounds for x.x_opt = [1 1]; % Known optimal point (optional).f_opt = 0; % Known optimal function value (optional).f_min = 0; % Lower bound on function (optional).x_max = [ 1.3 1.3]; % Plot region parameters.x_min = [-1.1 -0.2]; % Plot region parameters.

A = [1 -1]; % Linear constraints matrix.b_L = -inf; % Lower bounds on linear constraints.b_U = 1; % Upper bounds on linear constraints.c_L = -inf; % Lower bounds on nonlinear constraints.c_U = 1; % Upper bounds on nonlinear constraints.

end......

4. Make the following addition in con c.m:

...

...elseif P == 15 % RB BANANA

cx = -x(1)^2 - x(2);end......

5. Make the following addition in con dc.m:

...

...elseif P == 15 % RB BANANA

if init==0dc = [-2*x(1);-1];

elsedc = ones(2,1);

endend......

6. Make the following addition in con d2c.m:

...

...elseif P == 15 % RB BANANA

if init==0

74

Page 75: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

d2c = [-2 0;0 0]*lam;else

d2c = [1 0; 0 0]end

end......

7. Save all the files properly.

3.5 Defining Global Mixed-Integer Nonlinear Programming Problems

To illustrate how to define a global mixed-integer nonlinear programming problem, add the constraints (13), (14)and

x1 integer (15)

to (12). Constraint (13) is of linear type and will therefore be defined separately from the nonlinear constraint(14).

To define (12) with the constraints (13), (14) and (15) as a global mixed-integer nonlinear programming problemfollow the step wise instructions below (for all instructions we assume that you edit the copied files in a texteditor). Note that we in this example change the lower variable bounds to xL = (−2,−2)T . The reason for thatis just to speed up the global search for the reader who wants to run this example.

1. Copy the files glc prob.m, glc f.m and glc c.m to the working directory.

2. Modify the files glc prob.m and glc f.m in the same way as described for for the box-bounded case in Section3.3.

3. Extend the problem definition in glc prob.m with the constraint parameters:

...

...elseif P == 24

Name=’RB BANANA’;x_L = [-2;-2]; % Lower bounds for x.x_U = [ 2; 2]; % Upper bounds for x.x_opt = [1 1]; % Known optimal point (optional).f_opt = 0; % Known optimal function value (optional).A = [1 -1]; % Linear constraints matrix.b_L = -inf; % Lower bounds on linear constraints.b_U = 1; % Upper bounds on linear constraints.c_L = -inf; % Lower bounds on nonlinear constraints.c_U = 1; % Upper bounds on nonlinear constraints.Integers = [1]; % Integer constraint.n_global = 1; % Number of global minima (optional).n_local = 1; % Number of local minima (optional).K = []; % Lipschitz constant, not used.x_max = [ 2 2]; % Plot region parameters.x_min = [-2 -2]; % Plot region parameters.

end......

4. Make the following addition in glc c.m:

...

...

75

Page 76: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

elseif P == 24 % RB BANANAcx = -x(1)^2 - x(2);

end......

5. Save all the files properly.

3.6 Defining Problems in Own Problem Definition Files

Assume you have a collection of e.g. constrained problems which you want to define in your own problem definitionfiles. Also assume you have defined your problems in con prob, con f, con g, con H, con c and con dc as describedin Section 3.4. Of course, you can remove the already existing problems and define your first problem as numberone. The extra modifications needed are:

1. Rename the files to for example connew prob, connew f, connew g, connew H, connew c and connew dc.

2. Make the following modification in the beginning of connew prob:

...

...if ask==-1 & ~isempty(Prob)

if isstruct(Prob)if ~isempty(Prob.P)

if P==Prob.P & strcmp(Prob.probFile,’connew_prob’), return; endend

endend......

3. Make the following modifications at the end of connew prob:

...

...%MIDEVA%# call connew_f connew_g connew_H connew_c connew_dc

Prob=mFiles(Prob,’connew_f’,’connew_g’,’connew_H’,’connew_c’,’connew_dc’);......

4. Save all the files properly.

5. Run

AddProblemFile(’connew_prob’,’New Constrained Test Problems’,’con’);

The text New Constrained ... is of course possible to change as the user likes. Now connew prob.m is one ofthe TOMLAB setup files and all problems in connew prob.m are accessible from the GUI, the menu systems,and the driver routines. This file is also the default file for constrained problems.

3.7 Special Notes

See the Section 5.1 on how the to set User Supplied Problem Parameters in TOMLAB. The Section 5.2 on how todefine a User Given Stationary Point might be of interest for the user working with algorithm development.

76

Page 77: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

3.8 How to Solve Nonlinear Optimization Problems Using TOMLAB

In general, solving a problem in TOMLAB demands that you have defined the problem in the problem definitionfiles as described in Section 3.2. When you have defined your problem in the problem definition files, there areseveral possible ways to solve it. You can use the Graphical User Interface routine tomlabGUI, the menu systemsucOpt, conOpt etc. or the driver routines ucRun, conRun, etc. You could also solve your problem by a direct callto the optimization routine. Which approach to choose depends on your purpose.

The interactive environments in the menu systems and the Graphical User Interface (GUI) are the most straight-forward approaches. These choices give you easy access to all available utilities. How to use the menu systems andthe GUI are described in Section 1.4 and Section 1.6, respectively.

When several problems are to be solved, e.g. in an algorithmic development environment, it is inefficient to use aninteractive system. In this case, we recommend you to solve your problems by directly call the driver routines. Inthe reminder of this section we will illustrate how these driver routines are called, how you directly call an generaloptimization routine and how you can solve a quadratic program by a direct call to the actual solver.

3.9 Using the Driver Routines

Solve the problem RB BANANA (12) defined as an unconstrained problem. Default values will be used for allparameters not explicitly changed. The following calls will solve our problem:

probFile = ’uc_prob’; % Problem definition file.P = 18; % Problem number.Prob = probInit(probFile, P); % Setup Prob structure.

Result = ucRun([], Prob, [], [], probFile, P);

To display the result of your run you just call the print routine PrintResult with your Result structure,

PrintResult(Result);

which gives the following printing output:

=== * * * ================================================== * * *Problem 18: RB BANANA f_k 0.000000000000000001

User given f(x_*) 0.000000000000000000f(x_0) 24.199999999999996000

Solver: ucSolve. EXIT=0. INFORM=2.Safeguarded BFGS

FuncEv 48 GradEv 40TOMLAB Global Variable Counters give:FuncEv 48 GradEv 41 Iter 36Starting vector x:x_0: -1.200000 1.000000Optimal vector x:x_k: 1.000000 1.000000Diff x-x0:

2.200000e+000 -2.312176e-009Gradient g_k:g_k: -4.162202e-009 9.227064e-010TOMLAB found no active constraints.

=== * * * ================================================== * * *

77

Page 78: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

If you want to solve the problem by using the Matlab routine fminu you just add the definition of Solver and thencall the driver routine ucRun:

probFile = ’uc_prob’; % Problem definition file.P = 18; % Problem number.Prob = probInit(probFile, P); % Setup Prob structure.Solver = ’fminu’; % Solver routine.

Result = ucRun(Solver, Prob, [], [], probFile, P);

Our second example is of a more ”testing and developing” characteristic. We want to illustrate how the driverroutines could be used in an efficient way.

By use of a simple for loop we will solve all the constrained problems defined in the files connew prob, connew f,connew g, connew H, connew c and connew dc, see Section 4.3. We have chosen to explicitly set the values ofseveral parameters, just in illustrative purpose. This procedure is not necessary since you could use the defaultvalues. The function drv test below runs conRun for all problems defined in connew prob, and then displays thenumber of iterations performed. Instead of just printing the number of iterations, you can store some of the resultsfor later use in e.g. statistical analysis.

function drv_test();

probFile = ’connew_prob’; % Solve problems defined in connew_prob.mprobNames = feval(probFile); % Get a list of all available problems.ask = 0; % Do not ask questions in problem definition.PriLev = 0; % No printing output.

Solver = ’conSolve’;

optParam = conDef; % Set default values.

optParam.PriLev = 0; % No printing output.optParam.eps_x = 1E-7; % Termination tolerance for X (Default=1E-8).optParam.eps_f = 1E-9; % Termination tolerance on F.(Default=1E-10). Dir.derivativeoptParam.eps_c = 1E-5; % Termination criterion on constraint violation (Default=1E-6)optParam.method = 1; % Optimization solver sub-method technique.optParam.MaxIter = 200; % Maximum number of iterations. (Default 100*no. of variables)optParam.eps_g = 1E-5; % Termination tolerance on gradient.(Default=1E-6).optParam.eps_Rank = 1E-11; % Rank test tolerance. Used in subspace minimization.optParam.wait = 0; % If true, pause after iteration printout.optParam.eps_absf = 1E-35; % Absolute convergence tolerance in function f.

optParam.LineSearch.sigma = 0.5; % Line search accuracy sigma. (Default=0.9)

for P = 1:size(probNames,1)probNumber = P;

Prob = probInit(probFile, P, ask, [], usr);Prob.optParam = optParam;

fprintf(’\n Problem number %d:’,P);fprintf(’ %s’,Prob.Name);

Result = conRun(Solver, Prob, ask, PriLev, probFile, probNumber);fprintf(’\n Number of iterations: %d’,Result.Iter);

end

78

Page 79: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

3.10 Direct Call to an Optimization Routine

When you want to solve your problem by a direct call to an Optimization routine there are two possible ways ofdoing it. The difference is in the way the problem dependent parameters are defined. The most natural way isto use a � prob routine (e.g. uc prob if the problem is of the type unconstrained) to define those parameters. Theother way is to define those parameters by first calling the routines ProbAssign and mFiles. In this subsection, wewill give examples of the two different approaches.

First, solve the problem RB BANANA (12) as an unconstrained problem. In this case, define the problem in thefiles ucnew prob, ucnew f, ucnew g and ucnew H as described in Section 3.2. Using the problem definition files inthe working directory solve the problem and print the result by the following calls.

File: tomlabv2/usersguide/ucnewSolve1.m

probFile = ’ucnew_prob’; % Problem definition file.P = 18; % Problem number.Prob = probInit(probFile, P); % Setup Prob structure.

Result = ucSolve(Prob);PrintResult(Result);

Now, we will solve the same problem as in the example above but we will define the parameters x 0, x L and x Lby calling the routine ProbAssign. Note that in this case we will not use the file ucnew prob, only the files ucnew fand ucnew g. The file ucnew H is not needed because a quasi-Newton BFGS algorithm is used. The call to theroutine mFiles defines the files that defines our problem.

File: tomlabv2/usersguide/ucnewSolve2.m

optType = ’uc’; % Problem type.x_0 = [-1.2;1]; % Starting values for the optimization.x_L = [-10;-10]; % Lower bounds for x.x_U = [2;2]; % Upper bounds for x.

Prob = probAssign(optType, x_0, [], x_L, x_U); % Setup Prob structure.Prob = mFiles(Prob,’ucnew_f’,’ucnew_g’); % Problem definition files.Prob.P = 18; % Problem number.Prob.Solver.Alg=1; % Use quasi-Newton BFGSProb.uP = 100; % Set alpha parameter

Result = ucSolve(Prob);PrintResult(Result);

79

Page 80: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

80

Page 81: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

4 Solving Nonlinear Least Squares and Parameter Estimation Prob-lems

This section describes how to define and solve different types of nonlinear least squares and parameter estimationproblems. Several examples are given on how to proceed, depending on if a quick solution is wanted, or moreadvanced tests are needed. TOMLAB is also compatible with Math Works Optimization TB v2.0, and it is shownhow to run TOMLAB using their syntax.

All test example and output files are part of the standard distribution of TOMLAB, and all tests can be run bythe user. There is a file RunAllTests that goes through and runs all tests. The diary command is used to savescreen output and the resulting files are stored with the extension out, and having the same name as the test file.

4.1 Defining Nonlinear Least Squares Problems

To define (12) as a nonlinear least squares problem follow the step wise instructions below (for all instructions weassume that you edit the copied files in a text editor):

1. Copy the files ls prob.m, ls r.m and ls J.m to the working directory.

2. Add the problem name to the menu choice in ls prob.m:

...

...,’Plasmid Stability n=3 (subst.)’...,’Plasmid Stability n=3 (probability)’...,’RB BANANA’...

); % MAKE COPIES OF THE PREVIOUS ROW AND CHANGE TO NEW NAMES

if isempty(P)return;

end......

3. Add the following in ls prob.m after the last already existing problem (the optional parameters are notnecessary to define):

...

...elseif P==10

Name=’RB BANANA’;Yt=[0;0]; % r(x) = residual = model psi(t,x) - data Yt(t)x_0=[-1.2 1]’; % Starting values for the optimization.x_L=[-10;-10]; % Lower bounds for x.x_U=[2;2]; % Upper bounds for x.x_opt=[1 1]; % Known optimal point (optional).f_opt=0; % Known optimal function value (optional).f_min=0; % Lower bound on function (optional).x_max=[ 1.3 1.3]; % Plot region parameters.x_min=[-1.1 -0.2]; % Plot region parameters.

elsedisp(’ls_prob: Illegal problem number’)pauseName=[];

end......

81

Page 82: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

4. Make the following addition in ls r.m:

...

...yMod=r;

elseif P==10% RB BANANAr = [10*(x(2)-x(1)^2);1-x(1)];

end

if Prob.NLLS.UseYt & m==length(r), r=r-Yt; end......

5. Make the following addition in ls J.m:

...

...elseif P==10

% RB BANANAJ = [-20*x(1) 10

-1 0 ];end......

6. Save all the files properly.

4.2 Defining Exponential Sum Fitting Problems

The pre-defined exponential sum fitting problems are defined in one problem definition file, exp prob.m. Assumethat we want to fit a sum of exponential terms to the data series

t = 10−3

30507090110130150170190210230250270290310330350370

, Y (t) = 10−4

18299154281334711466100778729738267085932535247344271374434853111295026862476

, (16)

here named SW.

To define (16) as a exponential sum fitting problem follow the step wise instructions below (for all instructions weassume that you edit the copied file in a text editor):

1. Copy the file exp prob.m to the working directory.

82

Page 83: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

2. Add the problem name to the menu choice in exp prob.m:

...

...,’Atcexp nr2 ’...,’Atcexp nr2\~ ’...,’SW ’...); % MAKE COPIES OF THE PREVIOUS ROW AND CHANGE TO NEW NAMES

if isempty(P)return;

end......

3. Add the following in exp prob.m after the last already existing problem:

...

...elseif P==44

Name=’SW’;t=[30:20:370]’; % Time in msYt=[18299 15428 13347 11466 10077 8729 7382 6708 5932 5352 4734 4271 ...

3744 3485 3111 2950 2686 2476]’;t=t/1000; % Scale to seconds. Gives lambda*1000, of order 1Yt=Yt/10000; % Scale function values. Avoid large alpha

elsedisp(’exp_prob: Illegal problem number’)

...

...

4. Save the file properly.

There are four different types of exponential terms available in TOMLAB. The type of exponential terms isdetermined by the parameter Prob.ExpFit.eType which is set by defining the parameter eType in the problemdefinition file:

...

...elseif P==44

Name=’SW’;t=[30:20:370]’; % Time in msYt=[18299 15428 13347 11466 10077 8729 7382 6708 5932 5352 4734 4271 ...

3744 3485 3111 2950 2686 2476]’;t=t/1000; % Scale to seconds. Gives lambda*1000, of order 1Yt=Yt/10000; % Scale function values. Avoid large alphaeType = 1;

elsedisp(’exp_prob: Illegal problem number’)

...

...

The above definition of eType is not necessary and was made just in illustrative purpose since 1 is the default valueof eType.

The four different types of exponential models available in TOMLAB are given in Table 35.

83

Page 84: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Table 35: The different types of exponential terms.

f(t) =p∑i

αie−βit, αi ≥ 0, 0 ≤ β1 < β2 < ... < βp, eType = 1.

f(t) =p∑i

αi(1− e−βit), αi ≥ 0, 0 ≤ β1 < β2 < ... < βp, eType = 2.

f(t) =p∑i

tαie−βit, αi ≥ 0, 0 ≤ β1 < β2 < ... < βp, eType = 3.

f(t) =p∑i

(tαi − γi)e−βit, αi, γi ≥ 0, 0 ≤ β1 < β2 < ... < βp, eType = 4.

4.3 Defining Problems in Own Problem Definition Files

Assume you have a collection of e.g. nonlinear least squares problems which you want to define in your own problemdefinition files. Also assume you have defined your problems in ls prob, ls r and ls J as described in Section 4.1Of course, you can remove the already existing problems and define your first problem as number one. The extramodifications needed are:

1. Rename the files to for example lsnew prob, lsnew r and lsnew J.

2. Make the following modification in the beginning of lsnew prob:

...

...if ask==-1 & ~isempty(Prob)

if isstruct(Prob)if ~isempty(Prob.P)

if P==Prob.P & strcmp(Prob.probFile,’lsnew_prob’), return; endend

endend......

3. Make the following modifications at the end of lsnew prob:

...

...%MIDEVA%# call ls_f ls_g ls_H lsnew_r lsnew_J

Prob=mFiles(Prob,’ls_f’,’ls_g’,’ls_H’,[],[],[],’lsnew_r’,’lsnew_J’);......

4. Save all the files properly.

5. Run

AddProblemFile(’lsnew_prob’,’New Nonlinear Least Squares Test Problems’,’con’);

The text New Nonlinear ... is of course possible to change as the user likes. Now lsnew prob.m is one of theTOMLAB setup files and all problems in lsnew prob.m are accessible from the GUI, the menu systems, andthe driver routines. This file is also the default file for nonlinear least squares problems.

84

Page 85: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Now see Section 3.8 on how to solve optimization problems in TOMLABand Section 3.9 on how to use the driverroutines.

The following example illustrate how the driver routines could be used in an efficient way. By use of a simple forloop we will solve all the least squares problems defined in the files lsnew prob, lsnew r and lsnew J, see Section4.3. We have chosen to explicitly set the values of several parameters, just in illustrative purpose. This procedureis not necessary since you could use the default values. The function drv test below runs lsRun for all problemsdefined in lsnew prob, and then displays the number of iterations performed. Instead of just printing the numberof iterations, you can store some of the results for later use in e.g. statistical analysis.

function drv_test();

probFile = ’lsnew_prob’; % Solve problems defined in lsnew_prob.mprobNames = feval(probFile); % Get a list of all available problems.

ask = 0; % Do not ask questions in problem definition.PriLev = 0; % No printing output.usr = 0; % Do not solve problem defined in usr_prob.m.

Solver = ’clsSolve’;

optParam = lsDef; % Set default values.

optParam.PriLev = 0; % No printing output.optParam.eps_x = 1E-7; % Termination tolerance for X (Default=1E-8).optParam.eps_f = 1E-9; % Termination tolerance on F.(Default=1E-10). Dir.derivativeoptParam.eps_c = 1E-5; % Termination criterion on constraint violation (Default=1E-6)optParam.method = 1; % Optimization solver sub-method technique.optParam.MaxIter = 200; % Maximum number of iterations. (Default 100*no. of variables)optParam.eps_g = 1E-5; % Termination tolerance on gradient.(Default=1E-6).optParam.eps_Rank = 1E-11; % Rank test tolerance. Used in subspace minimization.optParam.wait = 0; % If true, pause after iteration printout.optParam.eps_absf = 1E-35; % Absolute convergence tolerance in function f.

optParam.LineSearch.sigma = 0.5; % Line search accuracy sigma. (Default=0.9)

for P = 1:size(probNames,1)probNumber = P;

Prob = probInit(probFile, P, ask, [], usr);Prob.optParam = optParam;

fprintf(’\n Problem number %d:’,P);fprintf(’ %s’,Prob.Name);

Result = lsRun(Solver, Prob, ask, PriLev, probFile, probNumber);fprintf(’\n Number of iterations: %d’,Result.Iter);

end

Another example is on how to solve the exponential sum fitting problem (16)

probFile = ’exp_prob’; % Problem definition file.P = 44; % Problem number.Prob = probInit(probFile, P); % Setup Prob structure.Result = clsRun([], Prob, [], [], probFile, P);

Also see the Section 3.10 on how to make a direct call to an optimization routine.

85

Page 86: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

5 Special Notes and Features

In this section is collected several topics of general interest, which enables the user to use TOMLAB more efficiently.The reader should also consult Section 1.2 to get a complete picture of the system.

5.1 User Supplied Problem Parameters

The best way to describe this will be by giving some examples. Assume you have a problem with variable dimension.If you want to interactively give the dimension of the problem during the problem setup, the routine askparamwill help you. Let us take problem 27 in cls prob as an example.

...

...elseif P==27

Name=’RELN’; % Test for releasing more than one bound with variable dimensionuP=checkuP(Name,Prob);% n variable, 1 <= n , default n=10n = askparam(ask, ’Give problem dimension ’, 1, [], 10, uP);uP(1)=n;Yt=zeros(n,1);x_0 = zeros(n,1);x_opt = 3.5*ones(n,1);

...

...

The parameter uP, which is a field in the problem structure Prob, is aimed for this kind of problems and we cansee above that uP(1) is set to the dimension supplied by the user. Type help askparam for information about theparameters sent to askparam. When user supplied parameters are to be handled the routine checkuP should becalled in the same way as above (directly after the definition of the name of the problem). checkuP checks thatthe user parameters set in uP (or Prob.uP) are the ones that is set for the actual problem in the first place. Ifthey are set outside the system checkuP will let them keep those values.

In the other problem definition files, cls r and cls J in this example, the parameter(s) are ”unpacked” and can beused e.g. in the definition of the Jacobian.

...

...elseif P==27

% ’RELN’n = Prob.uP(1);

...

...

If you want questions to be asked during the problem setup you must set the ask flag true in the call to probInit.See the example below:

ask=1;Prob = probInit(’cls_prob’,27,ask);

The system will now ask you to give the problem dimension, and let us assume that you choose the dimension tobe 20:

Current value = 10

Give problem dimension 20

86

Page 87: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Now we call clsSolve to solve the problem,

Result=clsSolve(Prob);

which gives the printing output

==================================================Iteration no: 0 Func 80.00000000000000000000 Cond 1==================================================Iteration no: 1 Func 1.25000000000000000000 Cond 1*** Convergence 2, Projected gradient small ***

As a second example let us assume that the user will solve the problem above for all dimensions between 10 and30. Then the following code snippet will help us.

for dim=10:30Prob = [];Prob.uP(1) = dim;PriLev = 0;

Result = clsRun([],Prob,[],PriLev,’cls_prob’,27);end

5.2 User Given Stationary Point

Known stationary points could be defined in the problem definition files. It is also possible for the user to definethe type of stationary point (minimum, saddle or maximum). When we have defined the problem RB BANANA(12) in the previous sections we have defined x opt to (1, 1) in the problem definition files. Since we now that thispoint is a minimum point we could extend the definition of x opt to

x_opt = [1 1 StatPntType]; % Known optimal point (optional).

where StatPntType equals 0, 1, or 2 depending on the type of the stationary point (minimum, saddle or maximum).In our case we will set StatPntType to 0 since (1, 1) is a minimum point and the extension becomes

x_opt = [1 1 0]; % Known optimal point (optional).

If there is more than one known stationary point, the points are defined as rows in a matrix with the values ofStatPntType as the last column. Assume that (−1,−1) is a saddle point, (1,−2) is a minimum point and (−3, 5)is a maximum point for a certain problem. The definition of x opt could then look like

x_opt = [ -1 -1 11 -2 0-3 5 2 ];

Note that it is not necessary to define x opt, and if x opt is defined it is not necessary to define StatPntType.

5.3 Printing Utilities and Print Levels

The amount of printing is determined by setting a print level for each routine. This parameter most often has thename PriLev.

The main driver or menu routine called may have a PriLev parameter among its input parameters. This parameterdetermines the level of printing output of the result of the optimization.

87

Page 88: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Table 36: PriLev in the optimization routines

Value Description< 0 Totally silent.0 Error messages and warnings.1 Final results including convergence test results and minor warnings.2 Each iteration, short output.3 Each iteration, more output.4 Line search or QP information.5 Hessian output, final output in solver.

The optimization routines normally sets the PriLev parameter to Prob.optParam.PriLev. The structure optParam,which itself is a field in the structure Prob, is set to default values by a call to optParamdef. The user may thenchange any values before calling the main routine, see Table 36. The fields in optParam is described in Table 7.

There is a wait flag field in optParam, optParam.wait. If this flag is set true, the routines uses the pause statementto avoid the output just flushing by.

Three global variables, MAX c, MAX x and MAX r, are used as upper bounds for the number of constraints,variables and residuals to be printed. Those variables, useful for large problems, are set to default values by callingtomlabInit.

The TOMLAB routines print large amounts of output if high values for the PriLev parameter is set. To make theoutput look better and save space, several printing utilities have been developed, see Table 42 page 133. There isalso a routine PrintResult that prints the results of an optimization given the Result structure.

For matrices there are two routines, mPrint and printmat. The routine printmat prints a matrix with row andcolumn labels. The default is to print the row and column number. The standard row label is eight characterslong. The supplied matrix name is printed on the first row, the column label row, if the length of the name is atmost eight characters. Otherwise the name is printed on a separate row.

The standard column label is seven characters long, which is the minimum space an element will occupy in theprint out. On a 80 column screen, then it is possible to print a maximum of ten elements per row. Independenton the number of rows in the matrix, printmat will first display A(:, 1 : 10), then A(:, 11 : 20) and so on.

The routine printmat tries to be intelligent and avoid decimals when the matrix elements are integers. It determinesthe maximal positive and minimal negative number to find out if more than the default space is needed. If anyelement has an absolute value below 10−5 (avoiding exact zeros) or if the maximal elements are too big, a switchis made to exponential format. The exponential format uses ten characters, displaying two decimals and thereforeseven matrix elements are possible to display on each row.

For large matrices, especially integer matrices, the user might prefer the routine mPrint. With this routine a moredense output is possible. All elements in a matrix row is displayed (over several output rows) before next matrixrow is printed. A row label with the name of the matrix and the row number is displayed to the left using theMatlab style of syntax.

The default in mPrint is to eight characters per element, with two decimals. However, it is easy to change theformat and the number of elements displayed. For a binary matrix it is possible to display 36 matrix columns inone 80 column row.

5.4 Approximation of Derivatives

Both numerical differentiation and automatic differentiation are available. For numerical differentiation there arefive different approaches.

First there is the classical approach with forward or backward differences together with an automatic step selectionprocedure. This is handled by the routine fdng, which is a direct implementation of the FD algorithm [29, page343].

If the Spline Toolbox is installed, gradient, Jacobian, constraint gradient and Hessian approximations could be

88

Page 89: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

computed in three different ways depending of which of the three routines csapi, csaps or spaps the user choose touse.

The fifth approximation method is a method by Squire and Trapp [54], which is using complex variables to estimatethe derivative of real functions. The method is not particulary sensitive to the choice of step length.

Numerical differentiation is automatically used for gradient, Jacobian, constraint gradient and Hessian if the userroutine is nonpresent.

Automatic differentiation is performed by use of the ADMAT TB, for information of how to get a copy of ADMATTB see http://simon.cs.cornell.edu/home/verma/AD/. Below, we give a short instruction of how to install it.

1. Install the ADMAT TB at e.g. d:\Admat\...2. Change the path commands in ...\tomlabv2\lib\admatInit.m and execute the file. (If you choose d:\Admat

in 1. it should be:)

...

...path(path,’d:\admat’);path(path,’d:\admat\reverse’);path(path,’d:\admat\reverseS’);path(path,’d:\admat\PROBS’);path(path,’d:\admat\ADMIT\ADMIT-1’);......

3. If not done before, setup location of installed c-compiler by ”mex -setup”.

4. In directory d:\Admat\ADMIT\ADMIT-1, execute ”mex id.c” to form id.dll.

ADMAT TB should be initialized by calling admatInit before running TOMLAB with automatic differentiation.Note that if TOMLAB should be fully compatible with the ADMAT TB then your functions must be definedaccording to the ADMAT TB requirements. Some of the predefined test problems in TOMLAB do not fulfill thoserequirements.

In the Graphical User Interface, differentiation strategy selection is made from the Diff menu reachable in ad-vanced mode. When running the menu routines you should push the How to compute derivatives button in theOptimization Parameter Menu. To choose differentiation strategy when running the driver routines or directlycalling the actual solver you just set Prob.AutoDiff equal to 1 for automatic differentiation or Prob.NumDiff to1, 2, 3 or 4 for numerical differentiation, before calling drivers or solvers. Note that Prob.NumDiff = 1 willrun the fdng routine and Prob.NumDiff = 2, 3, 4 will run the Spline Toolbox routines csapi, csaps and spapscorrespondingly. The csaps demands that a smoothness parameter is set and the spaps routine demands that atolerance parameter is set. Those parameters are asked for when the corresponding routine is chosen but couldalso be explicitly set by the user via the splineSmooth and splineTol fields in the optimization parameter struc-ture optParam, see Table 7. The user should be aware of that there is no guarantee that the default values ofsplineSmooth and splineTol are appropriately chosen.

Here follows some examples of the use of approximative derivatives when running the driver routines ucRun andclsRun.

Automatic Differentiation example

probFile = ’uc_prob’;P = 1;Prob = probInit(probFile, P);Solver = ’ucSolve’;Prob.Solver.Alg = 1;Prob.AutoDiff = 1; % Use Automatic Differentiation.Result = ucRun(Solver, Prob, [], [], probFile, P);

FD example

89

Page 90: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

probFile = ’uc_prob’;P = 1;Prob = probInit(probFile, P);Solver = ’ucSolve’;Prob.Solver.Alg = 1;Prob.NumDiff = 1; % Use the fdng routine.Result = ucRun(Solver, Prob, [], [], probFile, P);

Spline example

probFile = ’ls_prob’;P = 1;Prob = probInit(probFile, P);Solver = ’clsSolve’;Prob.Solver.Alg = 0;Prob.NumDiff = 2; % Use the Spline Toolbox routine csapi.Result = lsRun(Solver, Prob, [], [], probFile, P);

5.5 Partially Separable Functions

The routine sTrustr implements a structured trust region algorithm for partially separable functions (psf). We willhere give the definition of a psf and illustrate how such a function is defined.

f is partially separable if f(x) =M∑i

fi(x), where, for each i ∈ {1, ...,M} there exists a subspace Ni �= 0 such that,

for all w ∈ Ni and for all x ∈ X, it holds that fi(x + w) = fi(x). X is the closed convex subset of Rn defined by

the constraints.

Consider the problem DAS 2 in File: tomlabv2/testprob/con prob :

minx

f(x) = 12

6∑1ri(x)2

s/t Ax ≥ bx ≥ 0

(17)

where

r =

√116 x1 − 3√

11x2−3√

2√0.0775 · x3 + 0.5√

0.0775x43 −3√

2−56 x1 + 0.6x3

0.75x3 + 23x4

, A =

−1 −2 −1 −1

−3 −1 −2 10 1 4 0

, b =

−5

−41.5

.

The objective function in (17) is partially separable according to the definition above and the constraints are linearand therefore they define a convex set. DAS 2 is defined as constrained problem 14 in con prob, con f, con g etc.to be an illustrative example of how to define a problem with a partially separable objective function. Note thedefinition of pSepFunc in con prob.

Solving (17) with sTrustr is done by the following definitions and call:

probFile = ’con_prob’;P = 14;Prob = probInit(probFile,P);Solver = ’sTrustr’;

Result = conRun(Solver,Prob,[],[],probFile,P);

90

Page 91: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

5.6 Recursive solver calls

For solving some kinds of problems it could be suitable or even necessary to apply algorithms which is based on arecursive approach. Here, we by a recursive approach also include those cases where you in each iteration solves anoptimization problem as a subproblem. For example, the EGO algorithm (implemented in the routine ego) solvesan unconstrained (uc) and a box-bounded global optimization problem (glb) in each iteration. As mentioned inSection 1.2.1 TOMLAB uses a number of global variables. To avoid that those variables are not reinitialized orgiven new values by the underlying procedure TOMLAB saves the global variables in the workspace before theunderlying procedure is called. Directly after the call to the underlying procedure the global variables are restored.

The method described above to handle the problem of global variables in recursive algorithms are treated by thetwo routines globalSave and globalGet. The globalSave routine saves all global variables in a structure glbSave(depth)and then initialize all of of them as empty. By using the depth variable, an arbitrarily number of recursions arepossible. The other routine globalGet retrieves all global variables in the structure glbSave(depth).

To illustrate the idea, we have pasted the parts of the ego code where the routines globalSave and globalGet arecalled.

...

...globalSave(1);EGOResult = glbSolve(EGOProb);globalGet(1);

...

...globalSave(1);[DACEResult] = ucSolve(DACEProb);globalGet(1);

...

...

5.7 Usage of routines from Optimization Toolbox 1.x

TOMLAB has interfaces to some of the solvers in Math Works Optimization TB v1.5. If the user has this toolboxand want to run these routines for problems defined in the TOMLAB format, the path to directory optim1.x mustbe placed before the path to the directory mex. Edit the file startup.m and change if 0 to if 1 to add the correctpath.

If running Mideva, there are equivalents to these routines. If the user wants to run these routines for problemsdefined in the TOMLAB format, the path to directory mideva1.x must be placed before the path to the directorymex. and to the directory optim1.x (if in path). In the file startup.m, change if 0 to if 1 to add the correct path.

5.8 Using Matlab 5.0 or 5.1

Are you are running TOMLAB under Matlab 5.0 or 5.1? If running on PC then the directory matlab5.1 must beput before the other TOMLAB v2.0 directories in the Matlab search path.

If running on Unix then the directory unix5.1 must be put before the other TOMLAB v2.0 directories in theMatlab search path.

The matlab5.1 directory contains two routines, strcmpi and xnargin. The command strcmpi, used by someTOMLAB routines, is a Matlab 5.2 command. Therefore, the matlab5.1 directory routine strcmpi is createdfor 5.0/5.1 users. It simply calls strcmp after doing upper on the arguments.

A bug in Matlab 5.1 on PC for the nargin command makes it necessary to call nargin with only non-capitalizedletters. The routine xnargin in Matlab 5.1 does lower on the arguments in the call to nargin, and the xnarginroutine in the lib directory does not do it. On unix systems it is necessary to keep the exact function name.

The unix5.1 directory contains one routine, strcmpi.

91

Page 92: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

6 The TOMLAB Routines - Detailed Descriptions

6.1 Optimization Routines in TOMLAB

In the following subsections the optimization routines in TOMLAB will be described.

6.1.1 clsSolve

PurposeSolve nonlinear least squares optimization problems with linear inequality and equality constraints and simplebounds on the variables.

clsSolve solves problems of the form

minx

f(x) = 12r(x)

T r(x)

s/t xL ≤ x ≤ xUbL ≤ Ax ≤ bU

where x, xL, xU ∈ Rn, r(x) ∈ R

N , A ∈ Rm1×n and bL, bU ∈ R

m1 .

Calling SyntaxResult = clsSolve(Prob, varargin)

Description of InputsProb Problem description structure. The following fields are used:

Solver.Alg Solver algorithm to be run:0: Gives default, now Fletcher - Xu hybrid method;1: Fletcher - Xu hybrid method; Gauss-Newton / BFGS.2: Al-Baali - Fletcher hybrid method; Gauss-Newton/BFGS.3: Huschens method.4: Gauss-Newton

optParam Structure with special fields for optimization parameters, see Table 7.Fields used are: PreSolve, NOT release all, eps f, eps g, eps c, eps x, eps Rank,eps absf, MaxIter, wait, size x, size f, f Low, LineSearch, LineAlg, bTol, cTol, xTol,LowIts, method, PriLev and QN InitMatrix.

NLLS Structure with special fields for nonlinear least squares, see Table 11.A Constraint matrix for linear constraints.b L Lower bounds on the linear constraints.b U Upper bounds on the linear constraints.x L Lower bounds on the variables.x U Upper bounds on the variables.x 0 Starting point.USER.H Name of m-file computing the Hessian matrix H(x).USER.r Name of m-file computing the residual vector r(x).USER.J Name of m-file computing the Jacobian matrix J(x).f Low Lower bound on function value.

varargin Other parameters directly sent to low level routines.

92

Page 93: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Description of OutputsResult Structure with result from optimization. The following fields are changed:

Iter Number of iterations.ExitFlag Flag giving exit status.Inform Binary code telling type of convergence:

1: Iteration points are close.2: Projected gradient small.4: Function value close to 0.8: Relative function value reduction low for LowIts iterations.32: Local minimum with all variables on bounds.101: Maximum number of iterations reached.102: Function value below given estimate.104: x k not feasible, constraint violated.

f 0 Function value at start.f k Function value at optimum.g k Gradient value at optimum.H k Hessian value at optimum.B k Quasi-Newton approximation of the Hessian at optimum.x 0 Starting point.x k Optimal point.v k Lagrange multipliers.r k Residual at optimum.J k Jacobian matrix at optimum.xState State of each variable, described in Table 17 .bState State of each linear constraint, described in Table 18.Solver Solver used.SolverAlgorithm Solver algorithm used.Prob Problem structure used.

DescriptionThe solver clsSolve includes four optimization methods for nonlinear least squares problems: the Gauss-Newtonmethod, the Al-Baali-Fletcher [5] and the Fletcher-Xu [22] hybrid method, and the Hushens TSSM method [38].If rank problem occur, the solver is using subspace minimization. The line search is performed using the routineLineSearch which is a modified version of an algorithm by Fletcher [23]. Bound constraints are partly treated asdescribed in Gill, Murray and Wright [29]. clsSolve treats linear equality and inequality constraints using an activeset strategy and a null space method.

AlgorithmSee Appendix A.1.

M-files UsedclsDef.m, ResultDef.m, preSolve.m, qpSolve.m, qpoptSOL.m, LineSearch.m, secUpdat.m, iniSolve.m, endSolve.m

See AlsoconSolve, nlpSolve, sTrustr

WarningsSince no second order derivative information is used, clsSolve may not be able to determine the type of stationarypoint converged to.

6.1.2 conSolve

PurposeSolve general constrained nonlinear optimization problems.

conSolve solves problems of the form

minx

f(x)

s/t xL ≤ x ≤ xUbL ≤ Ax ≤ bUcL ≤ c(x) ≤ cU

93

Page 94: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

where x, xL, xU ∈ Rn, c(x), cL, cU ∈ R

m1 , A ∈ Rm2×n and bL, bU ∈ R

m2 .

Calling SyntaxResult = conSolve(Prob, varargin)

Description of InputsProb Problem description structure. The following fields are used:

Solver.Alg Solver algorithm to be run:0: Schittkowski SQP.1: Han-Powell SQP.

optParam Structure with special fields for optimization parameters, see Table 7.Fields used are: eps f, eps g, eps c, eps x, eps Rank, eps absf, MaxIter, wait,size x, size f, size c, f Low, LineSearch, LineAlg, xTol, bTol, cTol, LowIts, PriLev, methodand QN InitMatrix.

A Constraint matrix for linear constraints.b L Lower bounds on the linear constraints.b U Upper bounds on the linear constraints.c L Lower bounds on the general constraints.c U Upper bounds on the general constraints.x L Lower bounds on the variables.x U Upper bounds on the variables.x 0 Starting point.USER.f Name of m-file computing the objective function f(x).USER.g Name of m-file computing the gradient vector g(x).USER.H Name of m-file computing the Hessian matrix H(x).USER.c Name of m-file computing the vector of constraint functions c(x).USER.dc Name of m-file computing the matrix of constraint normals ∂c(x)/dx.f Low Lower bound on function value.

varargin Other parameters directly sent to low level routines.

94

Page 95: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Description of OutputsResult Structure with result from optimization. The following fields are changed:

Iter Number of iterations.ExitFlag Flag giving exit status.Inform Binary code telling type of convergence:

1: Iteration points are close.2: Small search direction.4: Merit function gradient small.8: Small p and constraints satisfied.101: Maximum number of iterations reached.102: Function value below given estimate.103: Close iterations, but constraints not fulfilled. Too large penalty weights

to be able to continue. Problem is maybe infeasible?.104: Search direction is zero and infeasible constraints. The problem is very

likely infeasible.f 0 Function value at start.f k Function value at optimum.g k Gradient value at optimum.H k Hessian value at optimum.x 0 Starting point.x k Optimal point.v k Lagrange multipliers.c k Value of constraints at optimum.cJac Constraint Jacobian at optimum.xState State of each variable, described in Table 17 .bState State of each linear constraint, described in Table 18.cState State of each general constraint.Solver Solver used.SolverAlgorithm Solver algorithm used.Prob Problem structure used.

DescriptionThe routine conSolve implements two SQP algorithms for general constrained minimization problems. One imple-mentation, optParam.alg = 0, is based on the SQP algorithm by Schittkowski with Augmented Lagrangian meritfunction described in [52]. The other, optParam.alg = 1, is an implementation of the HanPowell SQP method.

M-files UsedconDef.m, ResultDef.m, qpSolve.m, qpoptSOL.m, LineSearch.m, iniSolve.m, endSolve.m

See AlsonlpSolve, sTrustr

6.1.3 cutplane

PurposeSolve mixed integer linear programming problems (MIP).

cutplane solves problems of the form

minx

f(x) = cTx

s/t 0 ≤ x ≤ xUAx = b, xj ∈ N∀j ∈I

where c, x, xU ∈ Rn, A ∈ R

m×n and b ∈ Rm. The variables x ∈ I, the index subset of 1, ..., n are restricted to be

integers.

Calling Syntax[Result] = cutplane(Prob)

95

Page 96: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Description of InputsProb Problem description structure. The following fields are used:

optParam.method Variable selection rule to be used:0: Minimum reduced cost.1: Bland’s rule (default).2: Minimum reduced cost. Dantzig’s rule.

MIP.IntVars Which of the n variables are integers.QP.B Active set B 0 at start:

B(i) = 1: Include variable x(i) is in basic set.B(i) = 0: Variable x(i) is set on its lower bound.B(i) = −1: Variable x(i) is set on its upper bound.

optParam Structure with special fields for optimization parameters, see Table 7.Fields used are: MaxIter, PriLev, wait, eps f, eps Rank, xTol and bTol.

QP.c Constant vector.A Constraint matrix for linear constraints.b L Lower bounds on the linear constraints.b U Upper bounds on the linear constraints.x L Lower bounds on the variables.x U Upper bounds on the variables.x 0 Starting point.

Description of OutputsResult Structure with result from optimization. The following fields are changed:

Iter Number of iterations.ExitFlag 0: OK.

1: Maximal number of iterations reached.2: Unbounded feasible region.3: Rank problems. Can not find any solution point.4: No feasible point x 0 found.5: Illegal x 0.

Inform If ExitF lag > 0, Inform = ExitF lag.QP.B Optimal active set. See input variable QP.B.f 0 Function value at start.f k Function value at optimum.g k Gradient value at optimum, c.x 0 Starting point.x k Optimal point.v k Lagrange multipliers.xState State of each variable, described in Table 17 .Solver Solver used.SolverAlgorithm Solver algorithm used.FuncEv Number of function evaluations. Equal to Iter.ConstrEv Number of constraint evaluations. Equal to Iter.Prob Problem structure used.

DescriptionThe routine cutplane is an implementation of a cutting plane algorithm with Gomorov cuts. cutplane normally usesthe linear programming routines lpSolve and DualSolve to solve relaxed subproblems. cutplane calls the generalinterface routines SolveLP and SolveDLP. By changing the setting of the structure fields Prob.Solver.SolverLPand Prob.Solver.SolverDLP, different sub-solvers are possible to use, see the help for the interface routines.

AlgorithmSee Appendix A.2.

ExamplesSee exip39, exknap, expkorv.

M-files UsedlpDef.m, Phase1Simplex.m, Phase2Simplex.m, DualSolve.m

96

Page 97: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

See AlsomipSolve, balas, lpsimp1, lpsimp2, lpdual, SolveLP, SolveDLP

6.1.4 DualSolve

PurposeSolve linear programming problems when a dual feasible solution is available.

DualSolve solves problems of the form

minx

f(x) = cTx

s/t xL ≤ x ≤ xUAx = bU

where x, xL, xU ∈ Rn, c ∈ R

n, A ∈ Rm×n and bU ∈ R

m.

Finite upper bounds on x are added as extra inequality constraints. Finite nonzero lower bounds on x are addedas extra inequality constraints. Fixed variables are treated explicitly. Adding slack variables and making necessarysign changes gives the problem in the standard form

minx

fP (x) = cTx

s/t Ax = bx ≥ 0

and the following dual problem is solved,

maxy

fD(y) = bT y

s/t AT y ≤ cy urs

with x, c ∈ Rn, A ∈ R

m×n and b, y ∈ Rm.

Calling Syntax[Result] = DualSolve(Prob)

Description of InputsProb Problem description structure. The following fields are used:

Solver.Alg Variable selection rule to be used:0: Minimum reduced cost (default).1: Bland’s anti-cycling rule.2: Minimum reduced cost. Dantzig’s rule.

QP.B Active set B 0 at start:B(i) = 1: Include variable x(i) is in basic set.B(i) = 0: Variable x(i) is set on its lower bound.B(i) = −1: Variable x(i) is set on its upper bound.

optParam Structure with special fields for optimization parameters, see Table 7.Fields used are: MaxIter, PriLev, wait, eps f, eps Rank and xTol.

QP.c Constant vector.A Constraint matrix for linear constraints.b L Lower bounds on the linear constraints.b U Upper bounds on the linear constraints.x L Lower bounds on the variables.x U Upper bounds on the variables.x 0 Starting point, must be dual feasible.y 0 Dual parameters (Lagrangian multipliers) at x 0.

97

Page 98: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Description of OutputsResult Structure with result from optimization. The following fields are changed:

Iter Number of iterations.QP.B Optimal active set.ExitFlag Exit flag:

0: OK.1: Maximal number of iterations reached. No primal feasible solution found.2: Infeasible Dual problem.3: No dual feasible starting point found.4: Illegal step length due to numerical difficulties. Should not occur.5: Too many active variables in initial point.

f k Function value at optimum.x 0 Starting point.x k Optimal primal solution x.v k Optimal dual parameters. Lagrange multipliers for linear constraints.c Constant vector in standard form formulation.A Constraint matrix for linear constraints in standard form.b Right hand side in standard form.

DescriptionWhen a dual feasible solution is available, the dual simplex method is possible to use. DualSolve implements thismethod using the algorithm in [30, pages 105-106]. There are three rules available for variable selection. Bland’scycling prevention rule is the choice if fear of cycling exist. The other two are variants of minimum reduced costvariable selection, the original Dantzig’s rule and one which sorts the variables in increasing order in each step(the default choice).

M-files UsedlpDef.m, cpTransf.m

See AlsolpSolve

6.1.5 gblSolve

PurposeSolve box-bounded global optimization problems. gblSolve is a stand-alone version of glbSolve and runs indepen-dently of TOMLAB.

gblSolve solves problems of the formminx

f(x)

s/t xL ≤ x ≤ xU

where f ∈ R and x, xL, xU ∈ Rn.

Calling SyntaxResult = gblSolve(fun, x L, x U, GLOBAL, PriLev)

98

Page 99: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Description of Inputsfun Name of m-file computing the function value, given as a string.x L Lower bounds for x, must be given to restrict the search space.x U Upper bounds for x, must be given to restrict the search space.GLOBAL Structure field containing:

iterations Number of iterations, default 50.epsilon Global/local weight parameter, default 10−4.

If restart is wanted, the following fields in GLOBAL should be defined andequal the corresponding fields in the Result.GLOBAL structure from theprevious run:C Matrix with all rectangle centerpoints.D Vector with distances from centerpoint to the vertices.L Matrix with all rectangle side lengths in each dimension.F Vector with function values.d Row vector of all different distances, sorted.d min Row vector of minimum function value for each distance.

PriLev Printing level.

Description of OutputsResult Structure with result from optimization. The following fields are changed:

Iter Number of iterations.FuncEv Number function evaluations.x k Matrix with all points giving the function value f k.f k Function value at optimum.GLOBAL Special structure field containing:C Matrix with all rectangle centerpoints.D Vector with distances from centerpoint to the vertices.L Matrix with all rectangle side lengths in each dimension.F Vector with function values.d Row vector of all different distances, sorted.d min Row vector of minimum function value for each distance.

DescriptionThe global optimization routine gblSolve is an implementation of the DIRECT algorithm presented in [40]. DIRECTis a modification of the standard Lipschitzian approach that eliminates the need to specify a Lipschitz constant.Since no such constant is used, there is no natural way of defining convergence (except when the optimal functionvalue is known). Therefore gblSolve runs a predefined number of iterations and considers the best function valuefound as the optimal one. It is possible for the user to restart gblSolve with the final status of all parameters fromthe previous run. Let’s say that you have run gblSolve on a certain problem for 50 iterations. Then you could rune.g. 40 iterations more and get the same result as if you had chosen to run 90 iterations in the first place. Torestart gblSolve you must give the result of the first run as input to your next run. The m-file gblsolve also includesthe subfunction conhull which is an implementation of the algorithm GRAHAMHULL in [50, page 108] with themodifications proposed on page 109. conhull is used to identify all points lying on the convex hull defined by a setof points in the plane.

Since gblSolve is a stand-alone version of glbSolve it runs independently of TOMLAB.

AlgorithmSee Appendix A.3.

6.1.6 gclSolve

PurposeSolve global mixed-integer nonlinear programming problems. gclSolve is a stand-alone version of glcSolve and runsindependently of TOMLAB.

99

Page 100: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

gclSolve solves problems of the form

minx

f(x)

s/t xL ≤ x ≤ xUbL ≤ Ax ≤ bUcL ≤ c(x) ≤ cU

xi integer i ∈ I

where x, xL, xU ∈ Rn, c(x), cL, cU ∈ R

m1 , A ∈ Rm2×n and bL, bU ∈ R

m2 .

Calling SyntaxResult = gclSolve(fName, cName, x L, x U, A, b L, b U, c L, c U, I, GLOBAL, PriLev)

Description of InputsfName Name of m-file computing the function value, given as a string.cName Name of m-file computing the function value, given as a string.x L Lower bounds for x, must be given to restrict the search space.x U Upper bounds for x, must be given to restrict the search space.A Constraint matrix for linear constraints.b L Lower bounds on the linear constraints.b U Upper bounds on the linear constraints.c L Lower bounds on the general constraints.c U Upper bounds on the general constraints.I Set of integer variables (a vector).GLOBAL Structure field containing:

MaxEval Number of function evaluations, default 200.epsilon Global/local weight parameter, default 10−4.

If restart is wanted, the following fields in GLOBAL should be defined andequal the corresponding fields in the Result.GLOBAL structure from theprevious run:C Matrix with all rectangle centerpoints.D Vector with distances from centerpoint to the vertices.F Vector with function values.Split Split(i, j) is the number of splits along dimension i of rectangle j.T T (i) is the number of times rectangle i has been trisected.G Matrix with constraint values for each point.ignoreidx Rectangles to be ignored in the rectangle selection procedure.I L I L(i, j) is the lower bound for rectangle j in integer dimension I(i).I U I U(i, j) is the upper bound for rectangle j in integer dimension I(i).feasible Flag indicating if a feasible point has been found.f min Best function value found at a feasible point.s 0 s 0 is used as s(0).s s(j) is the sum of observed rates of change for constraint j.t t(i) is the total number of splits along dimension i.

PriLev Printing level.

100

Page 101: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Description of OutputsResult Structure with result from optimization. The following fields are changed:

Iter Number of iterations.FuncEv Number function evaluations.x k Matrix with all points giving the function value f k.f k Function value at optimum.c k Nonlinear constraints values at x k.GLOBAL Special structure field containing:C Matrix with all rectangle centerpoints.D Vector with distances from centerpoint to the vertices.F Vector with function values.Split Split(i, j) is the number of splits along dimension i of rectangle j.T T (i) is the number of times rectangle i has been trisected.G Matrix with constraint values for each point.ignoreidx Rectangles to be ignored in the rectangle selection procedure.I L I L(i, j) is the lower bound for rectangle j in integer dimension I(i).I U I U(i, j) is the upper bound for rectangle j in integer dimension I(i).feasible Flag indicating if a feasible point has been found.f min Best function value found at a feasible point.s 0 s 0 is used as s(0).s s(j) is the sum of observed rates of change for constraint j.t t(i) is the total number of splits along dimension i.

DescriptionThe routine gclSolve implements an extended version of DIRECT, see [41], that handles problems with bothnonlinear and integer constraints.

DIRECT is a modification of the standard Lipschitzian approach that eliminates the need to specify a Lipschitzconstant. Since no such constant is used, there is no natural way of defining convergence (except when the optimalfunction value is known). Therefore gclSolve is run for a predefined number of function evaluations and considersthe best function value found as the optimal one. It is possible for the user to restart gclSolve with the finalstatus of all parameters from the previous run. Let’s say that you have run gclSolve on a certain problem for 500function evaluations. Then you could run e.g. for 200 function evaluations more and let gclSolve search for a pointthat gives a lower function value. To restart gclSolve you must give the result of the first run as input to your nextrun.

DIRECT does not explicitly handle equality constraints. It works best when the integer variables describe anordered quantity and is less effective when they are categorical.

Since gclSolve is a stand-alone version of glcSolve it runs independently of TOMLAB.

6.1.7 glbSolve

PurposeSolve box-bounded global optimization problems.

glbSolve solves problems of the formminx

f(x)

s/t xL ≤ x ≤ xU

where f ∈ R and x, xL, xU ∈ Rn.

Calling SyntaxResult = glbSolve(Prob,varargin)

101

Page 102: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Description of InputsProb Problem description structure. The following fields are used:

optParam Structure with special fields for optimization parameters, see Table 7.Fields used are: PriLev.

x L Lower bounds for x, must be given to restrict the search space.x U Upper bounds for x, must be given to restrict the search space.USER.f Name of m-file computing the objective function f(x).GLOBAL Special structure field containing:iterations Number of iterations, default 50.epsilon Global/local weight parameter, default 10−4.K The Lipschitz constant. Not used.tolerance Error tolerance parameter. Not used.

If restart is chosen in the menu system, the following fields inGLOBAL are also used and contains information from the previous run:C Matrix with all rectangle centerpoints.D Vector with distances from centerpoint to the vertices.L Matrix with all rectangle side lengths in each dimension.F Vector with function values.d Row vector of all different distances, sorted.d min Row vector of minimum function value for each distance.

varargin Other parameters directly sent to low level routines.

Description of OutputsResult Structure with result from optimization. The following fields are changed:

Iter Number of iterations.FuncEv Number function evaluations.x k Matrix with all points giving the function value f k.f k Function value at optimum.GLOBAL Special structure field containing:C Matrix with all rectangle centerpoints.D Vector with distances from centerpoint to the vertices.L Matrix with all rectangle side lengths in each dimension.F Vector with function values.d Row vector of all different distances, sorted.d min Row vector of minimum function value for each distance.Solver Solver used.SolverAlgorithm Solver algorithm used.

DescriptionThe global optimization routine glbSolve is an implementation of the DIRECT algorithm presented in [40]. DIRECTis a modification of the standard Lipschitzian approach that eliminates the need to specify a Lipschitz constant.Since no such constant is used, there is no natural way of defining convergence (except when the optimal functionvalue is known). Therefore glbSolve runs a predefined number of iterations and considers the best function valuefound as the optimal one. It is possible for the user to restart glbSolve with the final status of all parameters fromthe previous run. Let’s say that you have run glbSolve on a certain problem for 50 iterations. Then you could rune.g. 40 iterations more and get the same result as if you had chosen to run 90 iterations in the first place. Torestart glbSolve you must give the result of the first run as input to your next run. The m-file glbsolve also includesthe subfunction conhull which is an implementation of the algorithm GRAHAMHULL in [50, page 108] with themodifications proposed on page 109. conhull is used to identify all points lying on the convex hull defined by a setof points in the plane.

AlgorithmSee Appendix A.3.

M-files UsediniSolve.m, endSolve.m

102

Page 103: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

6.1.8 glcSolve

PurposeSolve global mixed-integer nonlinear programming problems.

glcSolve solves problems of the form

minx

f(x)

s/t xL ≤ x ≤ xUbL ≤ Ax ≤ bUcL ≤ c(x) ≤ cU

xi integer i ∈ I

where x, xL, xU ∈ Rn, c(x), cL, cU ∈ R

m1 , A ∈ Rm2×n and bL, bU ∈ R

m2 .

Calling SyntaxResult = glcSolve(Prob,varargin)

Description of InputsProb Problem description structure. The following fields are used:

optParam Structure with special fields for optimization parameters, see Table 7.Fields used are: PriLev, cTol.

x L Lower bounds for x, must be given to restrict the search space.x U Upper bounds for x, must be given to restrict the search space.A Constraint matrix for linear constraints.b L Lower bounds on the linear constraints.b U Upper bounds on the linear constraints.c L Lower bounds on the general constraints.c U Upper bounds on the general constraints.USER.f Name of m-file computing the objective function f(x).USER.f Name of m-file computing the vector of constraint functions c(x).GLOBAL Special structure field containing:MaxEval Number of function evaluations, default 200.Integers Set of integer variables.epsilon Global/local weight parameter, default 10−4.K The Lipschitz constant. Not used.tolerance Error tolerance parameter. Not used.

If restart is chosen in the menu system, the following fields inGLOBAL are also used and contains information from the previous run:C Matrix with all rectangle centerpoints.D Vector with distances from centerpoint to the vertices.F Vector with function values.Split Split(i, j) is the number of splits along dimension i of rectangle j.T T (i) is the number of times rectangle i has been trisected.G Matrix with constraint values for each point.ignoreidx Rectangles to be ignored in the rectangle selection procedure.I L I L(i, j) is the lower bound for rectangle j in integer dimension I(i).I U I U(i, j) is the upper bound for rectangle j in integer dimension I(i).feasible Flag indicating if a feasible point has been found.f min Best function value found at a feasible point.s 0 s 0 is used as s(0).s s(j) is the sum of observed rates of change for constraint j.t t(i) is the total number of splits along dimension i.

varargin Other parameters directly sent to low level routines.

103

Page 104: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Description of OutputsResult Structure with result from optimization. The following fields are changed:

Iter Number of iterations.FuncEv Number function evaluations.x k Matrix with all points giving the function value f k.f k Function value at optimum.c k Nonlinear constraints values at x k.GLOBAL Special structure field containing:C Matrix with all rectangle centerpoints.D Vector with distances from centerpoint to the vertices.F Vector with function values.Split Split(i, j) is the number of splits along dimension i of rectangle j.T T (i) is the number of times rectangle i has been trisected.G Matrix with constraint values for each point.ignoreidx Rectangles to be ignored in the rectangle selection procedure.I L I L(i, j) is the lower bound for rectangle j in integer dimension I(i).I U I U(i, j) is the upper bound for rectangle j in integer dimension I(i).feasible Flag indicating if a feasible point has been found.f min Best function value found at a feasible point.s 0 s 0 is used as s(0).s s(j) is the sum of observed rates of change for constraint j.t t(i) is the total number of splits along dimension i.Solver Solver used.SolverAlgorithm Solver algorithm used.

DescriptionThe routine glcSolve implements an extended version of DIRECT, see [41], that handles problems with bothnonlinear and integer constraints.

DIRECT is a modification of the standard Lipschitzian approach that eliminates the need to specify a Lipschitzconstant. Since no such constant is used, there is no natural way of defining convergence (except when the optimalfunction value is known). Therefore glcSolve is run for a predefined number of function evaluations and considersthe best function value found as the optimal one. It is possible for the user to restart glcSolve with the finalstatus of all parameters from the previous run. Let’s say that you have run glcSolve on a certain problem for 500function evaluations. Then you could run e.g. for 200 function evaluations more and let glcSolve search for a pointthat gives a lower function value. To restart glcSolve you must give the result of the first run as input to your nextrun.

DIRECT does not explicitly handle equality constraints. It works best when the integer variables describe anordered quantity and is less effective when they are categorical.

M-files UsediniSolve.m, endSolve.m

6.1.9 LineSearch

PurposeLineSearch solves line search problems of the form

min0<αmin≤α≤αmax

f(x(k) + αp)

where x, p ∈ Rn.

Calling SyntaxResult = LineSearch(f, g, x, p, f 0, g 0, optParam, alphaMax, alpha 1, pType, PriLev, varargin)

104

Page 105: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Description of Inputsf Name of m-file computing the objective function f(x).g Name of m-file computing the gradient vector g(x).x Current iterate x.p Search direction p.f 0 Function value at α = 0.g 0 Gradient at α = 0, the directed derivative at the present point.optParam Structure with special fields for optimization parameters, the following fields

are used:LineAlg Type of line search algorithm, se Table 7.LineSearch Structure with line search parameters, see Table 15.

alphaMax Maximal value of step length α.alpha 1 First step in α.pType Type of problem:

0 Normal problem.1 Nonlinear least squares.2 Constrained nonlinear least squares.3 Merit function minimization.4 Penalty function minimization.

PriLev Printing level:PriLev > 0 Writes a lot of output in LineSearch.PriLev > 3 Writes a lot of output in intpol2 and intpol3.

varargin Other parameters directly sent to low level routines.

Description of OutputsResult Result structure with fields:

alpha Optimal line search step α.f alpha Optimal function value at line search step α.g alpha Optimal gradient value at line search step α.alphaVec Vector of trial step length values.r k Residual vector if Least Squares problem, otherwise empty.J k Jacobian matrix if Least Squares problem, otherwise empty.f k Function value at x+ αp.g k Gradient value at x+ αp.c k Constraint value at x+ αp.dc k Constraint gradient value at x+ αp.

DescriptionThe function LineSearch together with the routines intpol2 and intpol3 implements a modified version of a linesearch algorithm by Fletcher [23]. The algorithm is based on the Wolfe-Powell conditions and therefore theavailability of first order derivatives is an obvious demand. It is also assumed that the user is able to supply alower bound fLow on f (α). More precisely it is assumed that the user is prepared to accept any value of f (α) forwhich f (α) ≤ fLow. For example in a nonlinear least squares problem fLow = 0 would be appropriate.

LineSearch consists of two parts, the bracketing phase and the sectioning phase. In the bracketing phase theiterates α(k) moves out in an increasingly large jumps until either f ≤ fLow is detected or a bracket on an intervalof acceptable points is located. The sectioning phase generates a sequence of brackets

[a(k), b(k)

]whose lengths

tend to zero. Each iteration pick a new point α(k) in[a(k), b(k)

]by minimizing a quadratic or a cubic polynomial

which interpolates f(a(k)

), f ′

(a(k)

), f

(b(k)

)and f ′

(b(k)

)if it is known. The sectioning phase terminates when

α(k) is an acceptable point.

AlgorithmSee Appendix A.4.

Functions Usedintpol2.m, intpol3.m

105

Page 106: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

6.1.10 intpol2

PurposeFind the minimum of a quadratic approximation of a scalar function in a given interval.

Calling Syntaxalfa = intpol2(x0, f0, g0, x1, f1, a, b, PriLev)

Description of Inputsx0 Interpolation point x0.f0 Function value at x0.g0 Derivative value at x0.x1 Interpolation point x1.f1 Function value at x1.a Lower interval bound.b Upper interval bound.PriLev Printing level, Prilev > 3 gives a lot of output.

Description of Outputsalfa The minimum of the interpolated second degree polynomial in the interval

[a, b].

DescriptionIn the line search routine LineSearch the problem of choosing α in a given interval [a, b] occurs both in the bracketingphase and in the sectioning phase. If quadratic interpolation are to be used LineSearch calls intpol2 which findsthe minimum of a second degree polynomial approximation in the given interval.

AlgorithmSee Appendix A.4.3.

See AlsoLineSearch, intpol3

6.1.11 intpol3

PurposeFind the minimum of a cubic approximation of a scalar function in a given interval.

Calling Syntaxalfa = intpol3(x0, f0, g0, x1, f1, g1 , a, b, PriLev)

Description of Inputsx0 Interpolation point x0.f0 Function value at x0.g0 Derivative value at x0.x1 Interpolation point x1.f1 Function value at x1.g1 Derivative value at x1.a Lower interval bound.b Upper interval bound.PriLev Printing level, Prilev > 3 gives a lot of output.

Description of Outputsalfa The minimum of the interpolated third degree polynomial in the interval

[a, b].

DescriptionIn the line search routine LineSearch the problem of choosing α in a given interval [a, b] occurs both in the bracketingphase and in the sectioning phase. If cubic interpolation are to be used LineSearch calls intpol3 which finds theminimum of a third degree polynomial approximation in the given interval.

AlgorithmSee Appendix A.4.4.

106

Page 107: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

See AlsoLineSearch, intpol2

6.1.12 lpSolve

PurposeSolve general linear programming problems.

lpSolve solves problems of the formminx

f(x) = cTx

s/t xL ≤ x ≤ xUbL ≤ Ax ≤ bU

where x, xL, xU ∈ Rn, c ∈ R

n, A ∈ Rm×n and bL, bU ∈ R

m.

Calling SyntaxResult = lpSolve(Prob)

Description of InputsProb Problem description structure. The following fields are used:

Solver.Alg Variable selection rule to be used:0: Minimum reduced cost.1: Bland’s rule (default).2: Minimum reduced cost. Dantzig’s rule.

QP.B Active set B 0 at start:B(i) = 1: Include variable x(i) is in basic set.B(i) = 0: Variable x(i) is set on its lower bound.B(i) = −1: Variable x(i) is set on its upper bound.

optParam Structure with special fields for optimization parameters, see Table 7.Fields used are: MaxIter, PriLev, wait, eps f, eps Rank, xTol and bTol.

QP.c Constant vector.A Constraint matrix for linear constraints.b L Lower bounds on the linear constraints.b U Upper bounds on the linear constraints.x L Lower bounds on the variables.x U Upper bounds on the variables.x 0 Starting point.

107

Page 108: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Description of OutputsResult Structure with result from optimization. The following fields are changed:

Iter Number of iterations.ExitFlag 0: OK.

1: Maximal number of iterations reached.2: Unbounded feasible region.3: Rank problems. Can not find any solution point.4: Illegal x 0.5: No feasible point x 0 found.

Inform If ExitF lag > 0, Inform = ExitF lag.QP.B Optimal active set. See input variable QP.B.f 0 Function value at start.f k Function value at optimum.g k Gradient value at optimum, c.x 0 Starting point.x k Optimal point.v k Lagrange multipliers.xState State of each variable, described in Table 17 .Solver Solver used.SolverAlgorithm Solver algorithm used.FuncEv Number of function evaluations. Equal to Iter.ConstrEv Number of constraint evaluations. Equal to Iter.Prob Problem structure used.

DescriptionThe routine lpSolve implements an active set strategy (Simplex method) for Linear Programming using an addi-tional set of slack variables for the linear constraints. If the given starting point is not feasible then a Phase Iobjective is used until a feasible point is found.

M-files UsedlpDef.m, ResultDef.m, Phase1Simplex.m, Phase2Simplex.m

See AlsoqpSolve

6.1.13 mipSolve

PurposeSolve mixed integer linear programming problems (MIP).

mipSolve solves problems of the form

minx

f(x) = cTx

s/t xL ≤ x ≤ xUAx = b, xj ∈ N∀j ∈I

where c, x, xL, xU ∈ Rn, A ∈ R

m×n and b ∈ Rm. The variables x ∈ I, the index subset of 1, ..., n are restricted to

be integers.

Calling Syntax[Result] = mipSolve(Prob)

108

Page 109: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Description of InputsProb Problem description structure. The following fields are used:

optParam.method Variable selection rule to be used:0: Minimum reduced cost.1: Bland’s rule (default).2: Minimum reduced cost. Dantzig’s rule.

MIP.IntVars Which of the n variables are integers.If IntVars is a scalar, then variables 1,...,IntVars are assumed to be integers.If empty, all variables are assumed non-integer (LP problem)If length(IntVars) ¿ 1 ==¿ length(IntVars) == length(c) must hold,

MIP.VarWeight Weight for each variable in the variable selection phase. A lower value gives higher prioriSetting Prob.MIP.VarWeight = c; for knapsack problems improve convergence.

MIP.fIP An upper bound on the IP value wanted. Makes it possible to cut branches and avoid noMIP.xIP The x-values giving the fIP value.MIP.KNAPSACK True if a knapsack problem is to be solved, then a knapsack heuristic is used.QP.B Active set B 0 at start:

B(i) = 1: Include variable x(i) is in basic set.B(i) = 0: Variable x(i) is set on its lower bound.B(i) = −1: Variable x(i) is set on its upper bound.

optParam Structure with special fields for optimization parameters, see Table 7.Fields used are: MaxIter, PriLev, wait, eps f, eps Rank, xTol and bTol.

QP.c Constant vector.A Constraint matrix for linear constraints.b L Lower bounds on the linear constraints.b U Upper bounds on the linear constraints.x L Lower bounds on the variables.x U Upper bounds on the variables.x 0 Starting point.

Description of OutputsResult Structure with result from optimization. The following fields are changed:

Iter Number of iterations.ExitFlag 0: OK.

1: Maximal number of iterations reached.2: Unbounded feasible region.3: Rank problems. Can not find any solution point.4: No feasible point x 0 found.5: Illegal x 0.

Inform If ExitF lag > 0, Inform = ExitF lag.QP.B Optimal active set. See input variable QP.B.f 0 Function value at start.f k Function value at optimum.g k Gradient value at optimum, c.x 0 Starting point.x k Optimal point.v k Lagrange multipliers.xState State of each variable, described in Table 17 .Solver Solver used.SolverAlgorithm Solver algorithm used.FuncEv Number of function evaluations. Equal to Iter.ConstrEv Number of constraint evaluations. Equal to Iter.Prob Problem structure used.

DescriptionThe routinemipSolve is an implementation of a branch and bound algorithm from Nemhauser andWolsey [47, chap.8.2]. mipSolve normally uses the linear programming routines lpSolve and DualSolve to solve relaxed subproblems.mipSolve calls the general interface routines SolveLP and SolveDLP. By changing the setting of the structure

109

Page 110: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

fields Prob.Solver.SolverLP and Prob.Solver.SolverDLP, different sub-solvers are possible to use, see the help forthe interface routines.

AlgorithmSee [47, chap. 8.2] and the code in mipSolve.m.

ExamplesSee exip39, exknap, expkorv.

M-files UsedlpDef.m, lpSolve.m, DualSolve.m

See Alsocutplane, balas, SolveLP, SolveDLP

6.1.14 nlpSolve

PurposeSolve general constrained nonlinear optimization problems.

nlpSolve solves problems of the form

minx

f(x)

s/t xL ≤ x ≤ xUbL ≤ Ax ≤ bUcL ≤ c(x) ≤ cU

where x, xL, xU ∈ Rn, c(x), cL, cU ∈ R

m1 , A ∈ Rm2×n and bL, bU ∈ R

m2 .

Calling SyntaxResult = nlpSolve(Prob, varargin)

Description of InputsProb Problem description structure. The following fields are used:

optParam Structure with special fields for optimization parameters, see Table 7.Fields used are: eps g, eps c, eps x, MaxIter, wait, size x, PriLev, method andQN InitMatrix.

A Constraint matrix for linear constraints.b L Lower bounds on the linear constraints.b U Upper bounds on the linear constraints.c L Lower bounds on the general constraints.c U Upper bounds on the general constraints.x L Lower bounds on the variables.x U Upper bounds on the variables.x 0 Starting point.USER.f Name of m-file computing the objective function f(x).USER.g Name of m-file computing the gradient vector g(x).USER.H Name of m-file computing the Hessian matrix H(x).USER.c Name of m-file computing the vector of constraint functions c(x).USER.dc Name of m-file computing the matrix of constraint normals ∂c(x)/dx.USER.d2c Name of m-file computing the second derivatives of the constraints, weighted by an input Lagran

varargin Other parameters directly sent to low level routines.

110

Page 111: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Description of OutputsResult Structure with result from optimization. The following fields are changed:

Iter Number of iterations.ExitFlag Flag giving exit status.ExitFlag 0: Convergence. Small step. Constraints fulfilled.

1: Infeasible problem?2: Maximal number of iterations reached.

Inform Type of convergence.f 0 Function value at start.f k Function value at optimum.g k Gradient value at optimum.H k Hessian value at optimum.x 0 Starting point.x k Optimal point.v k Lagrange multipliers.c k Value of constraints at optimum.cJac Constraint Jacobian at optimum.xState State of each variable, described in Table 17 .bState State of each linear constraint, described in Table 18.cState State of each general constraint.Solver Solver used.SolverAlgorithm Solver algorithm used.Prob Problem structure used.

DescriptionThe routine nlpSolve implements the Filter SQP by Roger Fletcher and Sven Leyffer presented in the paper [24].

M-files UsedconDef.m, lpDef.m, Phase1Simplex.m, iniSolve.m, endSolve.m

See AlsoconSolve, sTrustr

6.1.15 preSolve

PurposeSimplify the structure of the constraints and the variable bounds in a linear constrained program.

Calling SyntaxProb = preSolve(Prob)

Description of InputsProb Problem description structure. The following fields are used:

A Constraint matrix for linear constraints.b L Lower bounds on the linear constraints.b U Upper bounds on the linear constraints.x L Lower bounds on the variables.x U Upper bounds on the variables.

Description of OutputsProb Problem description structure. The following fields are changed:

A Constraint matrix for linear constraints.b L Lower bounds on the linear constraints, set to NaN for redundant constraints.b U Upper bounds on the linear constraints, set to NaN for redundant constraints.x L Lower bounds on the variables.x U Upper bounds on the variables.

DescriptionThe routine preSolve is an implementation of those presolve analysis techniques described by Gondzio in [31],which is applicable to general linear constrained problems. See [10] for a more detailed presentation.

111

Page 112: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

preSolve consists of the two routines clean and mksp. They are called in the sequence clean, mksp, clean. Thesecond call to clean is skipped if the mksp routine could not remove a single nonzero entry from A.

clean consists of two routines, r rw sng that removes singleton rows and el cnsts that improves variable boundsand uses them to eliminate redundant and forcing constraints. Both r rw sng and el cnsts check if empty rowsappear and eliminate them if so. That is handled by the routine emptyrow. In clean the calls to r rw sng andel cnsts are repeated (in given order) until no further reduction is obtained.

Note that rows are actually not deleted or removed, instead preSolve indicates that constraint i is redundant bysetting b L(i) = b U(i) = NaN and leaves to the calling routine to decide what to do with those constraints.

6.1.16 qpe

PurposeSolve equality constrained quadratic programming problems.

qpe solves problems of the formminx

f(x) = 12 (x)

TFx+ cTx

s/t Ax = b

where x, c ∈ Rn, F ∈ R

n×n, A ∈ Rm×n and b ∈ R

m.

Calling Syntax[x, lambda, QZ, RZ] = qpe(F, c, A, b)

Description of InputsF Constant matrix, the Hessain.c Constant vector.A Constraint matrix for the linear constraints.b Right hand side vector.

Description of Outputsx Optimal point.lambda Lagrange multipliers.QZ The matrix Q in the QR-decomposition of F .RZ The matrix R in the QR-decomposition of F .

DescriptionThe routine qpe solves a quadratic programming problem, restricted to equality constraints, using a null spacemethod.

See AlsoqpBiggs, qpSolve, qplm

6.1.17 qpBiggs

PurposeSolve general quadratic programming problems.

qpBiggs solves problems of the form

minx

f(x) = 12 (x)

TFx+ cTx

s/t bi = aTi x i = 1, 2, ...,mebi ≤ aTi x i = me+ 1, ...,mxL ≤ x ≤ xU

where x, xL, xU ∈ Rn, F ∈ R

n×n, c ∈ Rn, A ∈ R

m×n and b ∈ Rm.

Calling Syntax[x, lambda, err, p vec, alfa vec] = qpBiggs(F, c, A, b, x L, x U, x0, me, PriLev, wait)

112

Page 113: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Description of InputsF Constant matrix, the Hessain.c Constant vector.A Constraint matrix for the linear constraints.b Right hand side vector.x L Lower bounds on the variables.x U Upper bounds on the variables.x0 Starting point.me Number of equality constraints, stored first in A and b.PriLev Print level: 0 None, 1 Final result, 2 Each iteration.wait Pause at each iteration if wait is true.

Description of Outputsx Optimal point.lambda Lagrange multipliers. Constraints, lower and upper variable bounds.err Error flag. 0 if OK; 1− 4 different failures.p vec All search directions p.alfa vec All step lengths α.

DescriptionThe implementation of qpBiggs is similar to qpSolve, but for negative definite quadratic problems uses the algorithmdescribed in M.C. Bartholomew-Biggs [6].

See AlsoqpSolve, qpe, qplm

6.1.18 qplm

PurposeSolve equality constrained quadratic programming problems.

qplm solves problems of the formminx

f(x) = 12 (x)

TFx+ cTx

s/t Ax = b

where x, c ∈ Rn, F ∈ R

n×n, A ∈ Rm×n and b ∈ R

m.

Calling Syntax[x, lambda] = qplm(F, c, A, b)

Description of InputsF Constant matrix, the Hessain.c Constant vector.A Constraint matrix for the linear constraints.b Right hand side vector.

Description of Outputsx Optimal point.lambda Lagrange multipliers.

DescriptionThe routine qplm solves a quadratic programming problem, restricted to equality constraints, using the Lagrangemethod.

See AlsoqpBiggs, qpSolve, qpe

6.1.19 qpSolve

PurposeSolve general quadratic programming problems.

113

Page 114: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

qpSolve solves problems of the form

minx

f(x) = 12 (x)

TFx+ cTx

s/t xL ≤ x ≤ xUbL ≤ Ax ≤ bU

where x, xL, xU ∈ Rn, F ∈ R

n×n, c ∈ Rn, A ∈ R

m×n and bL, bU ∈ Rm.

Calling SyntaxResult = qpSolve(Prob)

Description of InputsProb Problem description structure. The following fields are used:

optParam Structure with special fields for optimization parameters, see Table 7.Fields used are: eps f, eps Rank, MaxIter, wait, bTol and PriLev.

QP.F Constant matrix, the Hessian.QP.c Constant vector.A Constraint matrix for linear constraints.b L Lower bounds on the linear constraints.b U Upper bounds on the linear constraints.x L Lower bounds on the variables.x U Upper bounds on the variables.x 0 Starting point.

Description of OutputsResult Structure with result from optimization. The following fields are changed:

Iter Number of iterations.ExitFlag 0: OK, see Inform for type of convergence.

2: Can not find feasible starting point x 0.3: Rank problems. Can not find any solution point.4: Unbounded solution.

Inform If ExitF lag > 0, Inform = ExitF lag, otherwise Inform show type ofconvergence:0: Unconstrained solution.1: λ ≥ 0.2: λ ≥ 0. No second order Lagrange mult. estimate available.3: λ and 2nd order Lagr. mult. positive, problem is not negative definite.4: Negative definite problem. 2nd order Lagr. mult. positive, but releasing

variables leads to the same working set.f 0 Function value at start.f k Function value at optimum.g k Gradient value at optimum.H k Hessian value at optimum.x 0 Starting point.x k Optimal point.v k Lagrange multipliers.xState State of each variable, described in Table 17 .Solver Solver used.SolverAlgorithm Solver algorithm used.Prob Problem structure used.

DescriptionImplements an active set strategy for Quadratic Programming. For negative definite problems it computes eigen-values and is using directions of negative curvature to proceed. To find an initial feasible point the Phase 1 LPproblem is solved calling lpSolve. The routine is the standard QP solver used by nlpSolve, sTrustr and conSolve.

M-files UsedqpDef.m, ResultDef.m, lpDef.m, lpSolve.m, iniSolve.m, endSolve.m

See AlsoqpBiggs, qpe, qplm, nlpSolve, sTrustr and conSolve

114

Page 115: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

6.1.20 sTrustr

PurposeSolve optimization problems constrained by a convex feasible region.

sTrustr solves problems of the formminx

f(x)

s/t xL ≤ x ≤ xUbL ≤ Ax ≤ bUcL ≤ c(x) ≤ cU

where x, xL, xU ∈ Rn, c(x), cL, cU ∈ R

m1 , A ∈ Rm2×n and bL, bU ∈ R

m2 .

Calling SyntaxResult = sTrustr(Prob, varargin)

Description of InputsProb Problem description structure. The following fields are used:

optParam Structure with special fields for optimization parameters, see Table 7.Fields used are: eps f, eps g, eps c, eps x, eps Rank, MaxIter, wait, size x, size f,xTol, LowIts, PriLev, method and QN InitMatrix.

PartSep Structure with special fields for partially separable functions, see Table 12.A Constraint matrix for linear constraints.b L Lower bounds on the linear constraints.b U Upper bounds on the linear constraints.c L Lower bounds on the general constraints.c U Upper bounds on the general constraints.x L Lower bounds on the variables.x U Upper bounds on the variables.x 0 Starting point.USER.f Name of m-file computing the objective function f(x).USER.g Name of m-file computing the gradient vector g(x).USER.H Name of m-file computing the Hessian matrix H(x).USER.c Name of m-file computing the vector of constraint functions c(x).USER.dc Name of m-file computing the matrix of constraint normals ∂c(x)/dx.

varargin Other parameters directly sent to low level routines.

115

Page 116: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Description of OutputsResult Structure with result from optimization. The following fields are changed:

Iter Number of iterations.ExitFlag Flag giving exit status.Inform Binary code telling type of convergence:

1: Iteration points are close.2: Projected gradient small.4: Relative function value reduction low for LowIts iterations.8: Too small trust region.101: Maximum number of iterations reached.102: Function value below given estimate.103: Convergence to saddle point (eigenvalues computed).

f 0 Function value at start.f k Function value at optimum.g k Gradient value at optimum.H k Hessian value at optimum.x 0 Starting point.x k Optimal point.v k Lagrange multipliers.c k Value of constraints at optimum.cJac Constraint Jacobian at optimum.xState State of each variable, described in Table 17 .Solver Solver used.SolverAlgorithm Solver algorithm used.Prob Problem structure used.

DescriptionThe routine sTrustr is a solver for general constrained optimization, which uses a structural trust region algorithmcombined with an initial trust region radius algorithm (itrr). The feasible region defined by the constraints mustbe convex. The code is based on the algorithms in [16] and [51]. BFGS or DFP is used for the Quasi-Newtonupdate, if the analytical Hessian is not used. sTrustr calls itrr.

Functions Useditrr.m

M-files UsedconDef.m, qpoptSOL.m, qpSolve.m, iniSolve.m, endSolve.m

See AlsoconSolve, nlpSolve, clsSolve

6.1.21 itrr

PurposeDetermine the initial trust region radius.

Calling Syntax[D 0, f 0, x 0] = itrr(x 0, fS, gS, HS, jMax, iMax, Prob, varargin)

116

Page 117: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Description of Inputsx 0 Starting point.x L Lower bounds for x.x U Upper bounds for x.fS String with function call sequence. x k current point.gS String with gradient call sequence. x k current point.HS String with Hessian call sequence. x k current point.jMax Number of outer iterations, normally 1.iMax Number of inner iterations, normally 5.Prob Prob.PartSep.index is the index for the partial function to be analyzed.varargin Extra user parameters, passed to f , g and H;

Description of OutputsD 0 Initial trust region radius.f 0 Function value at the input starting point x 0.x 0 Updated starting point, if jMax > 1.

DescriptionThe routine itrr implements the initial trust region radius algorithm as described by Sartenaer in [51]. itrr is calledby sTrustr.

See AlsosTrustr

6.1.22 ucSolve

PurposeSolve unconstrained nonlinear optimization problems with simple bounds on the variables.

ucSolve solves problems of the formminx

f(x)

s/t xL ≤ x ≤ xU

where x, xL, xU ∈ Rn.

Calling SyntaxResult = ucSolve(Prob, varargin)

Description of InputsProb Problem description structure. The following fields are used:

Solver.Alg Solver algorithm to be run:0: Newton.1: Safeguarded BFGS (default).2: Safeguarded Inverse BFGS.3: Safeguarded Inverse DFP.4: Safeguarded DFP.5: Fletcher-Reeves CG.6: Polak-Ribiere CG.7: Fletcher conjugate descent CG-method.

optParam Structure with special fields for optimization parameters, see Table 7.Fields used are: eps f, eps g, eps x, eps Rank, MaxIter, wait, size x, size f, f Low,LineSearch, LineAlg, xTol, LowIts, method, PriLev and QN InitMatrix.

x L Lower bounds on the variables.x U Upper bounds on the variables.x 0 Starting point.USER.f Name of m-file computing the objective function f(x).USER.g Name of m-file computing the gradient vector g(x).USER.H Name of m-file computing the Hessian matrix H(x).f Low Lower bound on function value.

varargin Other parameters directly sent to low level routines.

117

Page 118: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Description of OutputsResult Structure with result from optimization. The following fields are changed:

Iter Number of iterations.ExitFlag 0 if convergence to local min. Otherwise errors.Inform Binary code telling type of convergence:

1: Iteration points are close.2: Projected gradient small.4: Relative function value reduction low for LowIts iterations.101: Maximum number of iterations reached.102: Function value below given estimate.104: Convergence to a saddle point.

f 0 Function value at start.f k Function value at optimum.g k Gradient value at optimum.H k Hessian value at optimum.B k Quasi-Newton approximation of the Hessian at optimum.x 0 Starting point.x k Optimal point.v k Lagrange multipliers.xState State of each variable, described in Table 17 .Solver Solver used.SolverAlgorithm Solver algorithm used.Prob Problem structure used.

DescriptionThe solver ucSolve includes several of the most popular search step methods for unconstrained optimization.The search step methods included in ucSolve are: the Newton method, the quasi-Newton BFGS and inverseBFGS method, the quasi-Newton DFP and inverse DFP method, the Fletcher-Reeves and Polak-Ribiere conjugategradient method, and the Fletcher conjugate descent method. For the Newton and the quasi-Newton methods thecode is using a subspace minimization technique to handle rank problem, see Lindstrom [43]. The quasi-Newtoncodes also use safe guarding techniques to avoid rank problem in the updated matrix. The line search is performedusing the routine LineSearch which is a modified version of an algorithm by Fletcher [23]. Bound constraints aretreated as described in Gill, Murray and Wright [29].

AlgorithmSee Appendix A.5.

M-files UseducDef.m, ResultDef.m, LineSearch.m, iniSolve.m, endSolve.m

See AlsoclsSolve

6.2 Driver Routines in TOMLAB

In the following subsections the driver routines in TOMLAB will be described.

6.2.1 clsRun

PurposeDriver routine for constrained nonlinear least squares solvers.

Calling SyntaxResult = clsRun(Solver, Prob, ask, PriLev, probFile, probNumber)

118

Page 119: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Description of InputsSolver The name of the solver that should be used to optimize the problem. Default

clsSolve. If the solver may run several different optimization algorithms,then the values of Prob.optParam.alg and Prob.optParam.subalg determineswhich algorithm.

Prob Problem description structure, see Table 5.ask Flag if questions should be asked during problem definition.

ask < 0 Use values in Prob.uP if defined or defaults.ask = 0 Use defaults.ask ≥ 1 Ask questions in probFile.ask = [ ] If Prob.uP = [ ], ask = −1, else ask = 0.

PriLev Print level when displaying the result of the optimization in the routinePrintResult. See Section 6.3.2 page 128.PriLev = 0 No output.PriLev = 1 Final result, shorter version.PriLev = 2 Final result.PriLev = 3 Full results.

The printing level in the optimization solver is controlled by setting theparameter Prob.optParam.PriLev.

probFile User problem init file, default cls prob.m.probNumber Problem number in probFile. probNumber = 0 gives a menu in probFile.

Description of OutputsResult Structure with result from optimization, see Table 16.

DescriptionThe driver routine clsRun is called by the menu routine clsOpt or the graphical user interface routine tomlabGUIto solve constrained nonlinear least squares problems defined in your problem definition files. It is also possiblefor the user to call clsRun directly from the Matlab command prompt, see Section 3.8. Via clsRun you can runthe TOMLAB internal solvers clsSolve and conSolve and the Matlab Optimization Toolbox solver constr. Youcan also, by use of a MEX-file interface run the commercial optimization solvers NLSSOL, MINOS, NPSOL andNPOPT.

M-files UsedxxxRun.m, xxxRun2.m, npopt.m, inibuild.m, clsDef.m, probInit.m, mkbound.m, clsSolve.m, conSolve.m, solrun.m,nlssol.m, minos.m, npsol.m, PrintResult.m, iniSolve.m, endSolve.m

6.2.2 conRun

PurposeDriver routine for constrained optimization solvers.

Calling SyntaxResult = conRun(Solver, Prob, ask, PriLev, probFile, probNumber)

119

Page 120: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Description of InputsSolver The name of the solver that should be used to optimize the problem. Default

conSolve. If the solver may run several different optimization algorithms,then the values of Prob.optParam.alg and Prob.optParam.subalg determineswhich algorithm.

Prob Problem description structure, see Table 5.ask Flag if questions should be asked during problem definition.

ask < 0 Use values in uP if defined or defaults.ask = 0 Use defaults.ask ≥ 1 Ask questions in probFile.ask = [ ] If uP = [ ], ask = −1, else ask = 0.

PriLev Print level when displaying the result of the optimization in the routinePrintResult. See Section 6.3.2 page 128.PriLev = 0 No output.PriLev = 1 Final result, shorter version.PriLev = 2 Final result.PriLev = 3 Full results.

The printing level in the optimization solver is controlled by setting theparameter Prob.optParam.PriLev.

probFile User problem init file, default con prob.m.probNumber Problem number in probFile. probNumber = 0 gives a menu in probFile.

Description of OutputsResult Structure with result from optimization, see Table 16.

DescriptionThe driver routine conRun is called by the menu routine conOpt or the graphical user interface routine tomlabGUIto solve constrained optimization problems defined in your problem definition files. It is also possible for the userto call conRun directly from the Matlab command prompt, see Section 3.8. Via conRun you can run the TOMLABinternal solvers conSolve, sTrustr and nlpSolve and the Matlab Optimization Toolbox solver constr. You can also,by use of a MEX-file interface run the commercial optimization solvers MINOS, NPSOL and NPOPT.

M-files UsedxxxRun.m, xxxRun2.m, PrintResult.m, inibuild.m, conDef.m, probInit.m, mkbound.m, conSolve.m, nlpSolve.m,solrun.m, minos.m, npsol.m, npopt.m

6.2.3 glbRun

PurposeDriver routine for box-bounded global optimization.

Calling SyntaxResult = glbRun(Solver, Prob, ask, PriLev, probFile, probNumber)

120

Page 121: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Description of InputsSolver The name of the solver that should be used to optimize the problem. Default

glbSolve. If the solver may run several different optimization algorithms,then the values of Prob.optParam.alg and Prob.optParam.subalg determineswhich algorithm.

Prob Problem description structure, see Table 5.ask Flag if questions should be asked during problem definition.

ask < 0 Use values in uP if defined or defaults.ask = 0 Use defaults.ask ≥ 1 Ask questions in probFile.ask = [ ] If uP = [ ], ask = −1, else ask = 0.

PriLev Print level when displaying the result of the optimization in the routinePrintResult. See Section 6.3.2 page 128.PriLev = 0 No output.PriLev = 1 Final result, shorter version.PriLev = 2 Final result.PriLev = 3 Full results.

The printing level in the optimization solver is controlled by setting theparameter Prob.optParam.PriLev.

probFile User problem init file, default glb prob.m.probNumber Problem number in probFile. probNumber = 0 gives a menu in probFile.

Description of OutputsResult Structure with result from optimization, see Table 16.

DescriptionThe driver routine glbRun is called by the menu routine glbOpt or the graphical user interface routine tomlabGUIto solve global optimization problems defined in your problem definition files. It is also possible for the user tocall glbRun directly from the Matlab command prompt, see Section 3.8. Via glbRun you can run the TOMLABinternal solver glbSolve.

M-files UsedxxxRun.m, xxxRun2.m, PrintResult.m, inibuild.m, ucDef.m, probInit.m, mkbound.m, glbSolve.m, iniSolve.m,endSolve.m

6.2.4 glcRun

PurposeDriver routine for global mixed-integer nonlinear programming.

Calling SyntaxResult = glcRun(Solver, Prob, ask, PriLev, probFile, probNumber)

121

Page 122: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Description of InputsSolver The name of the solver that should be used to optimize the problem. Default

glcSolve. If the solver may run several different optimization algorithms,then the values of Prob.optParam.alg and Prob.optParam.subalg determineswhich algorithm.

Prob Problem description structure, see Table 5.ask Flag if questions should be asked during problem definition.

ask < 0 Use values in uP if defined or defaults.ask = 0 Use defaults.ask ≥ 1 Ask questions in probFile.ask = [ ] If uP = [ ], ask = −1, else ask = 0.

PriLev Print level when displaying the result of the optimization in the routinePrintResult. See Section 6.3.2 page 128.PriLev = 0 No output.PriLev = 1 Final result, shorter version.PriLev = 2 Final result.PriLev = 3 Full results.

The printing level in the optimization solver is controlled by setting theparameter Prob.optParam.PriLev.

probFile User problem init file, default glc prob.m.probNumber Problem number in probFile. probNumber = 0 gives a menu in probFile.

Description of OutputsResult Structure with result from optimization, see Table 16.

DescriptionThe driver routine glcRun is called by the menu routine glcOpt or the graphical user interface routine tomlabGUIto solve constrained global optimization problems defined in your problem definition files. It is also possible forthe user to call glcRun directly from the Matlab command prompt, see Section 3.8. Via glcRun you can run theTOMLAB internal solver glcSolve.

M-files UsedxxxRun.m, xxxRun2.m, PrintResult.m, inibuild.m, conDef.m, probInit.m, mkbound.m, glcSolve.m, iniSolve.m,endSolve.m

6.2.5 lpRun

PurposeDriver routine for linear programming solvers.

Calling SyntaxResult = lpRun(Solver, Prob, ask, PriLev, probFile, probNumber)

122

Page 123: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Description of InputsSolver The name of the solver that should be used to optimize the problem. Default

lpSolve. If the solver may run several different optimization algorithms,then the values of Prob.optParam.alg and Prob.optParam.subalg determineswhich algorithm.

Prob Problem description structure, see Table 5.ask Flag if questions should be asked during problem definition.

ask < 0 Use values in uP if defined or defaults.ask = 0 Use defaults.ask ≥ 1 Ask questions in probFile.ask = [ ] If uP = [ ], ask = −1, else ask = 0.

PriLev Print level when displaying the result of the optimization in the routinePrintResult. See Section 6.3.2 page 128.PriLev = 0 No output.PriLev = 1 Final result, shorter version.PriLev = 2 Final result.PriLev = 3 Full results.

The printing level in the optimization solver is controlled by setting theparameter Prob.optParam.PriLev.

probFile User problem init file, default lp prob.m.probNumber Problem number in probFile. probNumber = 0 gives a menu in probFile.

Description of OutputsResult Structure with result from optimization, see Table 16.

DescriptionThe driver routine lpRun is called by the menu routine lpOpt or the graphical user interface routine tomlabGUI tosolve linear programming problems defined in your problem definition files. It is also possible for the user to calllpRun directly from the Matlab command prompt, see Section 2.1. Via lpRun you can run the TOMLAB internalsolvers lpSolve, lpsimp2 and akarmark and the Matlab Optimization Toolbox solver lp. You can also, by use of aMEX-file interface run the commercial optimization solvers MINOS and QPOPT.

M-files UsedxxxRun.m, xxxRun2.m, inibuild.m, lpDef.m, probInit.m, mkbound.m, lpSolve.m, lpsimp2.m, akarmark.m, lp.m,qpoptSOL.m, minos.m, PrintResult.m, iniSolve.m, endSolve.m

6.2.6 lsRun

PurposeDriver routine for nonlinear least squares solvers.

Calling SyntaxResult = lsRun(Solver, Prob, ask, PriLev, probFile, probNumber)

123

Page 124: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Description of InputsSolver The name of the solver that should be used to optimize the problem. Default

clsSolve. If the solver may run several different optimization algorithms,then the values of Prob.optParam.alg and Prob.optParam.subalg determineswhich algorithm.

Prob Problem description structure, see Table 5.ask Flag if questions should be asked during problem definition.

ask < 0 Use values in uP if defined or defaults.ask = 0 Use defaults.ask ≥ 1 Ask questions in probFile.ask = [ ] If uP = [ ], ask = −1, else ask = 0.

PriLev Print level when displaying the result of the optimization in the routinePrintResult. See Section 6.3.2 page 128.PriLev = 0 No output.PriLev = 1 Final result, shorter version.PriLev = 2 Final result.PriLev = 3 Full results.

The printing level in the optimization solver is controlled by setting theparameter Prob.optParam.PriLev.

probFile User problem init file, default ls prob.m.probNumber Problem number in probFile. probNumber = 0 gives a menu in probFile.

Description of OutputsResult Structure with result from optimization, see Table 16.

DescriptionThe driver routine lsRun is called by the menu routine lsOpt or the graphical user interface routine tomlabGUIto solve nonlinear least squares problems defined in your problem definition files. It is also possible for the userto call lsRun directly from the Matlab command prompt, see Section 3.8. Via lsRun you can run the TOMLABinternal solvers clsSolve and ucSolve and the MatlabOptimization Toolbox solver leastsq. You can also, by use ofa MEX-file interface run the commercial optimization solver NLSSOL.

M-files UsedxxxRun.m, xxxRun2.m, PrintResult.m, inibuild.m, lsDef.m, probInit.m,mkbound.m, clsSolve.m, ucSolve.m, solrun.m,nlssol.m, iniSolve.m, endSolve.m

6.2.7 mipRun

PurposeDriver routine for mixed-integer programming solvers.

Calling SyntaxResult = mipRun(Solver, Prob, ask, PriLev, probFile, probNumber)

124

Page 125: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Description of InputsSolver The name of the solver that should be used to optimize the problem. Default

mipSolve. If the solver may run several different optimization algorithms,then the values of Prob.optParam.alg and Prob.optParam.subalg determineswhich algorithm.

Prob Problem description structure, see Table 5.ask Flag if questions should be asked during problem definition.

ask < 0 Use values in uP if defined or defaults.ask = 0 Use defaults.ask ≥ 1 Ask questions in probFile.ask = [ ] If uP = [ ], ask = −1, else ask = 0.

PriLev Print level when displaying the result of the optimization in the routinePrintResult. See Section 6.3.2 page 128.PriLev = 0 No output.PriLev = 1 Final result, shorter version.PriLev = 2 Final result.PriLev = 3 Full results.

The printing level in the optimization solver is controlled by setting theparameter Prob.optParam.PriLev.

probFile User problem init file, default lp prob.m.probNumber Problem number in probFile. probNumber = 0 gives a menu in probFile.

Description of OutputsResult Structure with result from optimization, see Table 16.

DescriptionThe driver routine mipRun is called by the menu routine mipOpt or the graphical user interface routine tomlabGUIto solve linear programming problems defined in your problem definition files. It is also possible for the user to callmipRun directly from the Matlab command prompt, see Section 2.3. Via mipRun you can run the TOMLAB in-ternal solvers mipSolve and cutplane. You can also, by use of a MEX-file interface run the commercial optimizationsolver XPRESS/MP.

M-files UsedxxxRun.m, xxxRun2.m, inibuild.m lpDef.m, probInit.m,mkbound.m,mipSolve.m, cutplane.m, PrintResult.m, iniSolve.m,endSolve.m

6.2.8 qpRun

PurposeDriver routine for quadratic programming solvers.

Calling SyntaxResult = qpRun(Solver, Prob, ask, PriLev, probFile, probNumber)

125

Page 126: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Description of InputsSolver The name of the solver that should be used to optimize the problem. Default

qpSolve. If the solver may run several different optimization algorithms,then the values of Prob.optParam.alg and Prob.optParam.subalg determineswhich algorithm.

Prob Problem description structure, see Table 5.ask Flag if questions should be asked during problem definition.

ask < 0 Use values in uP if defined or defaults.ask = 0 Use defaults.ask ≥ 1 Ask questions in probFile.ask = [ ] If uP = [ ], ask = −1, else ask = 0.

PriLev Print level when displaying the result of the optimization in the routinePrintResult. See Section 6.3.2 page 128.PriLev = 0 No output.PriLev = 1 Final result, shorter version.PriLev = 2 Final result.PriLev = 3 Full results.

The printing level in the optimization solver is controlled by setting theparameter Prob.optParam.PriLev.

probFile User problem init file, default qp prob.m.probNumber Problem number in probFile. probNumber = 0 gives a menu in probFile.

Description of OutputsResult Structure with result from optimization, see Table 16.

DescriptionThe driver routine qpRun is called by the menu routine qpOpt or the graphical user interface routine tomlabGUIto solve quadratic programming problems defined in your problem definition files. It is also possible for the userto call qpRun directly from the Matlab command prompt, see Section 3.8. Via qpRun you can run the TOMLABinternal solvers qpe, qplm and qpiSolve and the Matlab Optimization Toolbox solver qp. TOMLAB also includesa routine qpBiggs, but it is not as stable as qpiSolve.

M-files UsedxxxRun.m, xxxRun2.m, PrintResult.m, inibuild.m, conDef.m, probInit.m, mkbound.m, qpe.m, qplm.m, qpSolve.m,qpBiggs.m, iniSolve.m, endSolve.m

6.2.9 ucRun

PurposeDriver routine for unconstrained optimization solvers.

Calling SyntaxResult = ucRun(Solver, Prob, ask, PriLev, probFile, probNumber)

126

Page 127: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Description of InputsSolver The name of the solver that should be used to optimize the problem. Default

ucSolve. If the solver may run several different optimization algorithms,then the values of Prob.optParam.alg and Prob.optParam.subalg determineswhich algorithm.

Prob Problem description structure, see Table 5.ask Flag if questions should be asked during problem definition.

ask < 0 Use values in uP if defined or defaults.ask = 0 Use defaults.ask ≥ 1 Ask questions in probFile.ask = [ ] If uP = [ ], ask = −1, else ask = 0.

PriLev Print level when displaying the result of the optimization in the routinePrintResult. See Section 6.3.2 page 128.PriLev = 0 No output.PriLev = 1 Final result, shorter version.PriLev = 2 Final result.PriLev = 3 Full results.

The printing level in the optimization solver is controlled by setting theparameter Prob.optParam.PriLev.

probFile User problem init file, default uc prob.m.probNumber Problem number in probFile. probNumber = 0 gives a menu in probFile.

Description of OutputsResult Structure with result from optimization, see Table 16.

DescriptionThe driver routine ucRun is called by the menu routine ucOpt or the graphical user interface routine tomlabGUI tosolve unconstrained optimization problems defined in your problem definition files. It is also possible for the userto call ucRun directly from the Matlab command prompt, see Section 3.8. Via ucRun you can run the TOMLABinternal solver ucSolve and the Matlab Optimization Toolbox solvers fmins and fminu. You can also, by use of aMEX-file interface run the commercial optimization solver MINOS.

M-files UsedxxxRun.m, xxxRun2.m, xxxRun3.m, inibuild.m, ucDef.m, probInit.m, mkbound.m, ucSolve.m, minos.m, iniSolve.m,endSolve.m

6.3 Utility Functions in TOMLAB

In the following subsections the utility functions in TOMLAB will be described.

6.3.1 cpTransf

PurposeTransform general convex programs on the form

minx

f(x)

s/t xL ≤ x ≤ xUbL ≤ Ax ≤ bU

where x, xL, xU ∈ Rn, A ∈ R

m×n and bL, bU ∈ Rm, to other forms.

Calling Syntax[AA, bb, meq] = cpTransf(Prob, TransfType, makeEQ, LowInf)

127

Page 128: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Description of InputsProb Problem description structure. The following fields are used:

QP.c Constant vector c in cTx.A Constraint matrix for linear constraints.b L Lower bounds on the linear constraints.b U Upper bounds on the linear constraints.x L Lower bounds on the variables.x U Upper bounds on the variables.

TransfType Type of transformation, see the description below.MakeEQ Flag, if set true, make standard form (all equalities).LowInf Variables equal to −Inf or variables < LowInf are set to LowInf before

transforming the problem. Default −10−4. |LowInf | are limit if upperbound variables are to be used.

Description of OutputsAA The expanded linear constraint matrix.bb The expanded upper bounds for the linear constraints.meq The first meq equations are equalities.

DescriptionIf TransType = 1 the program is transformed into the form

minx

f(x− xL)s/t AA(x− xL) ≤ bb

x− xL ≥ 0

where the first meq constraints are equalities. Translate back with (fixed variables do not change their values):

x(~x_L==x_U) = (x-x_L) + x_L(~x_L==x_U)

If TransType = 2 the program is transformed into the form

minx

f(x)

s/t AA(x) ≤ bbxL ≤ x ≤ xU

where the first meq constraints are equalities.

If TransType = 3 the program is transformed into the form

minx

f(x)

s/t AAx ≤ bbx ≥ xL

where the first meq constraints are equalities.

6.3.2 PrintResult

PurposePrints the result of an optimization.

Calling SyntaxPrintResult(Result, PriLev)

128

Page 129: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Description of InputsResult Result structure from optimization.PriLev Printing level:0 Silent.1 Problem number and name. Function value at the solution and at start.

Known optimal function value (if given).2 Optimal point x and starting point x 0. Number of evaluations of the func-

tion, gradient etc. Lagrange multipliers, both returned and TOMLAB esti-mate. Distance from start to solution. The residual, gradient and projectedgradient. ExitF lag and Inform.

3 Jacobian, Hessian or Quasi-Newton Hessian approximation.

6.3.3 PrintSolvers

PurposePrints the available solvers for a certain solvType.

Calling SyntaxPrintSolvers(solvType)

Description of InputssolvType Either a string ’uc’, ’con’ etc. or the corresponding solvType number. See

Table 1.

DescriptionThe routine PrintSolvers prints all available solvers for a given solvType, including Fortran, C and Matlab Opti-mization Toolbox solvers. If solvType is not specified then PrintSolvers lists all available solvers for all differentsolvType. The input argument could either be a string such as ’uc’, ’con’ etc. or a number corresponding to thetype of solver, see Table 1.

ExamplesSee Section 1.3.

M-files UsedSolverList.m

6.3.4 runtest

PurposeRun all selected problems defined in a problem file for a given solver.

Calling Syntaxruntest(Solver, SolverAlg, probFile, probNumbs, PriLevOpt, wait, PriLev)

Description of InputsSolver Name of solver, default conSolve.SolverAlg A vector of numbers defining which of the Solver algorithms to try. For

each element in SolverAlg, all probNumbs are solved. Leave empty, or set 0if to use the default algorithm.

probFile Problem definition file. probFile is by default set to con prob if Solver isconSolve, uc prob if Solver is ucSolve and so on.

probNumbs A vector with problem numbers to run. If empty, run all problems inprobFile.

PriLevOpt Printing level in Solver. Default 2, short information from each iteration.wait Set wait to 1 if pause after each problem. Default 1.PriLev Printing level in PrintResult. Default 5, full information.

M-files UsedSolverList.m

See Alsosystest

129

Page 130: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

6.3.5 systest

PurposeRun big test to check for bugs in TOMLAB.

Calling Syntaxsystest(solvTypes, PriLevOpt, PriLev, wait)

Description of InputssolvTypes A vector of numbers defining which solvType to test.PriLevOpt Printing level in the solver. Default 2, short information from each iteration.wait Set wait to 1 if pause after each problem. Default 1.PriLev Printing level in PrintResult. Default 5, full information.

See Alsoruntest

7 TOMLAB LDO

TOMLAB LDO is a collection of routines in TOMLAB v2.0 for solving linear and discrete optimization (LDO)problems in operations research and mathematical programming. Included are many routines for special problemsin linear programming, network programming, integer programming and dynamic programming.

Note that included in standard TOMLAB are the standard solver lpSolve for linear programming, the solverDualSolve, used to solve linear programming problems when a dual feasible point is known, and two routines formixed-integer programming, mipSolve and cutplane. The aim of the corresponding simpler routines in the LDOcollection are mainly teaching. Use the above routines for production runs.

7.1 Optimization Algorithms and Solvers in TOMLAB LDO

In this section we describe the LDO routines by giving tables describing most Matlab functions with some com-ments. All function files are included in the directory LDO.

There is a simple menu program, simplex, for linear programming. The routine is a utility to interactively solveLP problems in canonical standard form. When the problem is defined, simplex calls the TOMLAB internal LDOsolvers lpsimp1 and lpsimp2.

Like the Math Works, Inc. Optimization Toolbox 1.x, TOMLAB LDO is using a vector with optimization parame-ters. In Optimization Toolbox, the routine setting up the default values in a vector OPTIONS with 18 parametersis called foptions. Our solvers need more parameters, currently 29, and therefore the routine goptions is usedinstead of foptions.

In TOMLAB the routine lpOldDef is used to define the optPar vector and the lpDef the optParam structure.

7.1.1 Linear Programming

There are several algorithms implemented for linear programming, listed in Table 37. The solver (lpSolve2is using the same input and output format as the TOMLAB solvers described in Section 1.2. It is using theoptimization parameter structure optParam instead of the optimization parameter vector optPar.

lpsimp1 and lpsimp2 are simpler versions of the two basic parts in (lpSolve2 that solves Phase I and Phase II LPproblem, respectively. lpdual is an early version of the TOMLAB solver DualSolve.

are described below.

lpSolve calls both the routines Phase1Simplex and Phase2Simplex to solve a general linear program (lp) definedas

minx

f(x) = cTx

s/txL ≤ x ≤ xU ,bL ≤ Ax ≤ bU

(18)

130

Page 131: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

where c, x, xL, xU ∈ Rn, A ∈ R

m1×n, and bL, bU ∈ Rm1 .

Table 37: Solvers for linear programming.

Function Description Section PagelpSolve2 General solver for linear programming problems. Has two internal

routines. Phase1Simplex finds basic feasible solution (bfs) using ar-tificial variables. It calls the other internal routine, Phase2Simplex,which implements the revised simplex algorithm with three selectionrules.

6.1.12 107

lpsimp1 The Phase I simplex algorithm. Finds a basic feasible solution (bfs)using artificial variables. Calls lpsimp2.

7.4.11 147

lpsimp2 The Phase II revised simplex algorithm with three selection rules. 7.4.12 148karmark Karmakar’s algorithm. Kanonical form. 7.4.6 144lpkarma Solves LP on equality form, by converting and calling karmark. 7.4.10 147lpdual The dual simplex algorithm. 7.4.9 146akarmark Affine scaling variant of Karmarkar’s algorithm. 7.4.1 140

The implementation of lpsimp2 is based on the standard revised simplex algorithm as formulated in Goldfarb andTodd [30, page 91] for solving a Phase II LP problem. lpsimp1 implements a Phase I simplex strategy whichformulates a LP problem with artificial variables. This routine is using lpsimp2 to solve the Phase I problem.The dual simplex method [30, pages 105-106], usable when a dual feasible solution is available instead of a primalfeasible, is also implemented (lpdual).

Two polynomial algorithms for linear programming are implemented. Karmakar’s projective algorithm (karmark)is developed from the description in Bazaraa et. al. [7, page 386]. There is a choice of update, either accordingto Bazaraa or the rule by Goldfarb and Todd [30, chap. 9]. The affine scaling variant of Karmakar’s method(akarmark) is an implementation of the algorithm in Bazaraa [30, pages 411-413]. As the purification algorithm amodification of the algorithm on page 385 in Bazaraa is used.

The internal linear programming solvers lpsimp2 and lpdual both have three rules for variable selection implemented.Bland’s cycling prevention rule is the choice if fear of cycling exists. There are two variants of minimum reducedcost variable selection, the original Dantzig’s rule and one which sorts the variables in increasing order in eachstep (the default choice).

7.1.2 Transportation Programming

Transportation problems are solved using an implementation of the transportation simplex method as describedin Luenberger [44, chap 5.4] (TPsimplx). Three simple algorithms to find a starting basic feasible solution for thetransportation problem are included; the northwest corner method (TPnw), the minimum cost method (TPmc)and Vogel’s approximation method (TPvogel). The implementation of these algorithms follows the algorithmdescriptions in Winston [55, chap. 7.2]. The functions are described in Table 38.

Table 38: Routines for transportation programming.

Function Description Section PageTPnw Find initial bfs to TP using the northwest corner method. 7.5.6 156TPmc Find initial bfs to TP using the minimum cost method. 7.5.5 155TPvogel Find initial bfs to TP using Vogel’s approximation method. 7.5.7 156TPsimplx Implementation of the transportation simplex algorithm. 7.4.17 152

131

Page 132: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

7.1.3 Network Programming

The implementation of the network programming algorithms are based on the forward and reverse star repre-sentation technique described in Ahuja et al. [3, pages 35-36]. The following algorithms are currently implemented:

• Search for all reachable nodes in a network using a stack approach (gsearch). The implementation is avariation of the Algorithm SEARCH in [2, pages 231-233].

• Search for all reachable nodes in a network using a queue approach (gsearchq). The implementation is avariation of the Algorithm SEARCH in [2, pages 231-232].

• Find the minimal spanning tree of an undirected graph (mintree) with Kruskal’s algorithm described inAhuja et. al. [3, page 520-521].

• Solve the shortest path problem using Dijkstra’s algorithm (dijkstra). A direct implementation of the Algo-rithm DIJKSTRA in [2, pages 250-251].

• Solve the shortest path problem using a label correcting method (labelcor). The implementation is based onAlgorithm LABEL CORRECTING in [2, page 260].

• Solve the shortest path problem using a modified label correcting method (modlabel). The implementation isbased on Algorithm MODIFIED LABEL CORRECTING in [2, page 262], including the heuristic rule discussedto improve running time in practice.

• Solve the maximum flow problem using the Ford-Fulkerson augmenting path method (maxflow). The imple-mentation is based on the algorithm description in Luenberger [44, pages 144-145].

• Solve the minimum cost network flow problem (MCNFP) using a network simplex algorithm (NWsimplx).The implementation is based on Algorithm network simplex in Ahuja et. al. [3, page 415].

• Solve the symmetric traveling salesman problem using Lagrangian relaxation and the subgradient methodwith the Polyak rule II (salesman), an algorithm by Held and Karp [32].

The network programming routines are listed in Table 39.

Table 39: Routines for network programs.

Function Description Section Pagegsearch Searching all reachable nodes in a network. Stack approach. 7.5.2 154gsearchq Searching all reachable nodes in a network. Queue approach. 7.5.3 154mintree Finds the minimum spanning tree of an undirected graph. 7.5.4 155dijkstra Shortest path using Dijkstra’s algorithm. 7.4.3 142labelcor Shortest path using a label correcting algorithm. 7.4.8 145modlabel Shortest path using a modified label correcting algorithm. 7.4.14 149maxflow Solving maximum flow problems using the Ford-Fulkerson augmenting

path method.7.4.13 149

salesman Symmetric traveling salesman problem (TSP) solver using Lagrangianrelaxation and the subgradient method with the Polyak rule II.

7.4.16 151

NWsimplx Solving minimum cost network flow problems (MCNFP) with a net-work simplex algorithm.

7.4.15 150

7.1.4 Mixed-Integer Programming

To solve mixed linear inequality integer programs two algorithms are implemented as part of TOMLAB, mipSolveand cutplane. Described in the Network Programming section 7.1.3 is the salesman routine, which is an specialtype of integer programming problem. The directory tsplib contains test problems for the travelling salesmanproblem. The routine runtsp runs any of the 25 predefined problems. tsplib reads the actual problem definitionand generates the problem.

Balas method for binary integer programs restricted to integer coefficients is implemented in the routine balas [33].

132

Page 133: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

7.1.5 Dynamic Programming

Two simple examples of dynamic programming are included. Both examples are from Winston [55, chap. 20].Forward recursion is used to solve an inventory problem (dpinvent) and a knapsack problem (dpknap), see Table40.

Table 40: Routines for dynamic programming.

Function Description Section Pagedpinvent Forward recursion DP algorithm for the inventory problem. 7.4.4 142dpknap Forward recursion DP algorithm for the knapsack problem. 7.4.5 143

7.1.6 Lagrangian Relaxation

The usage of Lagrangian relaxation techniques is exemplified by the routine ksrelax, which solves integer linearprograms with linear inequality constraints and upper and lower bounds on the variables. The problem is solvedby relaxing all but one constraint and hence solving simple knapsack problems as subproblems in each iteration.The algorithm is based on the presentation in Fischer [21], using subgradient iterations and a simple line searchrule. Lagrangian relaxation is used by the symmetric travelling salesman solver salesman. Also a routine to drawa plot of the relaxed function is included. The Lagrangian relaxation routines are listed in Table 41.

Table 41: Routines for Lagrangian relaxation.

Function Description Section Pageksrelax Lagrangian relaxation with knapsack subproblems. 7.4.7 145urelax Lagrangian relaxation with knapsack subproblems, plot result. 7.4.18 153

7.1.7 Utility Routines

Table 42 lists the utility routines used in TOMLAB LDO. Some of them are also used by the other routines inTOMLAB.

Table 42: Utility routines.

Function Descriptiona2frstar Convert node-arc A matrix to Forward-Reverse Star Representation.z2frstar Convert matrix of arcs (and costs) to Forward-Reverse Star.cpTransf Transform general convex programs to other forms.lpDef Define optimization parameters in the TOMLAB format (optParam).lpOldDef Define optimization parameters in the Optimization Toolbox 1.x format (optPar).mPrint Print matrix, format: NAME(i, :) a(i, 1)a(i, 2)...a(i, n).printmat Print matrix with row and column labels.vPrint Print vector in rows, format: NAME(i1 : in) vi1vi2 ...vin .xPrint Print vector x, row by row, with format.xPrinti Print integer vector x. Calls xprint.xPrinte Print integer vector x in exponential format. Calls xprint.

133

Page 134: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

7.2 How to Solve Optimization Problems Using TOMLAB LDO

In this section we will describe how to use TOMLAB LDO to solve the different type of problems discussed inSection 7.1

7.2.1 How to Solve Linear Programming Problems

The following example shows how the simple LP problem in (7) can be solved by direct use of the optimizationroutines lpsimp1 and lpsimp2:

A = [ 1 24 1 ];

b = [ 6 12 ]’;c = [-7 -5]’;meq = 0;optPar = lpOldDef;optPar(13) = meq;[x_0, B_0, optPar, y] = lpsimp1(A, b, optPar);[x, B, optPar, y] = lpsimp2(A, b, c, optPar, x_0, B_0);

For further illustrations of how to solve linear programming problems see the example files listed in Table 43 andTable 44.

Table 43: Test examples for linear programming.

Function Descriptionexinled.m First simple LP example from a course in Operations Research.excycle Menu with cycling examples.excycle1 The Marshall-Suurballe cycling example. Run both the Bland’s cycle preventing rule and

the default minimum reduced cost rule and compare results.excycle2 The Kuhn cycling example.excycle3 The Beale cycling example.exKleeM The Klee-Minty example. Shows that the simplex algorithm with Dantzig’s rule visits all

vertices.exfl821 Run exercise 8.21 from Fletcher, Practical methods of Optimization. Illustrates redun-

dancy in constraints.ex412b4s Wayne Winston example 4.12 B4, using lpsimp1 and lpsimp2.expertur Perturbed both right hand side and objective function for Luenberger 3.12-10,11.ex6rev17 Wayne Winston chapter 6 Review 17. Simple example of calling the dual simplex solver

lpdual.ex611a2 Wayne Winston example 6.11 A2. A simple problem solved with the dual simplex solver

lpdual.

Some test examples are collected in the file demoLP and further described in Table 44.

Table 44: Test examples for linear programming running interior point methods.

Function Descriptionexww597 Test of karmark and lpsimp2 on Winston example page 597 and Winston 10.6 Problem

A1.exstrang Test of karmark and lpsimp2 on Strangs’ nutshell example.exkarma Test of akarmark.exKleeM2 Klee-Minty example solved with lpkarma and karmark.

134

Page 135: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

7.2.2 How to Solve Transportation Programming Problems

We will as an example solve the transportation problem

s =

5

2525

, d =

10102015

, C =

6 2 −1 0

4 2 2 33 1 2 1

, (19)

where s is the supply vector, d is the demand vector and C is the cost matrix. See TPsimplx Section 7.4.17.Solving (19) by use of the routine TPsimplx is done by:

s = [ 5 25 25 ]’;d = [10 10 20 15 ]’;C = [ 6 2 -1 0

4 2 2 33 1 2 1 ];

[X, B, optPar, y, C] = TPsimplx(s, d, C)

When neither starting base nor starting point is given as input argument TPsimplx calls TPvogel (using Vogel’sapproximation method) to find an initial basic feasible solution (bfs). If you want to use another method to findan initial bfs, e.g. the northwest corner method, you explicitly call the corresponding routine (TPnw) before thecall to TPsimplx:

s = [ 5 25 25 ]’;d = [10 10 20 15 ]’;C = [ 6 2 -1 0

4 2 2 33 1 2 1 ];

[X_0, B_0] = TPnw(s, d)

[X, B, optPar, y, C] = TPsimplx(s, d, C, X_0, B_0)

For further illustrations of how to solve transportation programming problems see the example files listed in Table45.

Table 45: Test examples for transportation programming.

Function Descriptionextp bfs Test of the three routines that finds initial basic feasible solution to a TP problem, routines

TPnw, TPmc and TPvogel.exlu119 Luenberger TP page 119. Find initial basis with TPnw, TPmc and TPvogel and run

TPsimplx for each.exlu119U Test unbalanced TP on Luenberger TP page 119, slightly modified. Runs TPsimplx.extp Runs simple TP example. Find initial basic feasible solution and solve with TPsimplx.

7.2.3 How to Solve Network Programming Problems

In TOMLAB LDO there are several routines for network programming problems. We will here give an example ofhow to solve a shortest path problem. Given the network in Figure 14, where the numbers at each arc representthe distance of the arc, we want to find the shortest path from node 1 to all other nodes. Representing the networkwith the node-arc incidence matrix A and the cost vector c gives:

135

Page 136: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

A =

1 1 0 0 0 0 0 0−1 0 1 −1 0 0 0 00 −1 0 1 1 0 −1 00 0 −1 0 0 1 1 −10 0 0 0 −1 −1 0 1

, c =

23142413

(20)

Representing the network with the forward and reverse star technique gives:

P =

134689

, Z =

1 21 32 43 23 54 54 35 4

, c =

23142413

, T =

14273856

, R =

113579

(21)

See a2frstar Section 7.5.1 for an explanation of the notation.

1

2

3

4

5

2

3

✲1

4

✲2

4

1

3

Figure 14: A network example.

Our choice of solver for this example is modlabel, see Section 7.4.14, which uses a modified label correctingalgorithm. First we define the incidence matrix A and the cost vector c and call the routine a2frstar to convert toa forward and reverse star representation (which is used by modlabel). Then the actual problem is solved.

A = [ 1 1 0 0 0 0 0 0

136

Page 137: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

-1 0 1 -1 0 0 0 00 -1 0 1 1 0 -1 00 0 -1 0 0 1 1 -10 0 0 0 -1 -1 0 1 ];

C = [ 2 3 1 4 2 4 1 3 ];

[P Z c T R x_U] = a2frstar(A, C);

[pred dist] = modlabel(1,P,Z,c);

For further illustrations of how to solve network programming problems see the example files listed in Table 46.

Table 46: Test examples for network programming.

Function Descriptionexgraph Testing network routines on simple example.exflow Testing several maximum flow examples.pathflow Pathological test example for maximum flow problems.exflow31 Test example N31.exmcnfp Minimum Cost Network Flow Problem (MCNFP) example from Ahuja et. al.

7.2.4 How to Solve Integer Programming Problems

The routines in TOMLAB LDO for solving integer programming problems are cutplane, mipSolve and balas. Toillustrate how to solve an integer programming problem we will solve the problem (7) with the addition of therequirement of the variables to be positive integers. We have chosen to use the routine cutplane, see Section 6.1.3.

A = [ 1 24 1 ];

b = [ 6 12 ]’;c = [-7 -5]’;meq = 0;optPar = lpOldDef;optPar(13) = meq;n_I = 2;

[x, B, optPar, y] = cutplane(A, b, c, optPar, [], [], n_I);

For further illustrations of how to solve integer programming problems see the example files listed in Table 47.

Table 47: Test examples for integer programming.

Function Descriptionexpkorv Test of cutplane and mipSolve for example PKorv.exIP39 Test example I39.exbalas Test of 0/1 IP (Balas algorithm) on simple example.

7.2.5 How to Solve Dynamic Programming Problems

We will in this subsection illustrate the simple approach to solve both a knapsack problem and an inventoryproblem with help of the routines dpknap (see Section 7.4.5) and dpinvent (Section 7.4.4). The knapsack problem(22) is an example from Kaj H. [33] and the inventory problem is an example from Winston [55, page 1013].

137

Page 138: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

maxu

f(u) = 7u1 + u2 + 4u3

s/t 2u1 + 3u2 + 2u3 ≤ 40 ≤ u1 ≤ 10 ≤ u2 ≤ 10 ≤ u3 ≤ 2uj ∈ N, j = 1, 2, 3

(22)

Problem (22) will be solved by the following definitions and call:

A = [ 2 3 2 ];b = 4;c = [ 7 2 4 ];u_UPP = [ 1 1 2 ];PriLev = 0;

[u, f_opt] = dpknap(A, b, c, u_UPP, PriLev);

Description of the inventory problem:A company knows that the demand for its product during each of the next for months will be as follows: month 1,1 unit; month 2, 3 units; month 3, 2 units; month 4, 4 units. At the beginning of each month, the company mustdetermine how many units should be produced during the current month. During a month in which any units areproduced, a setup cost of $3 is incurred. In addition, there is a variable cost of $1 for every unit produced. At theend of each month, a holding cost of 50 cents per unit on hand is incurred. Capacity limitations allow a maximumof 5 units to be produced during each month. The size of the company’s warehouse restricts the ending inventoryfor each month to at most 4 units. The company wants to determine a production schedule that will meet alldemands on time and will minimize the sum of production and holding costs during the four months. Assumethat 0 units are on hand at the beginning of the first month.

The inventory problem described above will be solved by the following definitions and call:

d = [1 3 2 4]’; % Demand. N = 4;P_s = 3; % Setup cost $3 if u > 0P = ones(5,1); % Production cost $1/unit in each time stepI_s = 0; % Zero setup cost for the InventoryI = 0.5*ones(5,1); % Inventory cost $0.5/unit in each time stepx_L = 0; % lower bound on inventory, xx_U = 4; % upper bound on inventory, xx_LAST = []; % Find best choice of inventory at endx_S = 0; % Empty inventory at startu_L = [0 0 0 0]; % Minimal amount produced in each time stepu_U = [5 5 5 5]; % Maximal amount produced in each time stepPriLev = 1;

[u, f_opt] = dpinvent(d, P_s, P, I_s, I, u_L, u_U, x_L, x_U, x_S, x_LAST, PriLev);

For further illustrations of how to solve dynamic programming problems see the example files listed in Table 48.

Table 48: Test examples for dynamic programming.

Function Descriptionexinvent Test of dpinvent on two inventory examples.exknap Test of dpknap (calls mipSolve and cutplane) on five knapsack examples.

138

Page 139: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

7.2.6 How to Solve Lagrangian Relaxation Problems

We end up this section with an example of how to solve an integer programming problem with the routine ksrelax,which uses a Lagrangian Relaxation technique. The problem to be solved, (23), is an example from Fischer [21].

maxx

f(x) = 16x1 + 10x2 + 4x4

s/t 8x1 + 2x2 + x3 + x4 ≤ 10x1 + x2 ≤ 1x3 + x4 ≤ 1xj ∈ 0/1, j = 1, 2, 3, 4

(23)

A = [ 8 2 1 41 1 0 00 0 1 1 ];

b = [10 1 1 ]’;c = [16 10 0 4 ]’;r = 1; % Do not relax the first constraintx_UPP = [1 1 1 1]’;

[x u f_opt optPar] = ksrelax(A, b, c, r, x_UPP);

For further illustrations of how to solve Lagrangian Relaxation problems see the example files listed in Table 49.

Table 49: Test examples for Lagrangian Relaxation.

Function Descriptionexrelax Test of ksrelax on LP example from Fischer -85.exrelax2 Simple example, runs ksrelax.exIP39rx Test example I39, relaxed. Calls urelax and plot.

139

Page 140: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

7.3 Printing Utilities and Print Levels

This section is written for the part of TOMLAB LDO which is not using the same input/output format and is notdesigned in the same way as the other routines in TOMLAB. Information about printing utilities and print levelsfor the other routines could be found in Section 5.3

The amount of printing is determined by setting a print level for each routine. This parameter most often has thename PriLev.

Normally the zero level (PriLev = 0) corresponds to silent mode with no output. The level one corresponds toa result summary and error messages. Level two gives output every iteration and level three displays vectors andmatrices. Higher levels give even more printing of debug type. See the help in the actual routine.

The main driver or menu routine called may have a PriLev parameter among its input parameters. The routinescalled from the main routine normally sets the PriLev parameter to optPar(1). The vector optPar is set to defaultvalues by a call to goptions. The user may then change any values before calling the main routine. The elementsin optPar is described giving the command: help goptions. For linear programming there is a special initializationroutine, lpOldDef, which calls goptions and changes some relevant parameters.

There is a wait flag in optPar, optPar(24). If this flag is set, the routines uses the pause statement to avoid theoutput just flushing by.

The TOMLAB LDO routines print large amounts of output if high values for the PriLev parameter is set. Tomake the output look better and save space, several printing utilities have been developed, see Table 42.

For matrices there are two routines, mPrint and printmat. The routine printmat prints a matrix with row andcolumn labels. The default is to print the row and column number. The standard row label is eight characterslong. The supplied matrix name is printed on the first row, the column label row, if the length of the name is atmost eight characters. Otherwise the name is printed on a separate row.

The standard column label is seven characters long, which is the minimum space an element will occupy in theprint out. On a 80 column screen, then it is possible to print a maximum of ten elements per row. Independenton the number of rows in the matrix, printmat will first display A(:, 1 : 10), then A(:, 11 : 20) and so on.

The routine printmat tries to be intelligent and avoid decimals when the matrix elements are integers. It determinesthe maximal positive and minimal negative number to find out if more than the default space is needed. If anyelement has an absolute value below 10−5 (avoiding exact zeros) or if the maximal elements are too big, a switchis made to exponential format. The exponential format uses ten characters, displaying two decimals and thereforeseven matrix elements are possible to display on each row.

For large matrices, especially integer matrices, the user might prefer the routine mPrint. With this routine a moredense output is possible. All elements in a matrix row is displayed (over several output rows) before next matrixrow is printed. A row label with the name of the matrix and the row number is displayed to the left using theMatlab style of syntax.

The default in mPrint is to eight characters per element, with two decimals. However, it is easy to change theformat and the number of elements displayed. For a binary matrix it is possible to display 36 matrix columns inone 80 column row.

7.4 Optimization Routines in TOMLAB LDO

In the following subsections the optimization routines in TOMLAB LDOwill be described.

7.4.1 akarmark

PurposeSolve linear programming problems of the form

minx

f(x) = cTx

s/t Ax = bx ≥ 0

where x, c ∈ Rn, A ∈ R

m×n and b ∈ Rm.

140

Page 141: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Calling Syntax[x, optPar, y, x 0] = akarmark(A, b, c, optPar, x 0)

Description of InputsA Constraint matrix.b Right hand side vector.c Cost vector.optPar Optimization parameter vector, see goptions.m.x 0 Starting point.

Description of Outputsx Optimal point.optPar Optimization parameter vector, see goptions.m.y Dual parameters.x 0 Starting point used.

DescriptionThe routine akarmark is an implementation of the affine scaling variant of Karmarkar’s method as described inBazaraa [30, pages 411-413]. As the purification algorithm a modified version of the algorithm on page 385 inBazaraa is used.

AlgorithmSee Appendix B.1.

ExamplesSee exakarma, exkarma, exkleem2.

M-files UsedlpDef.m

See Alsolpkarma, karmark

7.4.2 balas

PurposeSolve binary integer linear programming problems.

balas solves problems of the form

minx

f(x) = cTx

s/t aTi x = bi i = 1, 2, ...,meq

aTi x ≤ bi i = meq + 1, ...,mxj ∈ 0/1 j = 1, 2, ..., n

where c ∈ Zn, A ∈ Z

m×n and b ∈ Zm.

Calling Syntax[x, optPar] = balas(A, b, c, optPar)

Description of InputsA Constraint matrix.b Right hand side vector.c Cost vector.optPar Optimization parameter vector, see goptions.m.

Description of Outputsx Optimal point.optPar Optimization parameter vector, see goptions.m.

DescriptionThe routine balas is an implementation of Balas method for binary integer programs restricted to integer coeffi-cients.

AlgorithmSee the code in balas.m.

141

Page 142: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

ExamplesSee exbalas.

M-files UsedlpDef.m

See AlsomipSolve, cutplane

7.4.3 dijkstra

PurposeSolve the shortest path problem.

Calling Syntax[pred, dist] = dijkstra(s, P, Z, c)

Description of Inputss The starting node.p Pointer vector to start of each node in the matrix Z.Z Arcs outgoing from the nodes in increasing order.

Z(:, 1) Tail. Z(:, 2) Head.c Costs related to the arcs in the matrix Z.

Description of Outputspred pred(j) is the predecessor of node j.dist dist(j) is the shortest distance from node s to node j.

Descriptiondijkstra is a direct implementation of the algorithm DIJKSTRA in [2, pages 250-251] for solving shortest pathproblems using Dijkstra’s algorithm. Dikstra’s algorithm belongs to the class of label setting methods which areapplicable only to networks with nonnegative arc lengths. For solving shortest path problems with arbitrary arclengths use the routine labelcor or modlabel which belongs to the class of label correcting methods.

AlgorithmSee Appendix B.2.

ExamplesSee exgraph, exflow31.

See Alsolabelcor, modlabel

Limitationsdijkstra can only solve problems with nonnegative arc lengths.

7.4.4 dpinvent

PurposeSolve production/inventory problems of the form

minu

f(u) = Ps(t) + P (t)Tu(t) + I(t)Tx(t)

s/t uL ≤ u(t) ≤ uUxL ≤ x(t) ≤ xU0 ≤ u(t) ≤ x(t) + d(t)

uj ∈ N j = 1, 2, ..., nxj ∈ N j = 1, 2, ..., n

where x(t) = x(t− 1) + u(t)− d(t) and d ∈ Nn.

Calling Syntax[u, f opt, exit] = dpinvent(d, P s, P, I s, I, u L, u U, x L, x U, x S, x LAST, PriLev)

142

Page 143: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Description of Inputsd Demand vector.P s Production setup cost.P Production cost vector.I s Inventory setup cost.I Inventory cost vector.u L Minimal amount produced in each time step.u U Maximal amount produced in each time step.x L Lower bound on inventory.x U Upper bound on inventory.x S Inventory state at start.x LAST Inventory state at finish.PriLev Printing level:

PriLev = 0, no output.PriLev = 1, output of convergence results.PriLev > 1, output of each iteration.

Description of Outputsu Optimal control.f opt Optimal function value.exit Exit flag.

Descriptiondpinvent solves production/inventory problems using a forward recursion dynamic programming technique asdescribed in Winston [55, chap. 20].

AlgorithmSee Appendix B.3.

ExamplesSee exinvent.

7.4.5 dpknap

PurposeSolve knapsack problems of the form

maxu

f(u) = cTu

s/t Au ≤ bu ≤ uU

uj ∈ N j = 1, 2, ..., n

where A ∈ Nn, c ∈ R

n and b ∈ N

Calling Syntax[u, f opt, exit] = dpknap(A, b, c, u U, PriLev)

Description of InputsA Weigth vector.b Knapsack capacity.c Benefit vector.u U Upper bounds on u.PriLev Printing level:

PriLev = 0, no output.PriLev = 1, output of convergence results.PriLev > 1, output of each iteration.

Description of Outputsu Optimal control.f opt Optimal function value.exit Exit flag.

143

Page 144: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Descriptiondpknap solves knapsack problems using a forward recursion dynamic programming technique as described in [55,chap. 20]. The Lagrangian relaxation routines ksrelax and urelax call dpknap to solve the knapsack subproblems.

AlgorithmSee Appendix B.4.

ExamplesSee exknap.

7.4.6 karmark

PurposeSolve linear programming problems of Karmakar’s form

minx

f(x) = cTx

s/t Ax = 0n∑

j=1

xj = 1

x ≥ 0

where x, c ∈ Rn, A ∈ R

m×n and the following assumptions hold:

• The point x(0) =(

1n , ...,

1n

)T is feasible.

• The optimal objective value is zero.

Calling Syntax[x, optPar] = karmark(A, c, optPar)

Description of InputsA Constraint matrix.c Cost vector.optPar Optimization parameter vector, see goptions.m.

Description of Outputsx Optimal point.optPar Optimization parameter vector, see goptions.m.

DescriptionThe routine karmark is an implementation of Karmakar’s projective algorithm which is of polynomial complexity.The implementation uses the description in Bazaraa [7, page 386]. There is a choice of update, either accordingto Bazaraa or the rule by Goldfarb and Todd [30, chap. 9]. As the purification algorithm a modified version ofthe algorithm on page 385 in Bazaraa is used. karmark is called by lpkarma which transforms linear maximizationproblems on inequality form into Karmakar’s form needed for karmark.

AlgorithmSee Appendix B.7.

ExamplesSee exstrang, exww597.

M-files UsedlpDef.m

See Alsolpkarma, akarmark

144

Page 145: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

7.4.7 ksrelax

PurposeSolve integer linear problems of the form

maxx

f(x) = cTx

s/t Ax ≤ bx ≤ xU

xj ∈ N j = 1, 2, ..., n

where c ∈ Rn, A ∈ N

m×n and b ∈ Nm.

Calling Syntax[x P, u, f P, optPar] = ksrelax(A, b, c, r, x U, optPar)

Description of InputsA Constraint matrix.b Right hand side vector.c Cost vector.r Constraint not to be relaxed.x U Upper bounds on the variables.optPar Optimization parameter vector, see goptions.m.

Description of Outputsx P Primal solution.u Lagrangian multipliers.f P Function value at x P .optPar Optimization parameter vector, see goptions.m.

DescriptionThe routine ksrelax uses Lagrangian Relaxation to solve integer linear programming problems with linear inequalityconstraints and simple bounds on the variables. The problem is solved by relaxing all but one constraint and thensolve a simple knapsack problem as a subproblem in each iteration. The algorithm is based on the presentation inFisher [21], using subgradient iterations and a simple line search rule. LDO also contains a routine urelax whichplots the result of each iteration.

AlgorithmSee Appendix B.8.

ExamplesSee exrelax, exrelax2.

M-files UsedlpDef.m, dpknap.m

See Alsourelax

7.4.8 labelcor

PurposeSolve the shortest path problem.

Calling Syntax[pred, dist] = labelcor(s, P, Z, c)

Description of Inputss The starting node.p Pointer vector to start of each node in the matrix Z.Z Arcs outgoing from the nodes in increasing order.

Z(:, 1) Tail. Z(:, 2) Head.c Costs related to the arcs in the matrix Z.

145

Page 146: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Description of Outputspred pred(j) is the predecessor of node j.dist dist(j) is the shortest distance from node s to node j.

DescriptionThe implementation of labelcor is based on the algorithm LABEL CORRECTING in [2, page 260] for solving shortestpath problems. The algorithm belongs to the class of label correcting methods which are applicable to networkswith arbitrary arc lengths. labelcor requires that the network does not contain any negative directed cycle, i.e. adirected cycle whose arc lengths sum to a negative value.

AlgorithmSee Appendix B.9.

ExamplesSee exgraph.

See Alsodijkstra, modlabel

LimitationsThe network must not contain any negative directed cycle.

7.4.9 lpdual

PurposeSolve linear programming problems when a dual feasible solution is available.

lpdual solves problems of the form

minx

fP (x) = cTx

s/t aTi x = bi i = 1, 2, ...,meq

aTi x ≤ bi i = meq + 1, ...,mx ≥ 0

by rewriting it into standard form and solving the dual problem

maxy

fD(y) = bT y

s/t AT y ≤ cy urs

with x, c ∈ Rn, A ∈ R

m×n and b, y ∈ Rm.

Calling Syntax[x, y, B, optPar] = lpdual(A, b, c, optPar, B 0, x 0, y 0)

Description of InputsA Constraint matrix.b Right hand side vector.c Cost vector.optPar Optimization parameter vector, see goptions.m.B 0 Logical vector of length n for basic variables at start.x 0 Starting point, must be dual feasible.y 0 Dual parameters (Lagrangian multipliers) at x 0.

Description of Outputsx Optimal point.y Dual parameters (Lagrangian multipliers) at the solution.B Optimal basic set.optPar Optimization parameter vector, see goptions.m.

DescriptionWhen a dual feasible solution is available, the dual simplex method is possible to use. lpdual implements thismethod using the algorithm in [30, pages 105-106]. There are three rules available for variable selection. Bland’s

146

Page 147: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

cycling prevention rule is the choice if fear of cycling exist. The other two are variants of minimum reduced costvariable selection, the original Dantzig’s rule and one which sorts the variables in increasing order in each step(the default choice).

AlgorithmSee B.10.

ExamplesSee ex611a2, ex6rev17.

M-files UsedlpDef.m

See Alsolpsimp1, lpsimp2

7.4.10 lpkarma

PurposeSolve linear programming problems of the form

maxx

f(x) = cTx

s/t Ax ≤ bx ≥ 0

where x, c ∈ Rn, A ∈ R

m×n and b ∈ Rm.

Calling Syntax[x, y, optPar] = lpkarma(A, b, c, optPar)

Description of InputsA Constraint matrix.b Right hand side vector.c Cost vector.optPar Optimization parameter vector, see goptions.m.

Description of Outputsx Optimal point.y Dual solution.optPar Optimization parameter vector, see goptions.m.

Descriptionlpkarma converts a linear maximization problem on inequality form into Karmakar’s form and calls karmark tosolve the transformed problem.

AlgorithmSee Appendix B.11.

ExamplesSee exstrang, exww597.

M-files UsedlpDef.m, karmark.m

See Alsokarmark, akarmark

7.4.11 lpsimp1

PurposeFind a basic feasible solution to linear programming problems.

147

Page 148: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

lpsimp1 finds a basic feasible solution to problems of the form

minx

f(x) = cTx

s/t aTi x = bi i = 1, 2, ...,meq

aTi x ≤ bi i = meq + 1, ...,mx ≥ 0

where x, c ∈ Rn, A ∈ R

m×n and b ∈ Rm, b ≥ 0.

Calling Syntax[x, B, optPar, y] = lpsimp1( A, b, optPar)

Description of InputsA Constraint matrix.b Right hand side vector.optPar Optimization parameter vector, see goptions.m.

Description of Outputsx Basic feasible solution.B Basic set at the solution x.optPar Optimization parameter vector, see goptions.m.y Lagrange multipliers.

DescriptionThe routine lpsimp1 implements a Phase I Simplex strategy which formulates a LP problem with artificial variables.Slack variables are added to the inequality constraints and artificial variables are added to the equality constraints.The routine uses lpsimp2 to solve the Phase I problem.

AlgorithmSee Appendix B.12.

ExamplesSee exinled, excycle, excycle2, exKleeM, exfl821, ex412b4s.

M-files UsedlpDef.m, lpsimp2.m

See Alsolpsimp2

7.4.12 lpsimp2

PurposeSolve linear programming problems.

lpsimp2 solves problems of the form

minx

f(x) = cTx

s/t aTi x = bi i = 1, 2, ...,meq

aTi x ≤ bi i = meq + 1, ...,mx ≥ 0

where x, c ∈ Rn, A ∈ R

m×n and b ∈ Rm.

Calling Syntax[x, B, optPar, y] = lpsimp2(A, b, c, optPar, x 0, B 0)

Description of InputsA Constraint matrix.b Right hand side vector.c Cost vector.optPar Optimization parameter vector, see goptions.m.x 0 Starting point, must be a basic feasible solution.B 0 Logical vector of length n for basic variables at start.

148

Page 149: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Description of Outputsx Optimal point.B Optimal basic set.optPar Optimization parameter vector, see goptions.m.y Lagrange multipliers.

DescriptionThe routine lpsimp2 implements the Phase II standard revised Simplex algorithm as formulated in Goldfarb andTodd [30, page 91]. There are three rules available for variable selection. Bland’s cycling prevention rule is thechoice if fear of cycling exist. The other two are variants of minimum reduced cost variable selection, the originalDantzig’s rule and one which sorts the variables in increasing order in each step (the default choice).

AlgorithmSee Appendix B.13.

ExamplesSee exinled, excycle, excycle1, excycle2, excycle3, exKleeM, exfl821, ex412b4s, expertur.

M-files UsedlpDef.m

See Alsolpsimp1, lpdual

WarningsNo check is done whether the given starting point is feasible or not.

7.4.13 maxflow

PurposeSolve the maximum flow problem.

Calling Syntax[max flow, x] = maxflow(s, t, x U, P, Z, T, R, PriLev)

Description of Inputss The starting node, the source.t The end node, the sink.P Pointer vector to start of each node in the matrix Z.x U The capacity on each arc.Z Arcs outgoing from the nodes in increasing order.

Z(:, 1) Tail. Z(:, 2) Head.T Trace vector, points to Z with sorting order Head.R Pointer vector in T vector for each node.PriLev Printing Level: 0 Silent, 1 Print result (default).

Description of Outputsmax flow Maximal flow between node s and node t.x The flow on each arc.

Descriptionmaxflow finds the maximum flow between two nodes in a capacitated network using the Ford-Fulkerson augmentedpath method. The implementation is based on the algorithm description in Luenberger [44, page 144-145].

AlgorithmSee Appendix B.14.

ExamplesSee exflow, exflow31, pathflow.

7.4.14 modlabel

PurposeSolve the shortest path problem.

149

Page 150: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Calling Syntax[pred, dist] = modlabel(s, P, Z, c)

Description of Inputss The starting node.p Pointer vector to start of each node in the matrix Z.Z Arcs outgoing from the nodes in increasing order.

Z(:, 1) Tail. Z(:, 2) Head.c Costs related to the arcs in the matrix Z.

Description of Outputspred pred(j) is the predecessor of node j.dist dist(j) is the shortest distance from node s to node j.

DescriptionThe implementation of modlabel is based on the algorithm MODIFIED LABEL CORRECTING in [2, page 262] withthe addition of the heuristic rule discussed to improve running time in practice. The rule says: Add node to thebeginning of LIST if node has been in LIST before, otherwise add node at the end of LIST . The algorithmbelongs to the class of label correcting methods which are applicable to networks with arbitrary arc lengths.modlabel requires that the network does not contain any negative directed cycle, i.e. a directed cycle whose arclengths sum to a negative value.

AlgorithmSee Appendix B.15.

ExamplesSee exgraph.

See Alsodijkstra, labelcor

LimitationsThe network must not contain any negative directed cycle.

7.4.15 NWsimplx

PurposeSolve the minimum cost network flow problem.

Calling Syntax[Z, X, xmax, C, S, my, optPar] = NWsimplx(A, b, c, u, optPar)

Description of InputsA Node-arc incidence matrix. A is m× n.b Supply/demand vector of length m.c Cost vector of length n.u Arc capacity vector of length n.optPar Optimization parameter vector, see goptions.m.

Description of OutputsZ Arcs outgoing from the nodes in increasing order.

Z(:, 1) Tail. Z(:, 2) Head.X Optimal flow.xmax Upper bound on the flow.C Costs related to the arcs in the matrix Z.S Arc status at the solution:

Si = 1, arc i is in the optimal spanning tree.Si = 2, arc i is in L (variable at lower bound).Si = 3, arc i is in U (variable at upper bound).

my Lagrangian multipliers at the solution.optPar Optimization parameter vector, see goptions.m.

DescriptionThe implementation of the network simplex algorithm in NWsimplx is based on the algorithm NETWORK SIMPLEX

150

Page 151: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

in Ahuja et al. [3, page 415]. NWsimplx uses the forward and reverse star representation technique of the network,described in [3, pages 35-36].

AlgorithmSee [3, page 415] and the code in NWsimplx.m.

ExamplesSee exmcnfp.

M-files UsedlpDef.m, a2frstar.m

7.4.16 salesman

PurposeSolve the symmetric travelling salesman problem.

Calling Syntax[Tour, f tour, OneTree, f tree, w max, my max, optPar] =salesman(C, Zin, Zout, my, f BestTour, optPar)

Description of InputsC Cost matrix of dimension n× n where Cij = Cji is the cost of arc (i, j). If

there are no arc between node i and node j then set Cij = Cji = ∞. Itmust hold that Cii = NaN .

Zin List of arcs forced in.Zout List of arcs forced out.my Lagrange multipliers.f BestTour Cost (total distance) of a known tour.optPar Optimization parameter vector, see goptions.m.

Description of OutputsTour Arc list of the best tour found.f tour Cost (total distance) of the best tour found.OneTree Arc list of the best 1-tree found.f tree Cost of the best 1-tree found.w max Best dual objective.my max Lagrange multipliers at w max.optPar Optimization parameter vector, see goptions.m.

DescriptionThe routine salesman is an implementation of an algorithm by Held and Karp [32] which solves the symmetrictravelling salesman problem using Lagrangian Relaxation. The dual problem is solved using a subgradient methodwith the step length given by the Polyak rule II. The primal problem is to find a 1-tree. Here the routine mintreeis called to get a minimum spanning tree. With this method there is no guarantee that an optimal tour is found,i.e. a zero duality gap can not be guaranteed. To ensure convergence, salesman could be used as a subroutine ina Branch and Bound algorithm, see travelng which calls salesman.

AlgorithmSee [32] and the code in salesman.m.

ExamplesSee ulyss16.

M-files UsedlpDef.m, mintree.m

See Alsotravelng

151

Page 152: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

7.4.17 TPsimplx

PurposeSolve transportation programming problems.

TPsimplx solves problems of the form

minx

f(x) =m∑i

n∑j

cijxij

s/tn∑j

xij = si i = 1, 2, ...,mn∑i

xij = dj j = 1, 2, ..., n

x ≥ 0

where x, c ∈ Rm×n, s ∈ R

m and d ∈ Rn.

Calling Syntax[X, B, optPar, y, C] = TPsimplx(s, d, C, X, B, optPar, Penalty)

Description of Inputss Supply vector.d Demand vector.C The cost matrix of linear objective function coefficients.X Basic Feasible Solution matrix.B Index (i, j) of basis found.optPar Optimization parameter vector, see goptions.m.

Penalty If the problem is unbalanced withm∑i

si <n∑j

dj , a dummy supply point

is added with cost vector Penalty. If the length of Penalty < n then thevalue of the first element in Penalty is used for the whole added cost vector.Default: Computed as 10max(Cij).

Description of OutputsX Solution matrix.B Optimal set. Index (i, j) of the optimal basis found.optPar Optimization parameter vector, see goptions.m.y Lagrange multipliers.C The cost matrix, changed if the problem is unbalanced.

DescriptionThe routine TPsimplx is an implementation of the Transportation Simplex method described in Luenberger [44,chap 5.4]. In LDO, three routines to find a starting basic feasible solution for the transportation problem areincluded; the Northwest Corner method (TPnw), the Minimum Cost method (TPmc) and Vogel’s approximationmethod (TPvogel). If calling TPsimplx without giving a starting point then Vogel’s method is used to find astarting basic feasible solution.

AlgorithmSee Appendix B.19.

ExamplesSee extp bfs, exlu119, exlu119U, extp.

M-files UsedTPvogel.m

See AlsoTPmc, TPnw, TPvogel

WarningsNo check is done whether the given starting point is feasible or not.

152

Page 153: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

7.4.18 urelax

PurposeSolve integer linear problems of the form

maxx

f(x) = cTx

s/t Ax ≤ bx ≤ xU

xj ∈ N j = 1, 2, ..., n

where c ∈ Rn, A ∈ N

m×n and b ∈ Nm.

Calling Syntax[x P, u, f P] = urelax(u max, A, b, c, r, x U, optPar)

Description of Inputsu max Upper bounds on u.A Constraint matrix.b Right hand side vector.c Cost vector.r Constraint not to be relaxed.x U Upper bounds on the variables.optPar Optimization parameter vector, see goptions.m.

Description of Outputsx P Primal solution.u Lagrangian multipliers.f P Function value at x P .

DescriptionThe routine urelax is a simple example of the use of Lagrangian Relaxation to solve integer linear programmingproblems. The problem is solved by relaxing all but one constraint and then solve a simple knapsack problem asa subproblem in each iteration. urelax plots the result of each iteration. LDO also contains a more sophisticatedroutine, ksrelax, for solving problems of this type.

AlgorithmSee Appendix B.21.

ExamplesSee exip39rx.

M-files Useddpknap.m

See Alsoksrelax

7.5 Optimization Subfunction Utilities in TOMLAB LDO

In the following subsections the optimization subfunction utilities in TOMLAB LDO will be described.

7.5.1 a2frstar

PurposeConvert a node-arc incidence matrix representation of a network to the forward and reverse star data storagerepresentation.

Calling Syntax[P, Z, c, T, R, u] = a2frstar(A, C, U)

153

Page 154: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Description of InputsA The node-arc incidence matrix. A is m× n, where m is the number of arcs

and n is the number of nodes.C Cost for each arc, n-vector.U Upper bounds on flow (optional).

Description of OutputsP Pointer vector to start of each node in the matrix Z.Z Arcs outgoing from the nodes in increasing order.

Z(:, 1) Tail. Z(:, 2) Head.c Costs related to the arcs in the matrix Z.T Trace vector, points to Z with sorting order Head.R Rewerse pointer vector in T for each node.u Upper bounds on flow if U is given as input, else infinity.

DescriptionThe routine a2frstar converts a node-arc incidence matrix representation of a network to the forward and reversestar data storage representation as described in Ahuja et.al. [3, pages 35-36].

ExamplesSee exflow, exflow31, exgraph, pathflow.

7.5.2 gsearch

PurposeFind all nodes in a network which is reachable from a given source node.

Calling Syntax[pred, mark] = gsearch(s, P, Z, c)

Description of Inputss The starting node.P Pointer vector to start of each node in the matrix Z.Z Arcs outgoing from the nodes in increasing order.

Z(:, 1) Tail. Z(:, 2) Head.c Costs related to the arcs in the matrix Z.

Description of Outputspred pred(j) = Predecessor of node j.mark If mark(j) = 1 the node is reachable from node s.

Descriptiongsearch is searching for all nodes in a network which is reachable from the given source node s. The implementationis a variation of the Algorithm SEARCH in [2, pages 231-233]. The algorithm uses a depth-first search which meansthat it creates a path as long as possible and backs up one node to initiate a new probe when it can mark no newnodes from the tip of the path. A stack approach is used where nodes are selected from the front and added tothe front.

AlgorithmSee Appendix B.5.

ExamplesSee exgraph.

See Alsogsearchq

7.5.3 gsearchq

PurposeFind all nodes in a network which is reachable from a given source node.

154

Page 155: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Calling Syntax[pred, mark] = gsearchq(s, P, Z, c)

Description of Inputss The starting node.P Pointer vector to start of each node in the matrix Z.Z Arcs outgoing from the nodes in increasing order.

Z(:, 1) Tail. Z(:, 2) Head.c Costs related to the arcs in the matrix Z.

Description of Outputspred pred(j) = Predecessor of node j.mark If mark(j) = 1 the node is reachable from node s.

Descriptiongsearchq is searching for all nodes in a network which is reachable from the given source node s. The implementationis a variation of the Algorithm SEARCH in [2, pages 231-233]. The algorithm uses a breadth-first search whichmeans that it visits the nodes in order of increasing distance from s. The distance being the minimum number ofarcs in a directed path from s. A queue approach is used where nodes are selected from the front and added tothe rear.

AlgorithmSee Appendix B.6.

ExamplesSee exgraph.

See Alsogsearch

7.5.4 mintree

PurposeFind the minimum spanning tree of an undirected graph.

Calling Syntax[Z tree, cost] = mintree(C, Zin, Zout)

Description of InputsC Cost matrix of dimension n× n where Cij = Cji is the cost of arc (i, j). If

there are no arc between node i and node j then set Cij = Cji = ∞. Itmust hold that Cii = NaN .

Zin List of arcs which should be forced to be included in Z tree.Zout List of arcs which should not be allowed to be included in Z tree (could

also be given as NaN in C).

Description of OutputsZ tree List of arcs in the minimum spanning tree.cost The total cost.

Descriptionmintree is an implementation of Kruskal’s algorithm for finding a minimal spanning tree of an undirected graph.The implementation follows the algorithm description in [3, page 520-521]. It is possible to give as input, a listof those arcs which should be forced to be included in the tree as well as a list of those arcs which should not beallowed to be included in the tree. mintree is called by salesman.

AlgorithmSee Appendix B.16.

7.5.5 TPmc

PurposeFind a basic feasible solution to the Transportation Problem.

155

Page 156: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Calling Syntax[X,B] = TPmc(s, d, C)

Description of Inputss Supply vector of length m.d Demand vector of length n.C The cost matrix of linear objective function coefficients.

Description of OutputsX Basic feasible solution matrix.B Index (i, j) of the basis found.

DescriptionTPmc is an implementation of the Minimum Cost method for finding a basic feasible solution to the transportationproblem. The implementation of this algorithm follows the algorithm description in Winston [55, chap. 7.2].

AlgorithmSee Appendix B.17.

ExamplesSee extp bfs, exlu119, exlu119U, extp.

See AlsoTPnw, TPvogel, TPsimplx

7.5.6 TPnw

PurposeFind a basic feasible solution to the Transportation Problem.

Calling Syntax[X, B] = TPnw(s, d)

Description of Inputss Supply vector of length m.d Demand vector of length n.

Description of OutputsX Basic feasible solution matrix.B Index (i, j) of the basis found.

DescriptionTPnw is an implementation of the Northwest Corner method for finding a basic feasible solution to the trans-portation problem. The implementation of this algorithm follows the algorithm description in Winston [55, chap.7.2].

AlgorithmSee Appendix B.18.

ExamplesSee extp bfs, exlu119, exlu119U, extp.

See AlsoTPmc, TPvogel, TPsimplx

7.5.7 TPvogel

PurposeFind a basic feasible solution to the Transportation Problem.

Calling Syntax[X, B] = TPvogel(s, d, C, PriLev)

156

Page 157: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Description of Inputss Supply vector of length m.d Demand vector of length n.C The cost matrix of linear objective function coefficients.PriLev If PriLev > 0, the matrix X is displayed in each iteration.

If PriLev > 1, pause in each iteration.Default: PriLev = 0.

Description of OutputsX Basic feasible solution matrix.B Index (i, j) of the basis found.

DescriptionTPvogel is an implementation of Vogel’s method for finding a basic feasible solution to the transportation problem.The implementation of this algorithm follows the algorithm description in Winston [55, chap. 7.2].

AlgorithmSee Appendix B.20.

ExamplesSee extp bfs, exlu119, exlu119U, extp.

See AlsoTPmc, TPnw, TPsimplx

7.5.8 z2frstar

PurposeConvert a table of arcs and corresponding costs in a network to the forward and reverse star data storage repre-sentation.

Calling Syntax[P, Z, c, T, R, u] = z2frstar(Z, C, U)

Description of InputsZ A table with arcs (i, j). Z is n × 2, where n is the number of arcs. The

number of nodes m is set equal to the greatest element in Z.C Cost for each arc, n-vector.U Upper bounds on flow (optional).

Description of OutputsP Pointer vector to start of each node in the matrix Z.Z Arcs outgoing from the nodes in increasing order.

Z(:, 1) Tail. Z(:, 2) Head.c Costs related to the arcs in the matrix Z.T Trace vector, points to Z with sorting order Head.R Rewerse pointer vector in T for each node.u Upper bounds on flow if U is given as input, else infinity.

DescriptionThe routine z2frstar converts a table of arcs and corresponding costs in a network to the forward and reverse stardata storage representation as described in Ahuja et.al. [3, pages 35-36].

157

Page 158: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

8 Interfaces

8.1 The MEX-file Interface

TOMLAB is an open system with possibilities to interact with other program packages. An optimization solverimplemented in Fortran or C is called from TOMLAB using a MEX-file interface. MEX-file interfaces for bothFortran and C are easy to develop for Unix machines. Interfaces to many solvers are available on Unix. On PCmachines, there has been problems to make Fortran MEX-file interfaces that work properly. We have made generalMEX-file interfaces in C and converted solvers written in Fortran to C using the Fortran to C converter f2c [20].This solution is well-working and it should be easy to expand the list of available solvers to TOMLAB.

Presently, MEX-file interfaces has been developed for six general-purpose solvers available from the SystemsOptimization Laboratory, Department of Operations Research, Stanford University, Carlifornia; NPSOL 5.02 [28],NPOPT 1.0-10 (updated version of NPSOL), NLSSOL 5.0-2, QPOPT 1.0-10, LSSOL 1.05 and LPOPT 1.0-10.Furthermore, an interface to MINOS 5.5 [46] has been developed. MEX-file interfaces are available for both Unixand PC systems.

8.2 The Matlab Optimization Toolbox Interface

Included in TOMLAB is an interface to a number of the solvers in the Matlab Optimization Toolbox 1.x [13]Optimization Toolbox 2.0. The solvers that are directly possible to use, when a problem is generated in theTOMLAB format, are listed in Table 50. The user must of course have a valid license. The TOMLAB interfaceroutines are opt15Run and opt20Run, but the user does not need to call these directly, but can use the standardmulti-solver driver interface routines for each problem type, e.g. lpRun, qpRun, conRun, etc.

Several low-level interface routines have been written. For example, the constr solver needs both the objectivefunction and the vector of constraint functions in the same call, which nlp fc supplies. Also the gradient vectorand the matrix of constraint normals should be supplied in one call. These parameters are returned by the routinenlp gdc.

Optimization Toolbox 1.x is using a parameter vector OPTIONS of length 18, that the routine foptions is settingup the default values for. Optimization Toolbox 2.0 is instead using a structure.

Table 50: Matlab Optimization toolbox routines with a TOMLAB interface.

Function Type of problem solvedfmincon Constrained minimization.lsqnonlin Nonlinear least squares.fmins Unconstrained minimization using Nelder-Mead type simplex search method.fminu Unconstrained minimization using gradient search.linprog Linear programming.quadprog Quadratic programming.constr Constrained minimization.leastsq Nonlinear least squares.fmins Unconstrained minimization using Nelder-Mead type simplex search method.fminu Unconstrained minimization using gradient search.lp Linear programming.qp Quadratic programming.

8.3 The CUTE Interface

The Constrained and Unconstrained Testing Environment (CUTE) [11, 12] is a well-known software environmentfor nonlinear programming. The distribution of CUTE includes a test problem data base of nearly 1000 optimiza-tion problems, both academic and real-life applications. This data base is often used as a benchmark test in thedevelopment of general optimization software.

158

Page 159: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

CUTE stores the problems in the standard input format (SIF) in files with extension sif. There are tools to selectappropriate problems from the data base. Running CUTE, a SIF decoder creates up to five Fortran files; elfuns,extern, groups, ranges, and settyp, and one ASCII data file; outsdif.dat or outsdif.d. The Fortran files are compiledand linked together with the CUTE library and a solver routine. Running the binary executable, the problem issolved using the current solver. During the solution procedure, the ASCII data file outsdif.dat or outsdif.d is read.

With the CUTE distribution follows a Matlab interface. There are one gateway routine, ctools.f, for constrainedCUTE problems, and one gateway routine, utools.f, for unconstrained problems. These routines are using theMatlab MEX-file interface for communication between Matlab and the compiled Fortran (or C) code. The gatewayroutine is compiled and linked together with the Fortran files, generated by the SIF decoder, and the Matlab MEXlibrary to make a DLL (Dynamic Link Library) file. At run-time, Matlab calls the DLL, which will read the CUTEASCII data file for the problem specific information. Also included in the CUTE distribution is a set of Matlabm-files that calls the gateway routine.

For the TOMLAB CUTE interface we assume that the DLLs are already built and stored in any of four predefineddirectories; cutedll for constrained problems, cutebig for large constrained problems, cuteudll for unconstrainedproblems, cuteubig for large unconstrained problems. The name of the dll is the problem name used by CUTE,e.g. rosenbr.dll for the Rosenbrock banana function. The ASCII data file also has a unique name, e.g. rosenbr.dat.The CUTE Matlab interface assumes the DLLs to be named ctools.dll and utools.dll (and the data file to be calledoutsdif.dat on PC). TOMLAB calls the Matlab files in the CUTE distribution, but to solve the name problem,using the m-files ctools.m and utools.m to make a call to the correct DLL file. The ASCII data file is also copiedto a temporary file, with the necessary filename outsdif.dat, before executing the DLL.

When using the TOMLAB interface, the user either gets a menu of all DLLs in the CUTE directory chosen, ordirectly makes a choice of which problem to solve. Precompiled DLL files for the CUTE data set will be madeavailable, or the necessary files for the user to build his own DLLs. It is thus possible to run the huge set of CUTEtest problems in TOMLAB, using any solver callable from the toolbox.

8.4 The AMPL Interface

Using interfaces between a modeling language and TOMLAB could be of great benefit and improve the possibilitiesfor analysis on a given problem. As a first attempt, a TOMLAB interface to the modeling language AMPL [25]was built. The reason to choose AMPL was that it has a rudimentary Matlab interface written in C [27] thatcould easily be used.

AMPL is using ASCII files to define a problem. The naming convention is to use the problem name and vari-ous extensions, e.g. rosenbr.mod and rosenbr.dat for the Rosenbrock banana function. These files are normallyconverted to binary files with the extension nl, called nl-files. This gives a file rosenbr.nl for our example. ThenAMPL invokes a solver with two arguments, the problem name, e.g. rosenbr, and a string -AMPL. The secondargument is a flag telling AMPL is the caller. After solving the problem, the solver creates a file with extensionsol, e.g. rosenbr.sol, containing a termination message and the solution it has found.

The current TOMLAB AMPL interface is an interface to the problems defined in the AMPL nl-format. TOMLABassumes the nl-files to be stored in directory /tomlab/ampl or /tomlab/amplsp (for sparse problems). When usingthe TOMLAB interface, the user either gets a menu of the nl-files found or directly makes a choice of whichproblem to solve. The initialization routine in TOMLAB for AMPL problems, amp prob, either calls amplfunc orspamfunc, the two MEX-file interface routines written by Gay [27]. The low level routines amp f, amp g , etc. callsthe same MEX-file interface routines, and dependent on the parameters in the call, the appropriate information isreturned.

Note that the design of the AMPL solver interface makes it easy to run the TOMLAB solvers from AMPL usingthe Matlab Engine interface routines, a possible extension in the future. But indeed, any solver callable fromTOMLAB may now solve problems formulated in the AMPL language.

159

Page 160: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

A Description of Algorithms in TOMLAB

A.1 clsSolve

Transform the problem to the following form

minx

f(x) = 12r

T (x)r(x)

s/t aTi x = bi , i ∈ EaTi x ≥ bi , i ∈ IxL ≤ x ≤ xU

where E is the set of linear equalities and I the set of linear inequalities.Set k = 0, stop = 0 and the number of consequtive zero steps, α0 = 0.Set GNflag = 1 and AH = I.Set x(−1) = ∞, f (−1) = ∞, α = 1 and αmax = 1020.Set xi = max(x(0)

i , xLi) and x(0)

i = min(xi, xUi), i = 1, 2, ..., n.

if pSolve thenCall the presolve analysis routine preSolve.if any constraint was deleted in the presolve analysis routine thenUpdate E and I.

end ifend ifif x(0) is not feasible (with respect to the constraints) thenSolve the QP:

minx

f(x) = 12 x

TBx− x(0)TBx

s/t aTi x = bi , i ∈ EaTi x ≥ bi , i ∈ IxL ≤ x ≤ xU

where B = diag

(1

max(10−6,(x(0)i )2)

)will minimize the relative deviation between x and x(0) and B = I

minimizes the absolute deviation.Set x(0) = x.

end ifwhile not convergence doif k = 0 or I = ∅ thenif x(k)

i is beyond or very close to lower or upper bound, i = 1, 2, ..., n thenMove x(k)

i to bound.end ifSet up working sets for variables active on lower and upper bounds respectively.VL = {i : x(k)

i = xLi}, VU = {i : x(k)

i = xUi}

Set nract equal to the number of active variables.end ifif any variable has been moved to bound or k = 0 thenCompute r(k), J (k), f (k) and g(k).

end ifif k = 0 thenCompute H(k) = J (k)T

J (k).end ifif I = ∅ thenSet the constraint working set W = E.Compute first order Lagrange multiplier estimate λ.λi = −gi if i ∈ VU , λi = gi if i ∈ VL and λi = 0 else.if nract > 0 and α0 < 3 thenif nract < n thenRelease all variables xi, not activated in the previous iteration, where xLi

�= xUiand λi < −bTol.

if α = 0 then

160

Page 161: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Release all variables xi, inactive in the previous iteration, where xLi�= xUi

andλi < −bTol.

end ifelseRelease all variables xi where xLi

�= xUiand λi < −bTol.

end ifend if

elseif k = 0 thenSet up the initial constraint working set W = E ∪ {

i : i ∈ I ∧ aTi x = bi}.

The number of active variables and constraints must not exceed n.end ifif k > 0 and the release of more than one variable in the previous iteration resulted in a zero step thenActivate the released variables.Do not allow more than one variable to be released in this iteration.

end ifif there are any active variable or constraint thenCompute first order Lagrange multiplier estimate λ by solving the overdetermined system

AW (k)

ei , i ∈ V (k)L

−ei , i ∈ V (k)U

T

λ = g(k)

where ei is the ith unit row vector.Set λmin = min(λ)if λmin < −10−8 thenif only one variable is allowed to be released thenif λmin corresponds to a constraint thenRelease the constraint if it was not activated in the previous iteration.

elseRelease the corresponding variable xi, if it was not activated in the previous iteration and ifxLi

�= xUi.

end ifelseif λmin corresponds to a constraint thenRelease the constraint if it was not activated in the previous iteration.

end ifRelease all variables xi, not activated in the previous iteration, where xLi

�= xUiand λi < −10−8.

end ifend if

end ifend ifif variables or constraints was released thenUpdate the corresponding working sets and nract.

end ifif there has been any changes in the working sets or k = 0 thenCompute Z, null space basis for AW = Aij : i ∈W ∧ j /∈ VL ∪ VU

end ifif no variable or no constraint was released thenif all Lagrange multipliers corresponding to the active inequality constraints are ≥ −10−8 and for all activevariables i there either holds that λi ≥ −10−8 or xLi

= xUithen

Check convergence criterias, see A.1.1.end ifif any convergence criteria are fulfilled or nract = n thenSet stop = 1.

end ifend if

161

Page 162: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Check stop criterias, see A.1.2.if any stop criteria are fullfilled thenSet stop = 1.

end ifif stop thenEND ALGORITHM

end ifCompute search direction p with chosen method, see A.1.3.Set pfulli = pi if i /∈ VL ∪ VU else set pfulli = 0.Compute α1, step length estimate sent to line search routine.if k = 0 or ‖p‖ = 0 thenSet α1 = 1.

else

Set α1 = min(1,−2max(f(k−1)−f(k),10εx)

gT p=0

), where gi = gi : i /∈ VL ∪ VU .

if α1 < 0 thenChange sign on α1, pfull and p.

end ifend ifSet α1 = max (0.5, α1).if ‖p‖ = 0 thenSet x(k+1) = x(k), f (k+1) = f (k), g(k+1) = g(k), r(k+1) = r(k) and J (k+1) = J (k).

elseCompute αmax, the maximum step α such that x + αpfull is feasible with respect to the variable boundsand the nonactive inequality constraints.if αmax < 10−14 thenSet α = 0.

elseSolve the line search problem min

0<α≤αmax

f(x+ αpfull).

end ifif α = αmax thenif αmax is restricted by a variable bound thenActivate the corresponding variable.

elseActivate the corresponding constraint.

end ifend ifif α < 10−14 thenSet α0 = α0 + 1.

elseSet α0 = 0.

end ifSet x(k+1) = x(k) + αpfull.f (k+1), g(k+1), r(k+1) and J (k+1) was computed in the line search.if α > 10−14 thenDepending on the chosen method, update the approximation of the Hessian, see A.1.4.

end ifend ifSet k = k + 1.

end while

A.1.1 Convergence criterias

• maxi

∣∣∣x(k)i −x

(k−1)i

∣∣∣max

(∣∣∣x(k)i

∣∣∣,sizex

) ≤ εx and αmax > 10−14

162

Page 163: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

• max(∣∣ZT g(k)

∣∣max(

maxi/∈VL∪VU

∣∣∣x(k)i

∣∣∣ , sizex))

≤ εg max(abs(f (k)), sizef

)• f (k) ≤ εabsfsizef• Relative function value reduction low for LowIts iterations.

A.1.2 Stop criterias

• k ≥MaxIter• f (k) ≤ fLow

A.1.3 Computation of Search Direction

Gauss-Newton or hybrid method if GNflag = 1Solve the overdetermined system JZp = −r with rank estimation and a subspace minimization technique eitherusing Singular Value Decomposition or using QR-Decomposition with or without pivoting.Jij = Jij : j /∈ VL ∪ VU .

Fletcher-Xu, Al-Baali-Fletcher and Huschens TSSM if GNflag = 0Solve ZT HZp = −ZT g using Singular Value Decomposition with rank estimation and a subspace minimizationtechnique.Hij = Hij : i, j /∈ VL ∪ VU .

A.1.4 Update Procedure

Fletcher-XuSet z = αpfull.if f (k) − f (k+1) ≥ 0.2f (k) or ‖z‖ ≤ εx thenSet GNflag = 1.Set H(k+1) = J (k+1)T

J (k+1).elseSet GNflag = 0.

Set y = J (k+1)T

J (k+1)z +(J (k+1)T − J (k)T

)r(k+1).

if zT y < 0.01zT(g(k+1) − g(k)

)then

Set w = g(k+1) − g(k).elseSet w = y.

end ifif zTw < 10−13 or zTH(k)z < 10−13 thenSet GNflag = 1.Set H(k+1) = J (k+1)T

J (k+1).elseSet H(k+1) = H(k) + wwT

zTw− H(k)zzTH(k)T

zTH(k)z.

end ifend if

Al-Baali-FletcherSet z = αpfull.if f (k) − f (k+1) ≥ 0.2f (k) or ‖z‖ ≤ εx thenSet GNflag = 1.Set H(k+1) = J (k+1)T

J (k+1).elseSet GNflag = 0.

163

Page 164: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Set y = J (k+1)T

J (k+1)z +(J (k+1)T − J (k)T

)r(k+1).

if zT y < 0.2zTH(k)z thenSet w = 0.8zTH(k)z

zTH(k)z−zT yy +

(1− 0.8zTH(k)z

zTH(k)z−zT y

)H(k)z.

elseSet w = y.

end ifif zTw < 10−10 or zTH(k)z < 10−10 thenSet GNflag = 1.Set H(k+1) = J (k+1)T

J (k+1).elseSet H(k+1) = H(k) + wwT

zTw− H(k)zzTH(k)T

zTH(k)z.

end ifend if

Huschens TSSMSet:GNflag = 0,z = pfull,y* =

(J (k+1) − J (k)

)T r(k+1)

‖r(k)‖ ,y = J (k+1)T

J (k+1)z +∥∥r(k+1)

∥∥ y* andBs = J (k+1)T

J (k+1) +∥∥r(k+1)

∥∥A(k)H .

if zTBsz > 0 and yT z > 0 then

Set v = y +√

yT zzTBsz

Bsz.elseSet v = y.

end if

Set A(k+1)H = A(k)

H +

(y�−A

(k)H z

)vT +v

(y�−A

(k)H z

)T

vT z−

(y�−A

(k)H z

)TzvvT

(vT s)2.

Set H(k+1) = H(k) +∥∥r(k+1)

∥∥A(k+1)H .

A.2 cutplane

Set mi = m−meq.if mi > 0 thenAdd mi slack variables to create a problem on standard form.Update A, c and n.

end ifSet ε1 = 10−12.if B 0 is not given thenCall Phase I simplex routine Phase1Simplex to get the solution x and B.if no feasible Phase I solution were found thenSTOP.

end ifend ifSet Bidx = {i : Bi = 1}, the set of basic variables.Set Nidx = {i : Bi = 0}, the set of nonbasic variables.if x 0 is not given thenSet xj = 0, j /∈ Bidx.Solve ABxB = b, where AB = Aij , j ∈ Bidx and xB = xj , j ∈ Bidx.

elseSet x = x 0.

end ifCall Phase II simplex routine Phase2Simplex to get the solution x, B and y.for k = 0, 1, ..., kmax do

164

Page 165: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Update Bidx and Nidx.Set xidx = xj , j ≤ nI ∧ j ∈ Bidx.Set xIj

= �xidxj+ ε1�.

Set xrj= max(0, xidxj

− xIj).

Determine the variable with its fractional part closest to 0.5 i.e. set i = argmin(|xri− 0.5|).

if i = ∅ or xri< ε1 then

STOP, convergence.end ifSet cN = A−1

BiAN , where A−1

Biis the i:th row in A−1

B and AN = Aij , j ∈ Nidx.Set aj = 0 if j ∈ Nidx else set aj = max(0, cNj

− �cNj+ ε1�).

Set A =(A 0m×1

a −1), b = ( bT xri )T , c = ( cT 0 )T and x = ( xT −xri )T .

Set B = ( B 1 ), n = n+ 1 and m = m+ 1.Call dual simplex routine lpdual to get the solution x, B and y.if the dual simplex routine failed thenUse Phase I and Phase II simplex routines.

end ifend for

A.3 glbSolve

Set the global/local search weight parameter ε.Set Ci1 = 1

2 and Li1 = 12 , i = 1, 2, 3, ..., n.

Set F1 = f(x), where xi = xLi+ Ci1 (xUi

− xLi), i = 1, 2, 3, ..., n.

Set D1 =

√n∑

k=1

L2k.

Set fmin = F1 and imin = 1.for t = 1, 2, 3, ..., T doSet S =

{j : Dj ≥ Dimin

∧ Fj = mini{Fi : Di = Dj}

}.

Define α and β by letting the line y = αx′ + β pass through the points (Dimin, Fimin

) and(maxj

(Dj),mini

(Fi : Di = max

j(Dj)

)).

Let S be the set of all rectangles j ∈ S fullfilling Fj ≤ αDj + β + 10−12.Let S be the set of all rectangles in S which lies on the convex hull defined by the points (Dj , Fj), j ∈ S.while S �= ∅ doSelect j as the first element in S.Set S = S \ {j}.Let I be the set of dimensions with maximum rectangle side length, i.e. I =

{i : Dij = max

k(Dkj)

}.

Let δ equal two-thirds of this maximum side length, i.e. δ = 23 max

k(Dkj).

for all i ∈ I doSet ck = Ckj , k = 1, 2, 3, ..., n.Set c = c+ δei and c = c− δei, where ei is the ith unit vector.Compute f = f(x) and f = f(x) where xk = xLk

+ ck (xUk− xLk

) and xk = xLk+ ck (xUk

− xLk).

Set wi = min(f , f).Set C =

(C c c

)and F =

(F f f

).

end forwhile I �= ∅ doSelect the dimension i ∈ I with the lowest value of wi and set I = I \ {i}.Set Lij = 1

2δ.Let j and j be the indices that corresponds to the points c and c above.Set Lkj = Lkj and Lkj = Lkj , k = 1, 2, 3, ..., n.

Set Dj =

√n∑

k=1

L2kj .

165

Page 166: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Set Dj = Dj and Dj = Dj .end while

end whileSet fmin = min

j(Fj).

Set imin = argmin(Fj−fmin+E

Dj

), where E = max

(ε|fmin|, 10−8

).

end for

A.3.1 conhull

The points (xi, yi), i = 1, 2, 3, ...,m are given with x1 ≤ x2 ≤ ... ≤ xm.Set h = (1, 2, ...,m).if m ≥ 3 thenSet START = 1, v = START , w = m and flag = 0.while next(v) �= START or flag = 0 doif next(v) = w thenSet flag = 0.

end ifSet a = v, b = next(v) and c = next(next(v)).

Set A =

xa ya 1xb yb 1xc yc 1

.

if det(A) ≥ 0 thenSet leftturn = 0.

elseSet leftturn = 1.

end ifif leftturn thenSet v = next(v).

elseSet j = next(v).Set x = (x1, x2, ..., xj−1, xj+1, ..., xm), y = (y1, y2, ..., yj−1, yj+1, ..., ym) and

h = (h1, h2, ..., hj−1, hj+1, ..., hm).Set m = m− 1, w = w − 1 and v = pred(v).

end ifend while

end if

A.3.2 next

if v = m thenSet i = 1.

elseSet i = v + 1.

end if

A.3.3 pred

if v = 1 thenSet i = m.

elseSet i = v − 1.

end if

166

Page 167: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

A.4 LineSearch

A.4.1 Bracketing Phase

Set α(0) = 0.if f ′(0) = 0 thenSet µ = αmax.

elseSet µ = min

(αmax,

fLow−f(0)ρf ′(0)

).

end ifif µ < 0 thenSet µ = αmax.

end ifSet α(1) = min (1, µ, α1).if α(1) < 10−14 thenSet α(1) = 0.Terminate Line Search.

end iffor k = 1, 2, 3, ... doif f

(α(k)

) ≤ fLow thenTerminate Line Search.

end ifif f

(α(k)

) ≥ f (α(k−1)

)or f

(α(k)

)> f(0) + α(k)ρf ′(0) then

if f(α(k)

)= f

(α(k−1)

)and ‖p‖ ≤ 10−8 then

Terminate Line Search.end ifSet a(k) = α(k−1) and b(k) = α(k).Set k = k.Go to Sectioning Phase.

end ifif

∣∣f ′ (α(k))∣∣ ≤ −σf ′(0) then

Set α(k) = 0.Terminate Line Search.

end ifif f ′

(α(k)

) ≥ 0 thenSet a(k) = α(k) and b(k) = α(k−1).Set k = k.Go to Sectioning Phase.

end ifif µ ≤ 2α(k) − α(k−1) thenSet α(k+1) = µ.

elseChoose α(k+1) ∈ [

2α(k) − α(k)−1),min(µ, α(k) + τ1

(α(k) − α(k)−1)

))]using quadratic or cubic interpola-

tion. See A.4.3 and A.4.4 respectively.end ifif k > 30 thenSet α(k) = 0.Terminate Line Search.

end ifend for

A.4.2 Sectioning Phase

for k = k, k + 1, ... doif

∣∣a(k) − b(k)∣∣ ≤ ε1 then

if f(a(k)

)< f

(b(k)

)or f

(a(k)

)= f

(b(k)

) ∧ a(k) > b(k) then

167

Page 168: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Set α(k) = a(k).elseSet α(k) = b(k).

end ifTerminate Line Search.

end ifChoose α(k) ∈ [

a(k) + τ2(b(k) − a(k)

), b(k) − τ3

(b(k) − a(k)

)]using quadratic or cubic interpolation. See A.4.3

and A.4.4 respectively.if

(a(k) − α(k)

)f ′

(a(k)

) ≤ ε2 thenSet α(k) = a(k).Terminate Line Search.

end ifif f

(α(k)

)> f(0) + ρα(k)f ′(0) or f

(α(k)

) ≥ f (a(k)

)then

Set a(k+1) = a(k) and b(k+1) = α(k).elseif

∣∣f ′ (α(k))∣∣ ≤ −σf ′(0) then

Terminate Line Search.end ifSet a(k+1) = α(k).if

(b(k) − a(k)

)f ′

(α(k)

) ≥ 0 thenSet b(k+1) = a(k).

elseSet b(k+1) = b(k).

end ifend if

end for

A.4.3 intpol2

Transform g0 to [0, 1] by setting g0 = g0 (x1 − x0).Set c = f1 − f0 − g0.if c = 0 thenSet α = min (a, b).

elseTransform a and b to [0, 1] by setting a = a−x0

x1−x0and b = b−x0

x1−x0.

Define q (z) = f0 + g0z + cz2.Set zmin = − g0

2c .if q (zmin) ≤ q (a) and zmin ∈ [a, b] thenif q (zmin) ≤ q(b) thenSet α = x0 + zmin (x1 − x0).

elseSet α = b.

end ifelse if q (a) < q(b) thenSet α = a.

elseSet α = b.

end ifend if

A.4.4 intpol3

Transform g0 and g1 to [0, 1] by setting g0 = g0 (x1 − x0) and g1 = g1 (x1 − x0).Set r = 3 (f1 − f0)− 2g0 − g1.Set s = g0 + g1 − 2 (f1 − f0).if |s| < 10−12 |r| then

168

Page 169: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Call quadratic ineterpolation routine intpol2.elseTransform a and b to [0, 1] by setting a = a−x0

x1−x0and b = b−x0

x1−x0.

Define c(z) = f0 + g0z + rz2 + sz3.

Set z1 =−r+

√r2−3sg03s and z2 =

−r−√

r2−3sg03s .

if z1 ∈ [a, b] or z2 ∈ [a, b] thenif z1 ∈ [a, b] thenif z2 ∈ [a, b] thenif c(z1) ≤ c(z2) thenSet zmin = z1.

elseSet zmin = z2.

end ifend if

elseSet zmin = z2.

end ifif c(zmin) ≤ c(a) thenif c(zmin) ≤ c(b) thenSet α = x0 + zmin(x1 − x0).

elseSet α = b.

end ifelse if c(a) < c(b) thenSet α = a.

elseSet α = b.

end ifelseif c(a) < c(b) thenSet α = a.

elseSet α = b

end ifend if

end if

A.5 ucSolve

Set k = 0, stop = 0 and the number of consequtive zero steps, α0 = 0.Set β = 0, cgstep = 1 and cgrestart = 1 if restart teqnique shall be used else set cgrestart = 0.Set x(−1) = ∞, f (−1) = ∞, B(0) = I and α = 1.Set xi = max(x(0)

i , xLi) and x(0)

i = min(xi, xUi), i = 1, 2, ..., n.

while not convergence doif x(k)

i is beyond or very close to lower or upper bound, i = 1, 2, ..., n thenMove x(k)

i to bound.end ifSet up working sets for variables active on lower and upper bounds respectively.VL = {i : x(k)

i = xLi}, VU = {i : x(k)

i = xUi}

Set nract equal to the number of active variables.if any variable has been moved to bound or k = 0 thenCompute f (k) and g(k).

end ifCompute H(k).if nract > 0 and α0 < 3 then

169

Page 170: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Compute first order Lagrange multiplier estimate λ.λi = −gi if i ∈ VU , λi = gi if i ∈ VL and λi = 0 else.if nract < n thenRelease all variables xi, not activated in the previous iteration, where xLi

�= xUiand λi < −bTol.

if α = 0 thenRelease all variables xi, inactive in the previous iteration, where xLi

�= xUiand

λi < −bTol.end if

elseRelease all variables xi where xLi

�= xUiand λi < −bTol.

end ifend ifif variables was released thenUpdate VL, VU and nract.

elseCheck convergence criterias, see A.5.1.if any convergence criteria are fulfilled thenSet stop = 1.

end ifif stop and nract ∈ (0, n) and α0 < 3 thenCompute the search direction, p, for the free variables by solving Hp = −g,where Hij = Hij : i, j /∈ VL ∪ VU and gi = gi : i /∈ VL ∪ VU .Compute αmax, the maximum step α such that x+αpfull is feasible with respect to the variable bounds,where pfulli = pi if i /∈ VL ∪ VU else pfulli = 0.Compute second order Lagrange multiplier estimate, η, for the active variables.η = λ+ Hαmaxp,where λ = λi : i ∈ VL ∪ VU and H = Hij : i ∈ VL ∪ VU , j /∈ VL ∪ VU .if ηi < −bTol and xLi

�= xUithen

Release the corresponding variable xi, set stop = 0 and update VL, VU and nract.end if

end ifif stop and nract < n thenCheck if x is a saddle or a minimum point.Compute the eigenvalues of H and let ξ be the smallest eigenvalue.if ξ < −10−12 and no eigenvector search direction was used in previous iteration thenSet stop = 0 and set p equal to the eigenvector corresponding to ξ.Check if p is a descent direction i.e. if gT p < 0.If p is not a descent direction change sign on p.

end ifend if

end ifCheck stop criterias, see A.5.2.if any stop criteria are fullfilled thenSet stop = 1.

end ifif stop thenEND ALGORITHM

end ifif α = 0 and variables was released in the current iteration based on first order Lagrange multiplier estimatethenSearch in the negative gradient direction for the released variables.Set pfulli = −gi if variable i was released, else set pfulli = 0.

elserepeatCompute search direction p with chosen method if not computed before in this iteration, see A.5.3.if nract > 0 thenCompute second order Lagrange multiplier estimate η.

170

Page 171: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

if ηi < −bTol and xLi�= xUi

thenRelease the corresponding variable xi and update VL, VU and nract.

end ifend if

until no variable is released.Set pfulli = pi if i /∈ VL ∪ VU else set pfulli = 0.

end ifCompute α1, step length estimate sent to line search routine.if k > 0 and gT p �= 0 then

Set α1 = min(1,−2max(f(k−1)−f(k),10εx)

gT p=0

).

elseSet α1 = 1.

end ifSet α1 = max (0.5, α1).if p is a descent direction thenCompute αmax

if αmax < 10−14 thenSet α = 0.

elseSolve the line search problem min

0<α≤αmax

f(x+ αpfull).

end ifelseCompute the eigenvalues and their corresponding eigenvectors of H.Let P be the set of search directions containing all eigenvectors corresponding to negative eigenvalues, andthe negative search direction −p.for all p ∈ P and in order of most descent doSet pfulli = pi if i /∈ VL ∪ VU else set pfulli = 0.Compute αmax.if αmax > 10−7 thenSet α1 = 1.Solve the line search problem min

0<α≤αmax

f(x+ αpfull).

elseSet α = 0.

end ifif α > 10−6 thenAccept the search direction pfull and the step length α.break for

end ifend for

end ifif α < 10−14 thenSet α0 = α0 + 1.

elseSet α0 = 0.

end ifSet x(k+1) = x(k) + αpfull.f (k+1) and g(k+1) was computed in the line search.Depending on the chosen method, update the approximation of the Hessian, the approximation of the inverseHessian or β, see A.5.4.Set k = k + 1.

end while

171

Page 172: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

A.5.1 Convergence criterias

• maxi

∣∣∣x(k)i −x

(k−1)i

∣∣∣max

(∣∣∣x(k)i

∣∣∣,sizex

) ≤ εx

• maxi/∈VL∪VU

(∣∣∣g(k)i

∣∣∣max(∣∣∣x(k)

i

∣∣∣ , sizex))≤ εg max

(∣∣f (k)∣∣ , sizef)

• Relative function value reduction low for LowIts iterations.

A.5.2 Stop criterias

• k ≥MaxIter• f (k) ≤ fLow

A.5.3 Computation of Search Direction

NewtonSolve Hp = −g either using Singular Value Decomposition with rank estimation and a subspace minimizationtechnique or using LU-Decomposition with or without pivoting.

Safeguarded quasi-Newton DFP or BFGSSolve Bp = −g either using Singular Value Decomposition with rank estimation and a subspace minimizationtechnique or using LU-Decomposition with or without pivoting.

Safeguarded quasi-Newton inverse DFP or BFGSSet p = −Bg.

Fletcher-Reeves, Polak-Ribiere and Fletcher conjugate descent CGif cgrestart and cgstep = n+ 1 thenSet cgstep = 1 and β = 0.

end ifif k=0 thenSet p = −g.

elseSet p = −g + βp.

end ifSet cgstep = cgstep + 1.

A.5.4 Update Procedure

Safeguarded quasi-Newton BFGSSet z = αp.if ‖z‖ > εx thenSet y = g(k+1) − g(k).if zT y < 0.2 · zT Bz thenSet w = 0.8zT Bz

zT Bz−zT yy +

(1− 0.8zT Bz

zT Bz−zT y

)Bz.

elseSet w = y.

end ifif zTw = 0 thenif zT Bz �= 0 thenSet B(k+1) = B(k) − BzzT B

zT Bz.

end ifelse if zT Bz = 0 then

172

Page 173: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Set B(k+1) = B(k) + wwT

zTw.

elseSet B(k+1) = B(k) + wwT

zTw− BzzT B

zT Bzend if

end if

Safeguarded quasi-Newton inverse BFGSSet z = αp.if ‖z‖ > εx thenSet y = g(k+1) − g(k).if zT y �= 0 thenSet B(k+1) = B(k) +

(1 + yT By

zT y

)zzT

zT y− zyT B+ByzT

zT y.

end ifend if

Safeguarded quasi-Newton inverse DFPSet z = αp.if ‖z‖ > εx thenSet y = g(k+1) − g(k).if zT y < 0.2 · yT By thenSet w = 0.8yT By

yT By−zT yz +

(1− 0.8yT By

yT By−zT y

)By.

elseSet w = z.

end ifif zTw = 0 thenif yT By �= 0 thenSet B(k+1) = B(k) − ByyT B

yT By.

end ifelse if yT By = 0 thenSet B(k+1) = B(k) + wwT

yTw.

elseSet B(k+1) = B(k) + wwT

yTw− ByyT B

yT By.

end ifend if

Safeguarded quasi-Newton DFPSet z = αp.if ‖z‖ > εx thenSet y = g(k+1) − g(k).if zT y �= 0 thenSet B(k+1) = B(k) +

(1 + zT Bz

zT y

)yyT

zT y− yzT B+BzyT

zT y.

end ifend if

Fletcher-Reeves CG

Set β = g(k+1)Tg(k+1)

g(k)T g(k) .

Polak-Ribiere CG

Set β =

(g(k+1)T −g(k)T

)g(k+1)

g(k)T g(k) .

Fletcher conjugate descent CG

Set β = − g(k+1)Tg(k+1)

g(k)T p.

173

Page 174: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

B Description of Algorithms in TOMLAB LDO

B.1 akarmark

if x 0 is not given or x 0j = 0 for any j = 1, 2, ..., n thenSet x(0) = ( 1

n , ...,1n ).

if b−Ax(0) �= 0 then

Set A = ( A b−Ax(0) ), x(0) = ( x(0)T

1 )T and c = ( cT 2n∑

j=1

|ci| )T .Set n = n+ 1

end ifelseSet x(0) = x 0.

end ifCompute L = �1 + ∑

i

∑j

log2(1 + |aij |)�.Set tol = 2−2L.Compute α = n−1

3n and r = 1√n(n−1)

.

Set q = 0.97 and µ = min(10−12, tol2n ).for k = 0, 1, ..., kmax − 1 doSet D = diag{x(k)

1 , ..., x(k)n }, c = Dc, and A = AD.

Compute dual estimate y(k) by solving Ay = c− (µ, ..., µ)T .Compute reduced cost vector R = c−( µ

x(k)1

, ..., µ

x(k)n

)T−AT y, projected gradient vector gp = c−(µ, ..., µ)T−AT y

and search direction d = −Dgp.if R ≥ −10−10 and it either holds that cTx(k) − bT y(k) < tol or that the function value redution is less than10−14 thenLet W be a index set of the variables active on their lower bounds, i.e.W =

{j : x(k)

j ≤ 10−12}.

Set r equal to the rank of A plus the number of elements in W .while r < n doLet Z be a basis for the null space of the matrix

(A

ei,i∈W), where ei is the i:th unit row vector.

Let di = Zi1 if i /∈W and di = 0 if i ∈W .if cT d ≥ 0 thenSet d = −d.

end ifSet α = min

i/∈W,di<0

−x(k)i

di.

if {i : i /∈W,di < 0} = ∅ thenSTOP, purification failed.

end ifSet x(k+1) = x(k) + αd.Update W and set r equal to the rank of B plus the number of elements in W .

end whileSTOP, purification succeeded.

end ifSet λinvmax = max

j

dj

x(k)j

.

Set α = min(

qλinv

max, (1−q)2

µ

).

Set x(k+1) = x(k) + αd.end for

B.2 dijkstra

Set n equal to the number of nodes.Set B = {s} and T = N\{s}, where N is the set of all nodes.

174

Page 175: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Set dist(s) = 0 and pred(s) = 0.for j = 1, 2, ..., n doif (s, j) ∈ Z thenSet dist(j) = csj , where cij means the cost of arc (i, j).Set pred(j) = s.

elseSet dist(j) = ∞.

end ifend forwhile B �= N doLet i ∈ T be a node for which dist(i) = min{dist(j) : j ∈ T}.Set B = B ∪ {i} and T = T\{i}.for each j : (i, j) ∈ Z doif dist(j) > dist(i) + cij thenSet dist(j) = dist(i) + cij .Set pred(j) = i.

end ifend for

end while

B.3 dpinvent

Set xLOW = minjxLj

and xUPP = maxjxUj

.

Set s = 1 + xUPP − xLOW .Set Uij = 0, i = 1, 2, .., s, j = 1, 2, ..., n.Set fi = ∞ and fPi

= ∞, i = 1, 2, ..., s.Set fP1+xS−xLOW

= 0.for t = 1, 2, ..., n doSet ulow = uLt

and uupp = uUt.

if t = n thenSet xlow = xupp = xLAST .

elseSet xlow = xLt

and xupp = xUt.

end iffor i = xlow, xlow + 1, ..., xupp doSet umin = 0 and fmin = ∞.for j = ulow, ulow + 1, ..., uupp doSet x = i− j + dt.if xLOW ≤ x ≤ xUPP thenSet fu = P s(j > 0) + Ptj + I s(i > 0) + Iti+ fP1+x−xLOW

.if fu < fmin thenSet umin = j and fmin = fu.

end ifend if

end forSet f1+i−xLOW

= fmin and U1+i−xLOW ,t = umin.end forSet fP = f .

end forSet x = xLAST .for t = n, n− 1, ..., 1 doSet ut = U1+x−xLOW ,t.Set x = x− ut + dt.

end forSet f opt = f1+xLAST −xLOW

.

175

Page 176: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

B.4 dpknap

if u U is not given thenSet uUj

= � bAj

�, j = 1, 2, ..., n.elseSet uU = u U .

end ifSet Uij = 0, i = 1, 2, .., b+ 1, j = 1, 2, ..., n.Set fi = 0 and fPi

= 0, i = 1, 2, ..., b+ 1.for i = 1, 2, ..., n dofor k = 1, 2, ..., b+ 1 doSet umax = 0 and fmax = fPk

.for j = 1, 2, ...,min(uUi

, � bAi

�) doSet x = (k − 1)−Aij.if x < 0 thenbreak for

elseif cij + fP1+x

> fmax thenSet umax = j and fmax = cij + fP1+x

.end if

end ifend forSet fk = fmax and Uki = umax.

end forSet fP = f .

end forSet x = b+ 1.for k = n, n− 1, ..., 1 doSet uk = Uxk.Set x = x−AkUxk.

end forSet f opt = fb+1.

B.5 gsearch

Set pred(i) = 0 and mark(i) = 0, i = 1, 2, ...,m.Set pred(s) = −1 and mark(s) = 1.Set LIST = {s}.while LIST �= ∅ doSet i equal to the first element in LIST .if there is an arc from node i to node j and mark(j) = 0 thenSet mark(j) = 1 and pred(j) = i.Put j first in LIST .

elseDelete the first element in LIST .

end ifend while

B.6 gsearchq

Set pred(i) = 0 and mark(i) = 0, i = 1, 2, ...,m.Set pred(s) = −1 and mark(s) = 1.Set LIST = {s}.while LIST �= ∅ doSet i equal to the first element in LIST .Delete the first element in LIST .for all arcs (i, j) outgoing from node i do

176

Page 177: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

if mark(j) = 0 thenSet mark(j) = 1 and pred(j) = i.Put j at the end of LIST .

end ifend for

end while

B.7 karmark

Compute L = �1 + log2(1 + maxj

|cj |) log2(1 +m) +∑i

∑j

log2(1 + |aij |)�.Set tol = max(2−L, 10−0).Compute α = n−1

3n and r = 1√n(n−1)

.

Set x(0) = ( 1n , ...,

1n )

T .Set k = 0.while cTx(k) > tol and k ≤ kmax doSet D = diag{x(k)

1 , ..., x(k)n }, x(0) = ( 1

n , ...,1n ), c = Dc and B =

(AD1T

).

Compute d =(BT (BBT )−1B − I) c.

if Goldfarb/Todd choice of update thenSet α = 0.99.Compute x = x(0) + α d

n‖d‖ .else if Bazaraa choice of update thenCompute x = x(0) + αr d

‖d‖ .end ifSet x(k+1) = Dx

1TDx.

Set k = k + 1.end whileLet W be a index set of the variables active on their lower bounds, i.e. W =

{j : x(k)

j ≤ 10−12}.

Set B =(A1T

)and set r equal to the rank of B plus the number of elements in W .

while r < n doLet Z be a basis for the null space of the matrix

(B

ei,i∈W), where ei is the i:th unit row vector.

Let di = Zi1 if i /∈W and di = 0 if i ∈W .if cT d ≥ 0 thenSet d = −d.

end ifSet α = min

i/∈W,di<0

−x(k)i

di.

Set x(k+1) = x(k) + αd.Update W and set r equal to the rank of B plus the number of elements in W .

end while

B.8 ksrelax

Set xj = 0, j = 1, 2, ..., n and ui = 0, i = 1, 2, ...,m− 1.Set Arj = Arj , j = 1, 2, ..., n and b = br.Set Aij = Aij and bi = bi, i ∈ {1, 2, ...,m} − {r}, j = 1, 2, ..., n.Set λ = 2, fail = 0, fP = 0, fDold

= ∞ and xP = x.for k = 1, 2, ..., kmax doif cTx ≤ −∞ thenSTOP, convergence.

end ifSet c = ATu.Call the knapsack problem solver dpknap with the parameters A, b, c and xU to get the solution x and fD.Set fD = fD + uT b and compute the subgradient g = b− Ax.if gi ≥ 0, i = 1, 2, ...,m− 1 and cTx > fP then

177

Page 178: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Set fP = cTx and xP = x.Set fail = 0 and λ = 2.

end ifif fD < fDold

thenSet fail = 0.

elseSet fail = fail + 1.

end ifSet fDold

= fD.if fail > 0 thenSet λ = 1

2λ and fail = 0.end ifSet sSQ = gT g + (b− Ax)2.if α ≤ 0 or sSQ ≤ 10−14 thenSTOP, convergence.

end ifSet α = α

sSQand ui = max(0, ui − αgi), i = 1, 2, ...,m− 1.

end for

B.9 labelcor

Set dist(j) = ∞ for each j ∈ N\{s}, where N is the set of all nodes.Set dist(s) = 0 and pred(s) = 0.repeatfor all arcs (i, j) ∈ Z doif dist(j) > dist(i) + cij thenSet dist(j) = dist(i) + cij .Set pred(j) = i.

end ifend for

until no changes in dist are made

B.10 lpdual

Set mi = m−meq.if mi > 0 thenAdd mi slack variables to create a problem on standard form.Update A, c and n.

end ifif B 0 is given thenSet B(0) = {i : B 0i = 1}, the set of basic variables.Set N (0) = {i : B 0i = 0}, the set of nonbasic variables.

elseSet B(0) = {n−m+ 1, n−m+ 2, ..., n}.Set N (0) = {1, 2, ..., n−m}.

end ifif x 0 is given thenSet x = x 0.

elseSet xj = 0 : j ∈ N .Solve ABxB = b, where AB = Aij : j ∈ B and xB = xj : j ∈ B.

end ifif y 0 is given thenSet y = y 0.

elseCompute initial shadow prices y by solving ABy = cB , where cB = cj : j ∈ B.

178

Page 179: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

end ifCompute initial reduced costs cN = cN −AT

Ny, where AN = Aij : j ∈ N and cN = cj : j ∈ N .if cNi

< 0 for any i = 1, 2, ..., n−m thenif cNi

< −10−13 for any i = 1, 2, ..., n−m thenSTOP, initial shadow prices y is not dual feasible.

elseSet cNi

= 0 for all i such that −10−13 < cNi< 0.

end ifend iffor k = 1, 2, ..., kmax doCompute the objective function value f = bT y,if xi ≥ −10−10 for all i = 1, 2, ..., n thenif xi < 0 for any i = 1, 2, ..., n thenSet xi = 0 for all i such that xi < 0.

end ifSTOP, convergence.

end ifChoose the variable xp to exclude from the basis either using Blands rule or Minimal Reduced Cost rule.Solve AT

Bu = ep, where Bp = p.Compute v = AT

Nu.if vj ≥ 0 for all j = 1, 2, ..., n−m thenSTOP, infeasible dual problem.

end ifDetermine nonbasic variable xq to enter the base. Choose

−cNq

vq= min

{−cNj

vj: vj < −10−10, j = 1, 2, ..., n−m

}def= γ,

where q = Nq.if γ = ∅ thenChoose

−cNq

vq= min

{−cNj

vj: vj < 0, j = 1, 2, ..., n−m

}def= γ.

end ifif γ = ∅ or γ > 105 thenSTOP, numerical difficulties.

end ifSet cN = cN + γv, cp = γ, cq = 0 and y = y − γu.Compute primal search direction d by solving ABd = −aq, where aq is the q:th column in A.Set xq = α = xp

vq, xB = xB + αd and xp = 0.

Set B = B ∪ {q}\{p} and N = N ∪ {p}\{q}.if α > 105 thenNumerical difficuties, recompute x by setting xN = 0 and solving ABxB = b.

end ifend for

B.11 lpkarma

Set k = m+ n+ 2 and l = 2(m+ n) + 2.

Set M = 3

[n∑

j=1

|cj |+m∑i=1

|bi|+ 2maxi,j

(|cj |, |bi|)].

Set B =

cT −bT 01×k

A 0m×m Im×m 0m×n+1 −b0n×n AT 0n×m −In×n 0n×1 −c

11×l−1 −M

179

Page 180: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Set vi =l∑

j=1

Bij , i = 1, 2, ..., k.

Set B =(B −v )

and d =(01×l 1

)T .Call karmark with constraint matrix B and cost vector d to get the solution x.Set x = (M + 1)xj , j = 1, 2..., n.Set y = (M + 1)xj , j = n+ 1, ..., n+m.

B.12 lpsimp1

Solve the LP problemminx

f(x) = cT x

s/t Ax = bx ≥ 0

with A =(A Im×m

), c =

(0n 1meq 0m−meq

)T , x 0 =(0n bT

)T and

B 0 =(0n 1m

)T .if f(x) < 10−10 thenif there are no artificial variable left in the base thenSet x and B equal to those entries in x and B corresponding to the non artificial variables.

end ifelseNo feasible solution exist.Set x and B equal to those entries in x and B corresponding to the non artificial variables.

end if

B.13 lpsimp2

Set mi = m−meq.if mi > 0 thenAdd mi slack variables to create a problem on standard form.Update A, c and n.if x 0 is given thenExtend x 0 with zeros for the added slack variables.

end ifend ifif neither B 0 nor x 0 is given thenSet B(0) = {n−m+ 1, n−m+ 2, ..., n}.Set N (0) = {1, 2, ..., n−m}.

else if B 0 is given thenSet B(0) = {i : B 0i = 1}, the set of basic variables.Set N (0) = {i : B 0i = 0}, the set of nonbasic variables.

end ifif x 0 is given thenSet x = x 0.Set B(0) = {i : xi > 0}.Set N (0) = {i : xi ≤ 0}.if the number of elements in B(0) is less than m thenAdd to B(0), index elements i corresponding to xi = 0 to have B(0) contain m elements.Delete the same elements i from N (0).

end ifelseSet xj = 0 : j ∈ N .Solve ABxB = b, where AB = Aij : j ∈ B and xB = xj : j ∈ B.

end iffor k = 1, 2, ..., kmax doCompute the objective function value f = cTBxB, where cB = cj : j ∈ B.

180

Page 181: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Compute shadow prices y by solving ATBy = cB .

Compute reduced costs cN = cN −ATNy, where AN = Aij : j ∈ N and cN = cj : j ∈ N .

if cN ≥ −εf thenSTOP, x is optimal.

end ifChoose the variable xq to include in the new basis either using Bland’s anti-cycling rule or the MinimalReduced Cost rule.Compute the search direction d by solving ABd = −aq, where aq is the q:th column in A.Set P = {i : di < 0}.if P = ∅ thenThe problem is unbounded, STOP.

elseSet the step length α = −xp

dp= min

i∈P

(−xBi

di

).

Variable xp is to be excluded from the basis.end ifSet xB = xB + αd.Set xp = 0 and xq = α.Set B(k+1) = B(k) ∪ {q}\{p} and N (k+1) = N (k) ∪ {p}\{q}.

end for

B.14 maxflow

Set m equal to the number of nodes.Set xij = 0 ∀(i, j) ∈ Z.Set max flow = 0.while not convergence doSet pred(i) = 0 and flow(i) = 0, i = 1, 2, ...,m.Set pred(s) = −1 and flow(s) = ∞.Set LIST = s.while LIST �= ∅ and pred(t) = 0 doSet i equal to the first element in LIST .for all arcs (i, j) outgoing from node i doif pred(j) = 0 and xij < x Uij thenSet pred(j) = i and flow(j) = min (flow(i), x Uij − xij).Put j at the end of LIST .

end ifend forfor all arcs (j, i) coming in to node i doif pred(j) = 0 and xji < x Uji thenSet pred(j) = i and flow(j) = min (flow(i), xij).Put j at the end of LIST .

end ifend forDelete the first element in LIST .

end whileif pred(t) > 0 thenSet j = t and i = pred(t).Set xij = xij + flow(t).while i �= s doSet j = i and i = pred(i).if (i, j) ∈ Z thenSet xij = xij + flow(t).

elseSet xij = xij − flow(t).

end ifend while

181

Page 182: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Set max flow = max flow + flow(t).elseSTOP, the maximum flow is max flow.

end ifend while

B.15 modlabel

Set dist(j) = ∞ for each j ∈ N\{s}, where N is the set of all nodes.Set dist(s) = 0 and pred(s) = 0.Set LIST = {s}.while LIST �= ∅ doSet i equal to the first element in LIST .Delete the first element in LIST .for all arcs (i, j) outgoing from node i doif dist(j) > dist(i) + cij thenSet dist(j) = dist(i) + cij .Set pred(j) = i.if j /∈ LIST thenif j has been in in LIST before thenPut j first in LIST .

elsePut j at the end of LIST .

end ifend if

end ifend for

end while

B.16 mintree

Set Z tree = Zin.while the number of arcs in Z tree is less than n− 1 doChoose the arc (i, j) /∈ Z tree ∪ Zin for which Cij = min{Cij : (i, j) /∈ Z tree ∪ Zin}.if the arc (i, j) does not create a cycle with the arcs in Z tree thenAdd the arc (i, j) to Z tree.

end ifSet Cij = Cji = Inf.

end while

B.17 TPmc

Initially set x to a zero matrix of dimension m× n.Set M = max(c) + 1.for k = 1, 2, ...,m+ n− 1 doChoose (i, j) for which i+ j = min{i+ j : cij = min(c)}if si > dj thenSet xij = dj .Set si = si − dj .Set all elements in the j:th column of c equal to M .

elseSet xij = si.Set dj = dj − si.Set all elements in the i:th row of c equal to M .

end ifSet Bk = (i, j).

182

Page 183: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

end for

B.18 TPnw

Initially set x to a zero matrix of dimension m× n.Set i = 1 and j = 1.for k = 1, 2, ...,m+ n− 1 doif si > dj thenSet xij = dj .Set Bk = (i, j).Set si = si − dj .Set j = j + 1.

elseSet xij = si.Set Bk = (i, j).Set dj = dj − si.Set i = i+ 1.

end ifend for

B.19 TPsimplx

ifm∑i

si >n∑j

dj then

Add a dummy demand point with zero cost.

else ifm∑i

si <n∑j

dj then

Add a dummy supply point with high cost.end ifif x and B is not given thenCall TPvogel to get a starting basic feasible solution.

else if only x is given thenSet B to represent the nonzero entries in x.

else if only B is given thenCompute x for the given basis B.

end iffor k = 1, 2, ..., kmax doCompute the simplex multipliers y =

(uv

)by setting vn = 0 and solving the m+ n− 1 equations ui + vj = cij

for (i, j) ∈ B.Compute the reduced costs cij = cij − ui − vj.Set cmin = min(c).if cmin ≥ 0 thenSTOP, x is optimal.

elseSet q = (qi, qj) where cqiqj

= cmin.end ifDetermine the cycle of change vector µ by solving Aµ = b, where A ∈ R

n+m×n+m and b ∈ Rn+m. ABi1,i = 1,

Am+Bi2,i = 1 for i = 1, 2, ...,m+n. Am+n,m+n = 1 and the rest of the entries in A is zero. bqi= −1, bqj

= −1and the rest of the entries in b is zero.Set θ = min

{xBi1,Bi,2 : µi < 0

}.

if θ = ∅ thenSTOP, the problem has an unbounded fesible region.

elseSet p = (pi, pj) where xpipj

= θ.end ifSet xBi1,Bi,2 = xBi1,Bi,2 + θµi.

183

Page 184: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

Set xqiqj= θ.

Set B = B ∪ {q}\{p}.end for

B.20 TPvogel

Initially set x to a zero matrix of dimension m× n.Set k = 1.while k ≤ m+ n− 1 doCompute for each column j a penalty pcj

equal to the difference between the two smallest costs in the column,using entries that do not lie in a crossed-out row or column.if there is a column where only one entry is not crossed-out thenfor j = 1, 2, ..., n doif column j is a column with only one crossed-out entry thenChoose i so that (i, j) corresponds to that entry.if si > dj thenSet xij = dj .Set si = si − dj .

elseSet xij = si.Set dj = dj − si.

end ifSet Bk = (i, j).Set k = k + 1.

end ifend for

elseCompute for each row i a penalty pri

equal to the difference between the two smallest costs in the row,using entries that do not lie in a crossed-out row or column.if there is a row where only one entry is not crossed-out thenfor i = 1, 2, ...,m doif row i is a row with only one crossed-out entry thenChoose j so that (i, j) corresponds to that entry.if si > dj thenSet xij = dj .Set si = si − dj .

elseSet xij = si.Set dj = dj − si.

end ifSet Bk = (i, j).Set k = k + 1.

end ifend for

elseif max(pr) > max(pc) thenSet i = argmax(pr).Choose j so that (i, j) corresponds to the smallest cost in row i of the non crossed-out entries.

elseSet j = argmax(pc).Choose i so that (i, j) corresponds to the smallest cost in column j of the non crossed-out entries.

end ifif si > dj thenSet xij = dj .Set si = si − dj .Cross out column j.

184

Page 185: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

elseSet xij = si.Set dj = dj − si.Cross out row i.

end ifSet Bk = (i, j).Set k = k + 1.

end ifend if

end while

B.21 urelax

Set xj = 0, j = 1, 2, ..., n and ui = −1, i = 1, 2, ...,m− 1.Set Arj = Arj , j = 1, 2, ..., n and b = br.Set Aij = Aij and bi = bi, i ∈ {1, 2, ...,m} − {r}, j = 1, 2, ..., n.Set fP = 0 and xP = x.for k = 0, 1, ..., u max doSet ui = ui + 1, i = 1, 2, ...,m− 1.Set c = ATu.Call the knapsack problem solver dpknap with the parameters A, b, c and xU to get the solution x and fD.Set fD = fD + uT b and compute the subgradient g = b− Ax.if gi ≥ 0, i = 1, 2, ...,m− 1 and cTx > fP thenSet fP = cTx and xP = x.

end ifend for

185

Page 186: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

References

[1] LINGO - The Modeling Language and Optimizer. LINDO Systems Inc., Chicago, IL, 1995.

[2] R. K. Ahuja, T. L. Magnanti, and J. B. Orlin. Network flows. In G. L. Nemhauser, A. H. G. Rinnooy Kan, andM. J. Todd, editors, Optimization, volume 1 of Handbooks in Operations Research and Management Science.Elsevier/North Holland, Amsterdam, The Netherlands, 1989.

[3] R. K. Ahuja, T. L. Magnanti, and J. B. Orlin. Network Flows: Theory, Algorithms and Applications. Prentice-Hall Inc., Kanpur and Cambridge, 1993.

[4] M. Al-Baali and R. Fletcher. Variational methods for non-linear least squares. J. Oper. Res. Soc., 36:405–421,1985.

[5] M. Al-Baali and R. Fletcher. An efficient line search for nonlinear least-squares. Journal of OptimizationTheory and Applications, 48:359–377, 1986.

[6] M. C. Bartholomew-Biggs. Algorithms for general constrained nonlinear optimization. Technical ReportTechnical Report 277, Numerical Optimisation Centre, Mathematics Division, University of Hertfordshire,1993.

[7] Mokhtar S. Bazaraa, John J. Jarvis, and Hanif D. Sherali. Linear Programming and Network Flows. JohnWiley and Sons, New York, 2nd edition, 1990.

[8] J. Bisschop and R. Entriken. AIMMS - The Modeling System. Paragon Decision Technology, Haarlem, TheNetherlands, 1993.

[9] J. Bisschop and A. Meeraus. On the development of a general algebraic modeling system in a strategicplanning environment. Mathematical Programming Study, 20:1–29, 1982.

[10] Mattias Bjorkman. Nonlinear Least Squares with Inequality Constraints. Bachelor Thesis, Department ofMathematics and Physics, Malardalen University, Sweden, 1998. Supervised by K. Holmstrom.

[11] I. Bongartz, A. R. Conn, N. I. M. Gould, and P. L. Toint. CUTE: Constrained and Unconstrained TestingEnvironment. ACM Transactions on Mathematical Software, 21(1):123–160, 1995.

[12] I. Bongartz, A. R. Conn, Nick Gould, and Ph. L. Toint. CUTE: Constrained and Unconstrained TestingEnvironment. Technical report, IBM T. J. Watson Research Center, Yorktown Heights, NY 10598, September2 1997.

[13] Mary Ann Branch and Andy Grace. Optimization Toolbox User’s Guide. 24 Prime Park Way, Natick, MA01760-1500, 1996.

[14] A. Brooke, D. Kendrick, and A. Meeraus. GAMS - A User’s Guide. The Scientific Press, Redwood City, CA,1988.

[15] Thomas Coleman, Mary Ann Branch, and Andy Grace. Optimization Toolbox User’s Guide. 24 Prime ParkWay, Natick, MA 01760-1500, 1999. Third Printing Revised for Version 2 (Release 11).

[16] A. R. Conn, Nick Gould, A. Sartenaer, and Ph. L. Toint. Convergence properties of minimization algorithmsfor convex constraints using a structured trust region. SIAM Journal on Scientific and Statistical Computing,6(4):1059–1086, 1996.

[17] J. J. Dongarra, C. B. Moler, J. R. Bunch, and G. W. Stewart. LINPACK User’s Guide. SIAM, 1979.

[18] Erik Dotzauer and K. Holmstrom. The TOMLAB Graphical User Interface for Nonlinear Programming.Advanced Modeling and Optimization, 1(2):9–16, 1999.

[19] Arne Stolbjerg Drud. Interactions between nonlinear programing and modeling systems. Mathematical Pro-gramming, Series B, 79:99–123, 1997.

[20] S. I. Feldman, David M. Gay, Mark W. Maimone, and N. L. Schryer. A Fortran-to-C converter. TechnicalReport Computing Science Technical Report No. 149, AT&T Bell Laboratories, May 1992.

186

Page 187: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

[21] Marshall L. Fisher. An Application Oriented Guide to Lagrangian Relaxation. Interfaces 15:2, pages 10–21,March-April 1985.

[22] R. Fletcher and C. Xu. Hybrid methods for nonlinear least squares. IMA Journal of Numerical Analysis,7:371–389, 1987.

[23] Roger Fletcher. Practical Methods of Optimization. John Wiley and Sons, New York, 2nd edition, 1987.

[24] Roger Fletcher and Sven Leyffer. Nonlinear programming without a penalty function. Technical ReportNA/171, University of Dundee, 22 September 1997.

[25] R. Fourer, D. M. Gay, and B. W.Kernighan. AMPL - A Modeling Language for Mathematical Programming.The Scientific Press, Redwood City, CA, 1993.

[26] B. S. Garbow, J. M. Boyle, J. J. Dongara, and C. B. Moler. Matrix Eigensystem Routines-EISPACK GuideExtension. In Lecture Notes in Computer Science. Springer Verlag, New York, 1977.

[27] David M. Gay. Hooking your solver to AMPL. Technical report, Bell Laboratories, Lucent Technologies,Murray Hill, NJ 07974, 1997.

[28] P. E. Gill, W. Murray, M. A. Saunders, and M. H. Wright. User’s Guide for NPSOL (Version 4.0): A Fortranpackage for nonlinear programming. Department of Operations Research, Stanford University, Stanford, CA,1986. SOL 86-2.

[29] P. E. Gill, W. Murray, and M. H. Wright. Practical Optimization. Academic Press, London, 1982.

[30] D. Goldfarb and M. J. Todd. Linear programming. In G. L. Nemhauser, A. H. G. Rinnooy Kan, andM. J. Todd, editors, Optimization, volume 1 of Handbooks in Operations Research and Management Science.Elsevier/North Holland, Amsterdam, The Netherlands, 1989.

[31] Jacek Gondzio. Presolve analysis of linear programs prior to applying an interior point method. INFORMSJournal on Computing, 9(1):73–91, 1997.

[32] Michael Held and Richard M. Karp. The Traveling-Salesman problem and minimum spanning trees: Part II.Mathematical Programming, 1:6–25, 1971.

[33] Kaj Holmberg. Heltalsprogrammering och dynamisk programmering och floden i natverk och kombinatoriskoptimering. Technical report, Division of Optimization Theory, Linkoping University, Linkoping, Sweden,1988-1993.

[34] K. Holmstrom. The TOMLAB Optimization Environment in Matlab. Advanced Modeling and Optimization,1(1):47–69, 1999.

[35] K. Holmstrom and Mattias Bjorkman. Global Optimization with Integer and Nonlinear Constraints. AdvancedModeling and Optimization, 1(3), 1999. To be published.

[36] K. Holmstrom and Mattias Bjorkman. The TOMLAB NLPLIB Toolbox for Nonlinear Programming. Ad-vanced Modeling and Optimization, 1(1):70–86, 1999.

[37] K. Holmstrom, Mattias Bjorkman, and Erik Dotzauer. The TOMLAB OPERA Toolbox for Linear andDiscrete Optimization. Advanced Modeling and Optimization, 1(2):1–8, 1999.

[38] J. Huschens. On the use of product structure in secant methods for nonlinear least squares problems. SIAMJournal on Optimization, 4(1):108–129, February 1994.

[39] Kenneth Iverson. A Programming Language. John Wiley and Sons, New York, 1962.

[40] D. R. Jones, C. D. Perttunen, and B. E. Stuckman. Lipschitzian optimization without the Lipschitz constant.Journal of Optimization Theory and Applications, 79(1):157–181, October 1993.

[41] Donald R. Jones. DIRECT. Encyclopedia of Optimization, 2000. To be published.

[42] Donald R. Jones, Matthias Schonlau, and William J. Welch. Efficient global optimization of expensive Black-Box functions. Journal of Global Optimization, 13:455–492, 1998.

187

Page 188: TOMLAB v2.0 User’s Guide -   · PDF fileTOMLAB v2.0 User’s Guide ... M¨alardalenUniversity P.O.Box883,SE-72123V¨aster˚as,Sweden ... the user must also write subroutines

[43] P. Lindstrom. Algorithms for Nonlinear Least Squares - Particularly Problems with Constraints. PhD thesis,Inst. of Information Processing, University of Umea, Sweden, 1983.

[44] David G. Luenberger. Linear and Nonlinear Programming. Addison-Wesley Publishing Company, Reading,Massachusetts, 2nd edition, 1984.

[45] C. B. Moler. MATLAB—An Interactive Matrix Laboratory. Technical Report 369, Department of Mathe-matics and Statistics, University of New Mexico, 1980.

[46] Bruce A. Murtagh and Michael A. Saunders. MINOS 5.4 USER’S GUIDE. Technical Report SOL 83-20R, Revised Feb. 1995, Systems Optimization Laboratory, Department of Operations Research, StanfordUniversity, Stanford, California 94305-4022, 1995.

[47] G. L. Nemhauser and L. A. Wolsey. Integer programming. In G. L. Nemhauser, A. H. G. Rinnooy Kan, andM. J. Todd, editors, Optimization, volume 1 of Handbooks in Operations Research and Management Science.Elsevier/North Holland, Amsterdam, The Netherlands, 1989.

[48] P. C. Piela, T. G. Epperly, K. M. Westerberg, and A. W. Westerberg. ASCEND: An object-oriented computerenvironment for modeling and analysis: The modeling language. Computers and Chemical Engineering, 15:53–72, 1991.

[49] Raymond P. Polivka and Sandra Pakin. APL: The Language and Its Usage. Prentice Hall, Englewood Cliffs,N. J., 1975.

[50] Franco P. Preparata and Michael Ian Shamos. Computational Geometry. Springer-Verlag, New York, 1985.

[51] A. Sartenaer. Automatic determination of an initial trust region in nonlinear programming. Technical Report95/4, Department of Mathematics, Facultes Universitaires ND de la Paix, Bruxelles, Belgium, 1995.

[52] K. Schittkowski. On the Convergence of a Sequential Quadratic Programming Method with an AugmentedLagrangian Line Search Function. Technical report, Systems Optimization laboratory, Stanford University,Stanford, CA, 1982.

[53] B. T. Smith, J. M. Boyle, J. J. Dongarra, B. S. Garbow, Y. Ikebe, V. C. Klema, and C. B. Moler. MatrixEigensystem Routines - EISPACK Guide Lecture Notes in Computer Science. Springer-Verlag, New York,2nd edition, 1976.

[54] William Squire and George Trapp. Using complex variables to estimate derivatives of real functions. SIAMReview, 40(1):100–112, March 1998.

[55] Wayne L. Winston. Operations Research: Applications and Algorithms. International Thomson Publishing,Duxbury Press, Belmont, California, 3rd edition, 1994.

188