Mercurial > hg > octave-nkf
annotate scripts/optimization/sqp.m @ 19047:7bbe3658c5ef
maint: Use "FIXME:" coding convention in m-files.
* flipdim.m, prepad.m, rotdim.m, doc.m, strread.m, textread.m, krylov.m,
colon.m, dump_prefs.m, fileattrib.m, getappdata.m, __xzip__.m, unpack.m,
fsolve.m, axis.m, meshc.m, print.m, __ghostscript__.m, __go_draw_axes__.m,
__print_parse_opts__.m, struct2hdl.m, unique.m, spstats.m, treeplot.m, test.m,
datestr.m: Use "FIXME:" coding convention in m-files.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 25 Jun 2014 13:45:41 -0700 |
parents | f58a6cd3f909 |
children | 0e1f5a750d00 |
rev | line source |
---|---|
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
17338
diff
changeset
|
1 ## Copyright (C) 2005-2013 John W. Eaton |
18280
f58a6cd3f909
sqp.m: Fix return values in sqp (bug #32008).
Arun Giridhar <arungiridhar@gmail.com>
parents:
17744
diff
changeset
|
2 ## Copyright (C) 2013 Arun Giridhar |
5289 | 3 ## |
4 ## This file is part of Octave. | |
5 ## | |
6 ## Octave is free software; you can redistribute it and/or modify it | |
7 ## under the terms of the GNU General Public License as published by | |
7016 | 8 ## the Free Software Foundation; either version 3 of the License, or (at |
9 ## your option) any later version. | |
5289 | 10 ## |
11 ## Octave is distributed in the hope that it will be useful, but | |
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 ## General Public License for more details. | |
15 ## | |
16 ## You should have received a copy of the GNU General Public License | |
7016 | 17 ## along with Octave; see the file COPYING. If not, see |
18 ## <http://www.gnu.org/licenses/>. | |
5289 | 19 |
20 ## -*- texinfo -*- | |
11348
2ae0ca4ee36b
sqp.m: Change docstring to refer to x0 as the initial seed vector
Rik <octave@nomad.inbox5.com>
parents:
11347
diff
changeset
|
21 ## @deftypefn {Function File} {[@var{x}, @var{obj}, @var{info}, @var{iter}, @var{nf}, @var{lambda}] =} sqp (@var{x0}, @var{phi}) |
2ae0ca4ee36b
sqp.m: Change docstring to refer to x0 as the initial seed vector
Rik <octave@nomad.inbox5.com>
parents:
11347
diff
changeset
|
22 ## @deftypefnx {Function File} {[@dots{}] =} sqp (@var{x0}, @var{phi}, @var{g}) |
2ae0ca4ee36b
sqp.m: Change docstring to refer to x0 as the initial seed vector
Rik <octave@nomad.inbox5.com>
parents:
11347
diff
changeset
|
23 ## @deftypefnx {Function File} {[@dots{}] =} sqp (@var{x0}, @var{phi}, @var{g}, @var{h}) |
2ae0ca4ee36b
sqp.m: Change docstring to refer to x0 as the initial seed vector
Rik <octave@nomad.inbox5.com>
parents:
11347
diff
changeset
|
24 ## @deftypefnx {Function File} {[@dots{}] =} sqp (@var{x0}, @var{phi}, @var{g}, @var{h}, @var{lb}, @var{ub}) |
2ae0ca4ee36b
sqp.m: Change docstring to refer to x0 as the initial seed vector
Rik <octave@nomad.inbox5.com>
parents:
11347
diff
changeset
|
25 ## @deftypefnx {Function File} {[@dots{}] =} sqp (@var{x0}, @var{phi}, @var{g}, @var{h}, @var{lb}, @var{ub}, @var{maxiter}) |
13207
88bd1d1d6657
Reword sqp's docstring
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11587
diff
changeset
|
26 ## @deftypefnx {Function File} {[@dots{}] =} sqp (@var{x0}, @var{phi}, @var{g}, @var{h}, @var{lb}, @var{ub}, @var{maxiter}, @var{tol}) |
5289 | 27 ## Solve the nonlinear program |
6741 | 28 ## @tex |
29 ## $$ | |
30 ## \min_x \phi (x) | |
31 ## $$ | |
32 ## @end tex | |
33 ## @ifnottex | |
5289 | 34 ## |
35 ## @example | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
36 ## @group |
14327
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
37 ## min phi (x) |
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
38 ## x |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
39 ## @end group |
5289 | 40 ## @end example |
41 ## | |
6741 | 42 ## @end ifnottex |
43 ## subject to | |
5289 | 44 ## @tex |
6741 | 45 ## $$ |
8167
17352ccd860e
describe additional arguments in sqp() documentation string
Ivan Sutoris <ivan.sutoris@gmail.com>
parents:
8047
diff
changeset
|
46 ## g(x) = 0 \qquad h(x) \geq 0 \qquad lb \leq x \leq ub |
6741 | 47 ## $$ |
5289 | 48 ## @end tex |
6741 | 49 ## @ifnottex |
5289 | 50 ## |
51 ## @example | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
52 ## @group |
14327
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
53 ## g(x) = 0 |
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
54 ## h(x) >= 0 |
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
55 ## lb <= x <= ub |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
56 ## @end group |
5289 | 57 ## @end example |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10678
diff
changeset
|
58 ## |
6741 | 59 ## @end ifnottex |
5289 | 60 ## @noindent |
11348
2ae0ca4ee36b
sqp.m: Change docstring to refer to x0 as the initial seed vector
Rik <octave@nomad.inbox5.com>
parents:
11347
diff
changeset
|
61 ## using a sequential quadratic programming method. |
5289 | 62 ## |
11348
2ae0ca4ee36b
sqp.m: Change docstring to refer to x0 as the initial seed vector
Rik <octave@nomad.inbox5.com>
parents:
11347
diff
changeset
|
63 ## The first argument is the initial guess for the vector @var{x0}. |
5289 | 64 ## |
7001 | 65 ## The second argument is a function handle pointing to the objective |
13207
88bd1d1d6657
Reword sqp's docstring
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11587
diff
changeset
|
66 ## function @var{phi}. The objective function must accept one vector |
88bd1d1d6657
Reword sqp's docstring
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11587
diff
changeset
|
67 ## argument and return a scalar. |
5289 | 68 ## |
69 ## The second argument may also be a 2- or 3-element cell array of | |
70 ## function handles. The first element should point to the objective | |
71 ## function, the second should point to a function that computes the | |
72 ## gradient of the objective function, and the third should point to a | |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
73 ## function that computes the Hessian of the objective function. If the |
5289 | 74 ## gradient function is not supplied, the gradient is computed by finite |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
75 ## differences. If the Hessian function is not supplied, a BFGS update |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
76 ## formula is used to approximate the Hessian. |
5289 | 77 ## |
13207
88bd1d1d6657
Reword sqp's docstring
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11587
diff
changeset
|
78 ## When supplied, the gradient function @code{@var{phi}@{2@}} must accept |
13931
9de488c6c59c
doc: Spellcheck documentation before 3.6.0 release
Rik <octave@nomad.inbox5.com>
parents:
13929
diff
changeset
|
79 ## one vector argument and return a vector. When supplied, the Hessian |
13207
88bd1d1d6657
Reword sqp's docstring
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11587
diff
changeset
|
80 ## function @code{@var{phi}@{3@}} must accept one vector argument and |
88bd1d1d6657
Reword sqp's docstring
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11587
diff
changeset
|
81 ## return a matrix. |
5289 | 82 ## |
13207
88bd1d1d6657
Reword sqp's docstring
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11587
diff
changeset
|
83 ## The third and fourth arguments @var{g} and @var{h} are function |
88bd1d1d6657
Reword sqp's docstring
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11587
diff
changeset
|
84 ## handles pointing to functions that compute the equality constraints |
88bd1d1d6657
Reword sqp's docstring
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11587
diff
changeset
|
85 ## and the inequality constraints, respectively. If the problem does |
88bd1d1d6657
Reword sqp's docstring
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11587
diff
changeset
|
86 ## not have equality (or inequality) constraints, then use an empty |
13929
9cae456085c2
Grammarcheck of documentation before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
13305
diff
changeset
|
87 ## matrix ([]) for @var{g} (or @var{h}). When supplied, these equality |
13207
88bd1d1d6657
Reword sqp's docstring
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11587
diff
changeset
|
88 ## and inequality constraint functions must accept one vector argument |
88bd1d1d6657
Reword sqp's docstring
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11587
diff
changeset
|
89 ## and return a vector. |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
90 ## |
5289 | 91 ## The third and fourth arguments may also be 2-element cell arrays of |
92 ## function handles. The first element should point to the constraint | |
93 ## function and the second should point to a function that computes the | |
94 ## gradient of the constraint function: | |
6741 | 95 ## @tex |
96 ## $$ | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
97 ## \Bigg( {\partial f(x) \over \partial x_1}, |
6741 | 98 ## {\partial f(x) \over \partial x_2}, \ldots, |
99 ## {\partial f(x) \over \partial x_N} \Bigg)^T | |
100 ## $$ | |
101 ## @end tex | |
102 ## @ifnottex | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10678
diff
changeset
|
103 ## |
5289 | 104 ## @example |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
105 ## @group |
14327
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
106 ## [ d f(x) d f(x) d f(x) ] |
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
107 ## transpose ( [ ------ ----- ... ------ ] ) |
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
108 ## [ dx_1 dx_2 dx_N ] |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
109 ## @end group |
5289 | 110 ## @end example |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10678
diff
changeset
|
111 ## |
6741 | 112 ## @end ifnottex |
13207
88bd1d1d6657
Reword sqp's docstring
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11587
diff
changeset
|
113 ## The fifth and sixth arguments, @var{lb} and @var{ub}, contain lower |
88bd1d1d6657
Reword sqp's docstring
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11587
diff
changeset
|
114 ## and upper bounds on @var{x}. These must be consistent with the |
88bd1d1d6657
Reword sqp's docstring
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11587
diff
changeset
|
115 ## equality and inequality constraints @var{g} and @var{h}. If the |
88bd1d1d6657
Reword sqp's docstring
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11587
diff
changeset
|
116 ## arguments are vectors then @var{x}(i) is bound by @var{lb}(i) and |
13929
9cae456085c2
Grammarcheck of documentation before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
13305
diff
changeset
|
117 ## @var{ub}(i). A bound can also be a scalar in which case all elements |
13207
88bd1d1d6657
Reword sqp's docstring
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11587
diff
changeset
|
118 ## of @var{x} will share the same bound. If only one bound (lb, ub) is |
88bd1d1d6657
Reword sqp's docstring
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11587
diff
changeset
|
119 ## specified then the other will default to (-@var{realmax}, |
88bd1d1d6657
Reword sqp's docstring
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11587
diff
changeset
|
120 ## +@var{realmax}). |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
121 ## |
13207
88bd1d1d6657
Reword sqp's docstring
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11587
diff
changeset
|
122 ## The seventh argument @var{maxiter} specifies the maximum number of |
13929
9cae456085c2
Grammarcheck of documentation before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
13305
diff
changeset
|
123 ## iterations. The default value is 100. |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
124 ## |
13207
88bd1d1d6657
Reword sqp's docstring
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11587
diff
changeset
|
125 ## The eighth argument @var{tol} specifies the tolerance for the |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14595
diff
changeset
|
126 ## stopping criteria. The default value is @code{sqrt (eps)}. |
8167
17352ccd860e
describe additional arguments in sqp() documentation string
Ivan Sutoris <ivan.sutoris@gmail.com>
parents:
8047
diff
changeset
|
127 ## |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
128 ## The value returned in @var{info} may be one of the following: |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10678
diff
changeset
|
129 ## |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
130 ## @table @asis |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
131 ## @item 101 |
18280
f58a6cd3f909
sqp.m: Fix return values in sqp (bug #32008).
Arun Giridhar <arungiridhar@gmail.com>
parents:
17744
diff
changeset
|
132 ## The algorithm terminated normally. |
f58a6cd3f909
sqp.m: Fix return values in sqp (bug #32008).
Arun Giridhar <arungiridhar@gmail.com>
parents:
17744
diff
changeset
|
133 ## All constraints meet the specified tolerance. |
f58a6cd3f909
sqp.m: Fix return values in sqp (bug #32008).
Arun Giridhar <arungiridhar@gmail.com>
parents:
17744
diff
changeset
|
134 ## |
f58a6cd3f909
sqp.m: Fix return values in sqp (bug #32008).
Arun Giridhar <arungiridhar@gmail.com>
parents:
17744
diff
changeset
|
135 ## @item 102 |
f58a6cd3f909
sqp.m: Fix return values in sqp (bug #32008).
Arun Giridhar <arungiridhar@gmail.com>
parents:
17744
diff
changeset
|
136 ## The BFGS update failed. |
f58a6cd3f909
sqp.m: Fix return values in sqp (bug #32008).
Arun Giridhar <arungiridhar@gmail.com>
parents:
17744
diff
changeset
|
137 ## |
f58a6cd3f909
sqp.m: Fix return values in sqp (bug #32008).
Arun Giridhar <arungiridhar@gmail.com>
parents:
17744
diff
changeset
|
138 ## @item 103 |
f58a6cd3f909
sqp.m: Fix return values in sqp (bug #32008).
Arun Giridhar <arungiridhar@gmail.com>
parents:
17744
diff
changeset
|
139 ## The maximum number of iterations was reached. |
f58a6cd3f909
sqp.m: Fix return values in sqp (bug #32008).
Arun Giridhar <arungiridhar@gmail.com>
parents:
17744
diff
changeset
|
140 ## |
f58a6cd3f909
sqp.m: Fix return values in sqp (bug #32008).
Arun Giridhar <arungiridhar@gmail.com>
parents:
17744
diff
changeset
|
141 ## @item 104 |
f58a6cd3f909
sqp.m: Fix return values in sqp (bug #32008).
Arun Giridhar <arungiridhar@gmail.com>
parents:
17744
diff
changeset
|
142 ## The stepsize has become too small, i.e., |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
143 ## @tex |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
144 ## $\Delta x,$ |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
145 ## @end tex |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
146 ## @ifnottex |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
147 ## delta @var{x}, |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
148 ## @end ifnottex |
13207
88bd1d1d6657
Reword sqp's docstring
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11587
diff
changeset
|
149 ## is less than @code{@var{tol} * norm (x)}. |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
150 ## @end table |
8167
17352ccd860e
describe additional arguments in sqp() documentation string
Ivan Sutoris <ivan.sutoris@gmail.com>
parents:
8047
diff
changeset
|
151 ## |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
152 ## An example of calling @code{sqp}: |
5289 | 153 ## |
154 ## @example | |
7031 | 155 ## function r = g (x) |
156 ## r = [ sumsq(x)-10; | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
157 ## x(2)*x(3)-5*x(4)*x(5); |
7031 | 158 ## x(1)^3+x(2)^3+1 ]; |
159 ## endfunction | |
160 ## | |
161 ## function obj = phi (x) | |
14327
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
162 ## obj = exp (prod (x)) - 0.5*(x(1)^3+x(2)^3+1)^2; |
7031 | 163 ## endfunction |
5289 | 164 ## |
7031 | 165 ## x0 = [-1.8; 1.7; 1.9; -0.8; -0.8]; |
166 ## | |
167 ## [x, obj, info, iter, nf, lambda] = sqp (x0, @@phi, @@g, []) | |
5289 | 168 ## |
7031 | 169 ## x = |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
170 ## |
7031 | 171 ## -1.71714 |
172 ## 1.59571 | |
173 ## 1.82725 | |
174 ## -0.76364 | |
175 ## -0.76364 | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
176 ## |
7031 | 177 ## obj = 0.053950 |
178 ## info = 101 | |
179 ## iter = 8 | |
180 ## nf = 10 | |
181 ## lambda = | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
182 ## |
7031 | 183 ## -0.0401627 |
184 ## 0.0379578 | |
185 ## -0.0052227 | |
5289 | 186 ## @end example |
187 ## | |
5642 | 188 ## @seealso{qp} |
5289 | 189 ## @end deftypefn |
190 | |
11348
2ae0ca4ee36b
sqp.m: Change docstring to refer to x0 as the initial seed vector
Rik <octave@nomad.inbox5.com>
parents:
11347
diff
changeset
|
191 function [x, obj, info, iter, nf, lambda] = sqp (x0, objf, cef, cif, lb, ub, maxiter, tolerance) |
5289 | 192 |
17336
b81b9d079515
Use '##' for comments which stand alone on a line.
Rik <rik@octave.org>
parents:
17245
diff
changeset
|
193 globals = struct (); # data and handles, needed and changed by subfunctions |
5289 | 194 |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
195 if (nargin < 2 || nargin > 8 || nargin == 5) |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
196 print_usage (); |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
197 endif |
5289 | 198 |
11348
2ae0ca4ee36b
sqp.m: Change docstring to refer to x0 as the initial seed vector
Rik <octave@nomad.inbox5.com>
parents:
11347
diff
changeset
|
199 if (!isvector (x0)) |
2ae0ca4ee36b
sqp.m: Change docstring to refer to x0 as the initial seed vector
Rik <octave@nomad.inbox5.com>
parents:
11347
diff
changeset
|
200 error ("sqp: X0 must be a vector"); |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
201 endif |
11348
2ae0ca4ee36b
sqp.m: Change docstring to refer to x0 as the initial seed vector
Rik <octave@nomad.inbox5.com>
parents:
11347
diff
changeset
|
202 if (rows (x0) == 1) |
2ae0ca4ee36b
sqp.m: Change docstring to refer to x0 as the initial seed vector
Rik <octave@nomad.inbox5.com>
parents:
11347
diff
changeset
|
203 x0 = x0'; |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
204 endif |
5289 | 205 |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
206 have_hess = 0; |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
207 if (iscell (objf)) |
11120
a44f979a35ce
style fixes for some .m files
John W. Eaton <jwe@octave.org>
parents:
10821
diff
changeset
|
208 switch (numel (objf)) |
17174
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
209 case 1 |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
210 obj_fun = objf{1}; |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
211 obj_grd = @ (x) fd_obj_grd (x, obj_fun); |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
212 case 2 |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
213 obj_fun = objf{1}; |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
214 obj_grd = objf{2}; |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
215 case 3 |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
216 obj_fun = objf{1}; |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
217 obj_grd = objf{2}; |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
218 obj_hess = objf{3}; |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
219 have_hess = 1; |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
220 otherwise |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
221 error ("sqp: invalid objective function specification"); |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
222 endswitch |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
223 else |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
224 obj_fun = objf; # No cell array, only obj_fun set |
14595
11a9d448fdc3
Get rid of global variables in sqp.
Olaf Till <i7tiol@t-online.de>
parents:
14552
diff
changeset
|
225 obj_grd = @ (x) fd_obj_grd (x, obj_fun); |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
226 endif |
5289 | 227 |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
228 ce_fun = @empty_cf; |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
229 ce_grd = @empty_jac; |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
230 if (nargin > 2) |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
231 if (iscell (cef)) |
11120
a44f979a35ce
style fixes for some .m files
John W. Eaton <jwe@octave.org>
parents:
10821
diff
changeset
|
232 switch (numel (cef)) |
17174
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
233 case 1 |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
234 ce_fun = cef{1}; |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
235 ce_grd = @ (x) fd_ce_jac (x, ce_fun); |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
236 case 2 |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
237 ce_fun = cef{1}; |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
238 ce_grd = cef{2}; |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
239 otherwise |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
240 error ("sqp: invalid equality constraint function specification"); |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
241 endswitch |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
242 elseif (! isempty (cef)) |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
243 ce_fun = cef; # No cell array, only constraint equality function set |
14595
11a9d448fdc3
Get rid of global variables in sqp.
Olaf Till <i7tiol@t-online.de>
parents:
14552
diff
changeset
|
244 ce_grd = @ (x) fd_ce_jac (x, ce_fun); |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
245 endif |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
246 endif |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
247 |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
248 ci_fun = @empty_cf; |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
249 ci_grd = @empty_jac; |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
250 if (nargin > 3) |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
251 ## constraint function given by user with possible gradient |
14595
11a9d448fdc3
Get rid of global variables in sqp.
Olaf Till <i7tiol@t-online.de>
parents:
14552
diff
changeset
|
252 globals.cif = cif; |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
253 ## constraint function given by user without gradient |
14595
11a9d448fdc3
Get rid of global variables in sqp.
Olaf Till <i7tiol@t-online.de>
parents:
14552
diff
changeset
|
254 globals.cifcn = @empty_cf; |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
255 if (iscell (cif)) |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
256 if (length (cif) > 0) |
14595
11a9d448fdc3
Get rid of global variables in sqp.
Olaf Till <i7tiol@t-online.de>
parents:
14552
diff
changeset
|
257 globals.cifcn = cif{1}; |
5289 | 258 endif |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
259 elseif (! isempty (cif)) |
14595
11a9d448fdc3
Get rid of global variables in sqp.
Olaf Till <i7tiol@t-online.de>
parents:
14552
diff
changeset
|
260 globals.cifcn = cif; |
5289 | 261 endif |
262 | |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
263 if (nargin < 5 || (nargin > 5 && isempty (lb) && isempty (ub))) |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
264 ## constraint inequality function only without any bounds |
14595
11a9d448fdc3
Get rid of global variables in sqp.
Olaf Till <i7tiol@t-online.de>
parents:
14552
diff
changeset
|
265 ci_grd = @ (x) fd_ci_jac (x, globals.cifcn); |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
266 if (iscell (cif)) |
16933
e39f00a32dc7
maint: Use parentheses around condition for switch(),while(),if() statements.
Rik <rik@octave.org>
parents:
16064
diff
changeset
|
267 switch (length (cif)) |
17174
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
268 case 1 |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
269 ci_fun = cif{1}; |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
270 case 2 |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
271 ci_fun = cif{1}; |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
272 ci_grd = cif{2}; |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
273 otherwise |
c3c1ebfaa7dc
maint: Use common indentation for switch statement.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
274 error ("sqp: invalid inequality constraint function specification"); |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
275 endswitch |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
276 elseif (! isempty (cif)) |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
277 ci_fun = cif; # No cell array, only constraint inequality function set |
5289 | 278 endif |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
279 else |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
280 ## constraint inequality function with bounds present |
11348
2ae0ca4ee36b
sqp.m: Change docstring to refer to x0 as the initial seed vector
Rik <octave@nomad.inbox5.com>
parents:
11347
diff
changeset
|
281 lb_idx = ub_idx = true (size (x0)); |
2ae0ca4ee36b
sqp.m: Change docstring to refer to x0 as the initial seed vector
Rik <octave@nomad.inbox5.com>
parents:
11347
diff
changeset
|
282 ub_grad = - (lb_grad = eye (rows (x0))); |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
283 if (isvector (lb)) |
14595
11a9d448fdc3
Get rid of global variables in sqp.
Olaf Till <i7tiol@t-online.de>
parents:
14552
diff
changeset
|
284 globals.lb = tmp_lb = lb(:); |
11347
2726132f77f6
sqp.m: Remove never violated Inf bounds from computation (bug #31742)
Rik <octave@nomad.inbox5.com>
parents:
11290
diff
changeset
|
285 lb_idx(:) = tmp_idx = (lb != -Inf); |
14595
11a9d448fdc3
Get rid of global variables in sqp.
Olaf Till <i7tiol@t-online.de>
parents:
14552
diff
changeset
|
286 globals.lb = globals.lb(tmp_idx, 1); |
11347
2726132f77f6
sqp.m: Remove never violated Inf bounds from computation (bug #31742)
Rik <octave@nomad.inbox5.com>
parents:
11290
diff
changeset
|
287 lb_grad = lb_grad(lb_idx, :); |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
288 elseif (isempty (lb)) |
11348
2ae0ca4ee36b
sqp.m: Change docstring to refer to x0 as the initial seed vector
Rik <octave@nomad.inbox5.com>
parents:
11347
diff
changeset
|
289 if (isa (x0, "single")) |
14595
11a9d448fdc3
Get rid of global variables in sqp.
Olaf Till <i7tiol@t-online.de>
parents:
14552
diff
changeset
|
290 globals.lb = tmp_lb = -realmax ("single"); |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
291 else |
14595
11a9d448fdc3
Get rid of global variables in sqp.
Olaf Till <i7tiol@t-online.de>
parents:
14552
diff
changeset
|
292 globals.lb = tmp_lb = -realmax; |
10549 | 293 endif |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
294 else |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
295 error ("sqp: invalid lower bound"); |
6768 | 296 endif |
297 | |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
298 if (isvector (ub)) |
14595
11a9d448fdc3
Get rid of global variables in sqp.
Olaf Till <i7tiol@t-online.de>
parents:
14552
diff
changeset
|
299 globals.ub = tmp_ub = ub(:); |
11347
2726132f77f6
sqp.m: Remove never violated Inf bounds from computation (bug #31742)
Rik <octave@nomad.inbox5.com>
parents:
11290
diff
changeset
|
300 ub_idx(:) = tmp_idx = (ub != Inf); |
14595
11a9d448fdc3
Get rid of global variables in sqp.
Olaf Till <i7tiol@t-online.de>
parents:
14552
diff
changeset
|
301 globals.ub = globals.ub(tmp_idx, 1); |
11347
2726132f77f6
sqp.m: Remove never violated Inf bounds from computation (bug #31742)
Rik <octave@nomad.inbox5.com>
parents:
11290
diff
changeset
|
302 ub_grad = ub_grad(ub_idx, :); |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
303 elseif (isempty (ub)) |
11348
2ae0ca4ee36b
sqp.m: Change docstring to refer to x0 as the initial seed vector
Rik <octave@nomad.inbox5.com>
parents:
11347
diff
changeset
|
304 if (isa (x0, "single")) |
14595
11a9d448fdc3
Get rid of global variables in sqp.
Olaf Till <i7tiol@t-online.de>
parents:
14552
diff
changeset
|
305 globals.ub = tmp_ub = realmax ("single"); |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
306 else |
14595
11a9d448fdc3
Get rid of global variables in sqp.
Olaf Till <i7tiol@t-online.de>
parents:
14552
diff
changeset
|
307 globals.ub = tmp_ub = realmax; |
10549 | 308 endif |
6768 | 309 else |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
310 error ("sqp: invalid upper bound"); |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
311 endif |
6768 | 312 |
11347
2726132f77f6
sqp.m: Remove never violated Inf bounds from computation (bug #31742)
Rik <octave@nomad.inbox5.com>
parents:
11290
diff
changeset
|
313 if (any (tmp_lb > tmp_ub)) |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
314 error ("sqp: upper bound smaller than lower bound"); |
6768 | 315 endif |
11347
2726132f77f6
sqp.m: Remove never violated Inf bounds from computation (bug #31742)
Rik <octave@nomad.inbox5.com>
parents:
11290
diff
changeset
|
316 bounds_grad = [lb_grad; ub_grad]; |
14595
11a9d448fdc3
Get rid of global variables in sqp.
Olaf Till <i7tiol@t-online.de>
parents:
14552
diff
changeset
|
317 ci_fun = @ (x) cf_ub_lb (x, lb_idx, ub_idx, globals); |
11a9d448fdc3
Get rid of global variables in sqp.
Olaf Till <i7tiol@t-online.de>
parents:
14552
diff
changeset
|
318 ci_grd = @ (x) cigrad_ub_lb (x, bounds_grad, globals); |
6768 | 319 endif |
5289 | 320 |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
321 endif # if (nargin > 3) |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
322 |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
323 iter_max = 100; |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
324 if (nargin > 6 && ! isempty (maxiter)) |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
325 if (isscalar (maxiter) && maxiter > 0 && fix (maxiter) == maxiter) |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
326 iter_max = maxiter; |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
327 else |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
328 error ("sqp: invalid number of maximum iterations"); |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
329 endif |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
330 endif |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
331 |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
332 tol = sqrt (eps); |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
333 if (nargin > 7 && ! isempty (tolerance)) |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
334 if (isscalar (tolerance) && tolerance > 0) |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
335 tol = tolerance; |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
336 else |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
11371
diff
changeset
|
337 error ("sqp: invalid value for TOLERANCE"); |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
338 endif |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
339 endif |
5289 | 340 |
11348
2ae0ca4ee36b
sqp.m: Change docstring to refer to x0 as the initial seed vector
Rik <octave@nomad.inbox5.com>
parents:
11347
diff
changeset
|
341 ## Initialize variables for search loop |
2ae0ca4ee36b
sqp.m: Change docstring to refer to x0 as the initial seed vector
Rik <octave@nomad.inbox5.com>
parents:
11347
diff
changeset
|
342 ## Seed x with initial guess and evaluate objective function, constraints, |
2ae0ca4ee36b
sqp.m: Change docstring to refer to x0 as the initial seed vector
Rik <octave@nomad.inbox5.com>
parents:
11347
diff
changeset
|
343 ## and gradients at initial value x0. |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
344 ## |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
345 ## obj_fun -- objective function |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
346 ## obj_grad -- objective gradient |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
347 ## ce_fun -- equality constraint functions |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
348 ## ci_fun -- inequality constraint functions |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
349 ## A == [grad_{x_1} cx_fun, grad_{x_2} cx_fun, ..., grad_{x_n} cx_fun]^T |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
350 x = x0; |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
351 |
11348
2ae0ca4ee36b
sqp.m: Change docstring to refer to x0 as the initial seed vector
Rik <octave@nomad.inbox5.com>
parents:
11347
diff
changeset
|
352 obj = feval (obj_fun, x0); |
14595
11a9d448fdc3
Get rid of global variables in sqp.
Olaf Till <i7tiol@t-online.de>
parents:
14552
diff
changeset
|
353 globals.nfun = 1; |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
354 |
11348
2ae0ca4ee36b
sqp.m: Change docstring to refer to x0 as the initial seed vector
Rik <octave@nomad.inbox5.com>
parents:
11347
diff
changeset
|
355 c = feval (obj_grd, x0); |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
356 |
11348
2ae0ca4ee36b
sqp.m: Change docstring to refer to x0 as the initial seed vector
Rik <octave@nomad.inbox5.com>
parents:
11347
diff
changeset
|
357 ## Choose an initial NxN symmetric positive definite Hessian approximation B. |
2ae0ca4ee36b
sqp.m: Change docstring to refer to x0 as the initial seed vector
Rik <octave@nomad.inbox5.com>
parents:
11347
diff
changeset
|
358 n = length (x0); |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
359 if (have_hess) |
11348
2ae0ca4ee36b
sqp.m: Change docstring to refer to x0 as the initial seed vector
Rik <octave@nomad.inbox5.com>
parents:
11347
diff
changeset
|
360 B = feval (obj_hess, x0); |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
361 else |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
362 B = eye (n, n); |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
363 endif |
5289 | 364 |
11348
2ae0ca4ee36b
sqp.m: Change docstring to refer to x0 as the initial seed vector
Rik <octave@nomad.inbox5.com>
parents:
11347
diff
changeset
|
365 ce = feval (ce_fun, x0); |
2ae0ca4ee36b
sqp.m: Change docstring to refer to x0 as the initial seed vector
Rik <octave@nomad.inbox5.com>
parents:
11347
diff
changeset
|
366 F = feval (ce_grd, x0); |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
367 |
11348
2ae0ca4ee36b
sqp.m: Change docstring to refer to x0 as the initial seed vector
Rik <octave@nomad.inbox5.com>
parents:
11347
diff
changeset
|
368 ci = feval (ci_fun, x0); |
2ae0ca4ee36b
sqp.m: Change docstring to refer to x0 as the initial seed vector
Rik <octave@nomad.inbox5.com>
parents:
11347
diff
changeset
|
369 C = feval (ci_grd, x0); |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
370 |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
371 A = [F; C]; |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
372 |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
373 ## Choose an initial lambda (x is provided by the caller). |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
374 lambda = 100 * ones (rows (A), 1); |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
375 |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
376 qp_iter = 1; |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
377 alpha = 1; |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
378 |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
379 info = 0; |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
380 iter = 0; |
11348
2ae0ca4ee36b
sqp.m: Change docstring to refer to x0 as the initial seed vector
Rik <octave@nomad.inbox5.com>
parents:
11347
diff
changeset
|
381 # report (); # Called with no arguments to initialize reporting |
2ae0ca4ee36b
sqp.m: Change docstring to refer to x0 as the initial seed vector
Rik <octave@nomad.inbox5.com>
parents:
11347
diff
changeset
|
382 # report (iter, qp_iter, alpha, __sqp_nfun__, obj); |
5289 | 383 |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
384 while (++iter < iter_max) |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
385 |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
386 ## Check convergence. This is just a simple check on the first |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
387 ## order necessary conditions. |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
388 nr_f = rows (F); |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
389 |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
390 lambda_e = lambda((1:nr_f)'); |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
391 lambda_i = lambda((nr_f+1:end)'); |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
392 |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
393 con = [ce; ci]; |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
394 |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
395 t0 = norm (c - A' * lambda); |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
396 t1 = norm (ce); |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
397 t2 = all (ci >= 0); |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
398 t3 = all (lambda_i >= 0); |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
399 t4 = norm (lambda .* con); |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
400 |
18280
f58a6cd3f909
sqp.m: Fix return values in sqp (bug #32008).
Arun Giridhar <arungiridhar@gmail.com>
parents:
17744
diff
changeset
|
401 ## Normal convergence. All constraints are satisfied |
f58a6cd3f909
sqp.m: Fix return values in sqp (bug #32008).
Arun Giridhar <arungiridhar@gmail.com>
parents:
17744
diff
changeset
|
402 ## and objective has converged. |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
403 if (t2 && t3 && max ([t0; t1; t4]) < tol) |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
404 info = 101; |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
405 break; |
6382 | 406 endif |
407 | |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
408 ## Compute search direction p by solving QP. |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
409 g = -ce; |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
410 d = -ci; |
5289 | 411 |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
412 [p, obj_qp, INFO, lambda] = qp (x, B, c, F, g, [], [], d, C, |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
413 Inf (size (d))); |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
414 |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
415 info = INFO.info; |
5289 | 416 |
18280
f58a6cd3f909
sqp.m: Fix return values in sqp (bug #32008).
Arun Giridhar <arungiridhar@gmail.com>
parents:
17744
diff
changeset
|
417 ## FIXME: check QP solution and attempt to recover if it has failed. |
f58a6cd3f909
sqp.m: Fix return values in sqp (bug #32008).
Arun Giridhar <arungiridhar@gmail.com>
parents:
17744
diff
changeset
|
418 ## For now, just warn about possible problems. |
13206
658aa9fd8665
sqp: provide warnings for QP subproblem failures
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
419 |
658aa9fd8665
sqp: provide warnings for QP subproblem failures
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
420 id = "Octave:SQP-QP-subproblem"; |
658aa9fd8665
sqp: provide warnings for QP subproblem failures
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
421 switch (info) |
658aa9fd8665
sqp: provide warnings for QP subproblem failures
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
422 case 2 |
658aa9fd8665
sqp: provide warnings for QP subproblem failures
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
423 warning (id, "sqp: QP subproblem is non-convex and unbounded"); |
658aa9fd8665
sqp: provide warnings for QP subproblem failures
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
424 case 3 |
658aa9fd8665
sqp: provide warnings for QP subproblem failures
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
425 warning (id, "sqp: QP subproblem failed to converge in %d iterations", |
658aa9fd8665
sqp: provide warnings for QP subproblem failures
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
426 INFO.solveiter); |
658aa9fd8665
sqp: provide warnings for QP subproblem failures
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
427 case 6 |
658aa9fd8665
sqp: provide warnings for QP subproblem failures
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
428 warning (id, "sqp: QP subproblem is infeasible"); |
658aa9fd8665
sqp: provide warnings for QP subproblem failures
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
429 endswitch |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
430 |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
431 ## Choose mu such that p is a descent direction for the chosen |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
432 ## merit function phi. |
17245
7babcdb9bc13
Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents:
17174
diff
changeset
|
433 [x_new, alpha, obj_new, globals] = ... |
7babcdb9bc13
Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents:
17174
diff
changeset
|
434 linesearch_L1 (x, p, obj_fun, obj_grd, ce_fun, ci_fun, lambda, ... |
14595
11a9d448fdc3
Get rid of global variables in sqp.
Olaf Till <i7tiol@t-online.de>
parents:
14552
diff
changeset
|
435 obj, globals); |
5289 | 436 |
11348
2ae0ca4ee36b
sqp.m: Change docstring to refer to x0 as the initial seed vector
Rik <octave@nomad.inbox5.com>
parents:
11347
diff
changeset
|
437 ## Evaluate objective function, constraints, and gradients at x_new. |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
438 c_new = feval (obj_grd, x_new); |
5289 | 439 |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
440 ce_new = feval (ce_fun, x_new); |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
441 F_new = feval (ce_grd, x_new); |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
442 |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
443 ci_new = feval (ci_fun, x_new); |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
444 C_new = feval (ci_grd, x_new); |
5289 | 445 |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
446 A_new = [F_new; C_new]; |
5289 | 447 |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
448 ## Set |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
449 ## |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
450 ## s = alpha * p |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
451 ## y = grad_x L (x_new, lambda) - grad_x L (x, lambda}) |
6527 | 452 |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
453 y = c_new - c; |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
454 |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
455 if (! isempty (A)) |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
456 t = ((A_new - A)'*lambda); |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
457 y -= t; |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
458 endif |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
459 |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
460 delx = x_new - x; |
5289 | 461 |
18280
f58a6cd3f909
sqp.m: Fix return values in sqp (bug #32008).
Arun Giridhar <arungiridhar@gmail.com>
parents:
17744
diff
changeset
|
462 ## Check if step size has become too small (indicates lack of progress). |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
463 if (norm (delx) < tol * norm (x)) |
18280
f58a6cd3f909
sqp.m: Fix return values in sqp (bug #32008).
Arun Giridhar <arungiridhar@gmail.com>
parents:
17744
diff
changeset
|
464 info = 104; |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
465 break; |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
466 endif |
5289 | 467 |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
468 if (have_hess) |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
469 |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
470 B = feval (obj_hess, x); |
5289 | 471 |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
472 else |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
473 ## Update B using a quasi-Newton formula. |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
474 delxt = delx'; |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
475 |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
476 ## Damped BFGS. Or maybe we would actually want to use the Hessian |
11348
2ae0ca4ee36b
sqp.m: Change docstring to refer to x0 as the initial seed vector
Rik <octave@nomad.inbox5.com>
parents:
11347
diff
changeset
|
477 ## of the Lagrangian, computed directly? |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
478 d1 = delxt*B*delx; |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
479 |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
480 t1 = 0.2 * d1; |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
481 t2 = delxt*y; |
5289 | 482 |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
483 if (t2 < t1) |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
484 theta = 0.8*d1/(d1 - t2); |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
485 else |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
486 theta = 1; |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
487 endif |
5289 | 488 |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
489 r = theta*y + (1-theta)*B*delx; |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
490 |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
491 d2 = delxt*r; |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
492 |
18280
f58a6cd3f909
sqp.m: Fix return values in sqp (bug #32008).
Arun Giridhar <arungiridhar@gmail.com>
parents:
17744
diff
changeset
|
493 ## Check if the next BFGS update will work properly. |
f58a6cd3f909
sqp.m: Fix return values in sqp (bug #32008).
Arun Giridhar <arungiridhar@gmail.com>
parents:
17744
diff
changeset
|
494 ## If d1 or d2 vanish, the BFGS update will fail. |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
495 if (d1 == 0 || d2 == 0) |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
496 info = 102; |
10549 | 497 break; |
5289 | 498 endif |
499 | |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
500 B = B - B*delx*delxt*B/d1 + r*r'/d2; |
5289 | 501 |
502 endif | |
503 | |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
504 x = x_new; |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
505 |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
506 obj = obj_new; |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
507 |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
508 c = c_new; |
5289 | 509 |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
510 ce = ce_new; |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
511 F = F_new; |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
512 |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
513 ci = ci_new; |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
514 C = C_new; |
5289 | 515 |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
516 A = A_new; |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
517 |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
518 # report (iter, qp_iter, alpha, __sqp_nfun__, obj); |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
519 |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
520 endwhile |
5289 | 521 |
18280
f58a6cd3f909
sqp.m: Fix return values in sqp (bug #32008).
Arun Giridhar <arungiridhar@gmail.com>
parents:
17744
diff
changeset
|
522 ## Check if we've spent too many iterations without converging. |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
523 if (iter >= iter_max) |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
524 info = 103; |
5289 | 525 endif |
526 | |
14595
11a9d448fdc3
Get rid of global variables in sqp.
Olaf Till <i7tiol@t-online.de>
parents:
14552
diff
changeset
|
527 nf = globals.nfun; |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
528 |
7399 | 529 endfunction |
5289 | 530 |
531 | |
17245
7babcdb9bc13
Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents:
17174
diff
changeset
|
532 function [merit, obj, globals] = phi_L1 (obj, obj_fun, ce_fun, ci_fun, ... |
14595
11a9d448fdc3
Get rid of global variables in sqp.
Olaf Till <i7tiol@t-online.de>
parents:
14552
diff
changeset
|
533 x, mu, globals) |
5289 | 534 |
535 ce = feval (ce_fun, x); | |
536 ci = feval (ci_fun, x); | |
537 | |
538 idx = ci < 0; | |
539 | |
540 con = [ce; ci(idx)]; | |
541 | |
542 if (isempty (obj)) | |
543 obj = feval (obj_fun, x); | |
14595
11a9d448fdc3
Get rid of global variables in sqp.
Olaf Till <i7tiol@t-online.de>
parents:
14552
diff
changeset
|
544 globals.nfun++; |
5289 | 545 endif |
546 | |
547 merit = obj; | |
548 t = norm (con, 1) / mu; | |
549 | |
550 if (! isempty (t)) | |
551 merit += t; | |
552 endif | |
553 | |
7399 | 554 endfunction |
5289 | 555 |
556 | |
17245
7babcdb9bc13
Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents:
17174
diff
changeset
|
557 function [x_new, alpha, obj, globals] = ... |
7babcdb9bc13
Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents:
17174
diff
changeset
|
558 linesearch_L1 (x, p, obj_fun, obj_grd, ce_fun, ci_fun, lambda, ... |
14595
11a9d448fdc3
Get rid of global variables in sqp.
Olaf Till <i7tiol@t-online.de>
parents:
14552
diff
changeset
|
559 obj, globals) |
5289 | 560 |
561 ## Choose parameters | |
562 ## | |
563 ## eta in the range (0, 0.5) | |
564 ## tau in the range (0, 1) | |
565 | |
566 eta = 0.25; | |
567 tau = 0.5; | |
568 | |
569 delta_bar = sqrt (eps); | |
570 | |
571 if (isempty (lambda)) | |
572 mu = 1 / delta_bar; | |
573 else | |
574 mu = 1 / (norm (lambda, Inf) + delta_bar); | |
575 endif | |
576 | |
577 alpha = 1; | |
578 | |
579 c = feval (obj_grd, x); | |
580 ce = feval (ce_fun, x); | |
581 | |
17245
7babcdb9bc13
Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents:
17174
diff
changeset
|
582 [phi_x_mu, obj, globals] = phi_L1 (obj, obj_fun, ce_fun, ci_fun, x, ... |
14595
11a9d448fdc3
Get rid of global variables in sqp.
Olaf Till <i7tiol@t-online.de>
parents:
14552
diff
changeset
|
583 mu, globals); |
5289 | 584 |
585 D_phi_x_mu = c' * p; | |
586 d = feval (ci_fun, x); | |
587 ## only those elements of d corresponding | |
588 ## to violated constraints should be included. | |
589 idx = d < 0; | |
590 t = - norm ([ce; d(idx)], 1) / mu; | |
591 if (! isempty (t)) | |
592 D_phi_x_mu += t; | |
593 endif | |
594 | |
595 while (1) | |
17245
7babcdb9bc13
Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents:
17174
diff
changeset
|
596 [p1, obj, globals] = phi_L1 ([], obj_fun, ce_fun, ci_fun, ... |
14595
11a9d448fdc3
Get rid of global variables in sqp.
Olaf Till <i7tiol@t-online.de>
parents:
14552
diff
changeset
|
597 x+alpha*p, mu, globals); |
5289 | 598 p2 = phi_x_mu+eta*alpha*D_phi_x_mu; |
599 if (p1 > p2) | |
600 ## Reset alpha = tau_alpha * alpha for some tau_alpha in the | |
601 ## range (0, tau). | |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
602 tau_alpha = 0.9 * tau; # ?? |
5289 | 603 alpha = tau_alpha * alpha; |
604 else | |
605 break; | |
606 endif | |
607 endwhile | |
608 | |
609 x_new = x + alpha * p; | |
610 | |
7399 | 611 endfunction |
5289 | 612 |
613 | |
614 function grd = fdgrd (f, x) | |
615 | |
616 if (! isempty (f)) | |
617 y0 = feval (f, x); | |
618 nx = length (x); | |
619 grd = zeros (nx, 1); | |
620 deltax = sqrt (eps); | |
621 for i = 1:nx | |
622 t = x(i); | |
623 x(i) += deltax; | |
624 grd(i) = (feval (f, x) - y0) / deltax; | |
625 x(i) = t; | |
626 endfor | |
627 else | |
628 grd = zeros (0, 1); | |
629 endif | |
630 | |
7399 | 631 endfunction |
5289 | 632 |
633 | |
634 function jac = fdjac (f, x) | |
11348
2ae0ca4ee36b
sqp.m: Change docstring to refer to x0 as the initial seed vector
Rik <octave@nomad.inbox5.com>
parents:
11347
diff
changeset
|
635 |
6768 | 636 nx = length (x); |
5289 | 637 if (! isempty (f)) |
638 y0 = feval (f, x); | |
639 nf = length (y0); | |
640 nx = length (x); | |
641 jac = zeros (nf, nx); | |
642 deltax = sqrt (eps); | |
643 for i = 1:nx | |
644 t = x(i); | |
645 x(i) += deltax; | |
646 jac(:,i) = (feval (f, x) - y0) / deltax; | |
647 x(i) = t; | |
648 endfor | |
649 else | |
650 jac = zeros (0, nx); | |
651 endif | |
652 | |
7399 | 653 endfunction |
5289 | 654 |
655 | |
14595
11a9d448fdc3
Get rid of global variables in sqp.
Olaf Till <i7tiol@t-online.de>
parents:
14552
diff
changeset
|
656 function grd = fd_obj_grd (x, obj_fun) |
5289 | 657 |
14595
11a9d448fdc3
Get rid of global variables in sqp.
Olaf Till <i7tiol@t-online.de>
parents:
14552
diff
changeset
|
658 grd = fdgrd (obj_fun, x); |
5289 | 659 |
7399 | 660 endfunction |
5289 | 661 |
662 | |
663 function res = empty_cf (x) | |
664 | |
665 res = zeros (0, 1); | |
666 | |
7399 | 667 endfunction |
5289 | 668 |
669 | |
670 function res = empty_jac (x) | |
671 | |
672 res = zeros (0, length (x)); | |
673 | |
7399 | 674 endfunction |
5289 | 675 |
676 | |
14595
11a9d448fdc3
Get rid of global variables in sqp.
Olaf Till <i7tiol@t-online.de>
parents:
14552
diff
changeset
|
677 function jac = fd_ce_jac (x, ce_fun) |
5289 | 678 |
14595
11a9d448fdc3
Get rid of global variables in sqp.
Olaf Till <i7tiol@t-online.de>
parents:
14552
diff
changeset
|
679 jac = fdjac (ce_fun, x); |
5289 | 680 |
7399 | 681 endfunction |
5289 | 682 |
683 | |
14595
11a9d448fdc3
Get rid of global variables in sqp.
Olaf Till <i7tiol@t-online.de>
parents:
14552
diff
changeset
|
684 function jac = fd_ci_jac (x, cifcn) |
5289 | 685 |
14595
11a9d448fdc3
Get rid of global variables in sqp.
Olaf Till <i7tiol@t-online.de>
parents:
14552
diff
changeset
|
686 ## cifcn = constraint function without gradients and lb or ub |
11a9d448fdc3
Get rid of global variables in sqp.
Olaf Till <i7tiol@t-online.de>
parents:
14552
diff
changeset
|
687 jac = fdjac (cifcn, x); |
6768 | 688 |
7399 | 689 endfunction |
6768 | 690 |
7017 | 691 |
14595
11a9d448fdc3
Get rid of global variables in sqp.
Olaf Till <i7tiol@t-online.de>
parents:
14552
diff
changeset
|
692 function res = cf_ub_lb (x, lbidx, ubidx, globals) |
5289 | 693 |
6768 | 694 ## combine constraint function with ub and lb |
14595
11a9d448fdc3
Get rid of global variables in sqp.
Olaf Till <i7tiol@t-online.de>
parents:
14552
diff
changeset
|
695 if (isempty (globals.cifcn)) |
11a9d448fdc3
Get rid of global variables in sqp.
Olaf Till <i7tiol@t-online.de>
parents:
14552
diff
changeset
|
696 res = [x(lbidx,1)-globals.lb; globals.ub-x(ubidx,1)]; |
11347
2726132f77f6
sqp.m: Remove never violated Inf bounds from computation (bug #31742)
Rik <octave@nomad.inbox5.com>
parents:
11290
diff
changeset
|
697 else |
14595
11a9d448fdc3
Get rid of global variables in sqp.
Olaf Till <i7tiol@t-online.de>
parents:
14552
diff
changeset
|
698 res = [feval(globals.cifcn,x); x(lbidx,1)-globals.lb; |
11a9d448fdc3
Get rid of global variables in sqp.
Olaf Till <i7tiol@t-online.de>
parents:
14552
diff
changeset
|
699 globals.ub-x(ubidx,1)]; |
6768 | 700 endif |
5289 | 701 |
7399 | 702 endfunction |
6768 | 703 |
7017 | 704 |
14595
11a9d448fdc3
Get rid of global variables in sqp.
Olaf Till <i7tiol@t-online.de>
parents:
14552
diff
changeset
|
705 function res = cigrad_ub_lb (x, bgrad, globals) |
6768 | 706 |
14595
11a9d448fdc3
Get rid of global variables in sqp.
Olaf Till <i7tiol@t-online.de>
parents:
14552
diff
changeset
|
707 cigradfcn = @ (x) fd_ci_jac (x, globals.cifcn); |
6768 | 708 |
14595
11a9d448fdc3
Get rid of global variables in sqp.
Olaf Till <i7tiol@t-online.de>
parents:
14552
diff
changeset
|
709 if (iscell (globals.cif) && length (globals.cif) > 1) |
11a9d448fdc3
Get rid of global variables in sqp.
Olaf Till <i7tiol@t-online.de>
parents:
14552
diff
changeset
|
710 cigradfcn = globals.cif{2}; |
6768 | 711 endif |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
712 |
11347
2726132f77f6
sqp.m: Remove never violated Inf bounds from computation (bug #31742)
Rik <octave@nomad.inbox5.com>
parents:
11290
diff
changeset
|
713 if (isempty (cigradfcn)) |
2726132f77f6
sqp.m: Remove never violated Inf bounds from computation (bug #31742)
Rik <octave@nomad.inbox5.com>
parents:
11290
diff
changeset
|
714 res = bgrad; |
2726132f77f6
sqp.m: Remove never violated Inf bounds from computation (bug #31742)
Rik <octave@nomad.inbox5.com>
parents:
11290
diff
changeset
|
715 else |
2726132f77f6
sqp.m: Remove never violated Inf bounds from computation (bug #31742)
Rik <octave@nomad.inbox5.com>
parents:
11290
diff
changeset
|
716 res = [feval(cigradfcn,x); bgrad]; |
6768 | 717 endif |
718 | |
7399 | 719 endfunction |
7361 | 720 |
11348
2ae0ca4ee36b
sqp.m: Change docstring to refer to x0 as the initial seed vector
Rik <octave@nomad.inbox5.com>
parents:
11347
diff
changeset
|
721 # Utility function used to debug sqp |
2ae0ca4ee36b
sqp.m: Change docstring to refer to x0 as the initial seed vector
Rik <octave@nomad.inbox5.com>
parents:
11347
diff
changeset
|
722 function report (iter, qp_iter, alpha, nfun, obj) |
2ae0ca4ee36b
sqp.m: Change docstring to refer to x0 as the initial seed vector
Rik <octave@nomad.inbox5.com>
parents:
11347
diff
changeset
|
723 |
2ae0ca4ee36b
sqp.m: Change docstring to refer to x0 as the initial seed vector
Rik <octave@nomad.inbox5.com>
parents:
11347
diff
changeset
|
724 if (nargin == 0) |
2ae0ca4ee36b
sqp.m: Change docstring to refer to x0 as the initial seed vector
Rik <octave@nomad.inbox5.com>
parents:
11347
diff
changeset
|
725 printf (" Itn ItQP Step Nfun Objective\n"); |
2ae0ca4ee36b
sqp.m: Change docstring to refer to x0 as the initial seed vector
Rik <octave@nomad.inbox5.com>
parents:
11347
diff
changeset
|
726 else |
2ae0ca4ee36b
sqp.m: Change docstring to refer to x0 as the initial seed vector
Rik <octave@nomad.inbox5.com>
parents:
11347
diff
changeset
|
727 printf ("%5d %4d %8.1g %5d %13.6e\n", iter, qp_iter, alpha, nfun, obj); |
2ae0ca4ee36b
sqp.m: Change docstring to refer to x0 as the initial seed vector
Rik <octave@nomad.inbox5.com>
parents:
11347
diff
changeset
|
728 endif |
2ae0ca4ee36b
sqp.m: Change docstring to refer to x0 as the initial seed vector
Rik <octave@nomad.inbox5.com>
parents:
11347
diff
changeset
|
729 |
2ae0ca4ee36b
sqp.m: Change docstring to refer to x0 as the initial seed vector
Rik <octave@nomad.inbox5.com>
parents:
11347
diff
changeset
|
730 endfunction |
2ae0ca4ee36b
sqp.m: Change docstring to refer to x0 as the initial seed vector
Rik <octave@nomad.inbox5.com>
parents:
11347
diff
changeset
|
731 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
732 |
11348
2ae0ca4ee36b
sqp.m: Change docstring to refer to x0 as the initial seed vector
Rik <octave@nomad.inbox5.com>
parents:
11347
diff
changeset
|
733 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
2ae0ca4ee36b
sqp.m: Change docstring to refer to x0 as the initial seed vector
Rik <octave@nomad.inbox5.com>
parents:
11347
diff
changeset
|
734 %% Test Code |
2ae0ca4ee36b
sqp.m: Change docstring to refer to x0 as the initial seed vector
Rik <octave@nomad.inbox5.com>
parents:
11347
diff
changeset
|
735 |
13305
63463570d9fe
Add %!endfunction block keyword to test.m
Rik <octave@nomad.inbox5.com>
parents:
13268
diff
changeset
|
736 %!function r = __g (x) |
7371 | 737 %! r = [sumsq(x)-10; |
738 %! x(2)*x(3)-5*x(4)*x(5); | |
739 %! x(1)^3+x(2)^3+1 ]; | |
13305
63463570d9fe
Add %!endfunction block keyword to test.m
Rik <octave@nomad.inbox5.com>
parents:
13268
diff
changeset
|
740 %!endfunction |
7361 | 741 %! |
13305
63463570d9fe
Add %!endfunction block keyword to test.m
Rik <octave@nomad.inbox5.com>
parents:
13268
diff
changeset
|
742 %!function obj = __phi (x) |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
743 %! obj = exp (prod (x)) - 0.5*(x(1)^3 + x(2)^3 + 1)^2; |
13305
63463570d9fe
Add %!endfunction block keyword to test.m
Rik <octave@nomad.inbox5.com>
parents:
13268
diff
changeset
|
744 %!endfunction |
7361 | 745 %! |
746 %!test | |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
747 %! |
7361 | 748 %! x0 = [-1.8; 1.7; 1.9; -0.8; -0.8]; |
749 %! | |
13305
63463570d9fe
Add %!endfunction block keyword to test.m
Rik <octave@nomad.inbox5.com>
parents:
13268
diff
changeset
|
750 %! [x, obj, info, iter, nf, lambda] = sqp (x0, @__phi, @__g, []); |
7361 | 751 %! |
752 %! x_opt = [-1.717143501952599; | |
753 %! 1.595709610928535; | |
754 %! 1.827245880097156; | |
755 %! -0.763643103133572; | |
756 %! -0.763643068453300]; | |
757 %! | |
7371 | 758 %! obj_opt = 0.0539498477702739; |
7361 | 759 %! |
15757
534a2c881f45
Increase test tolerance on sqp (bug #37742)
Mike Miller <mtmiller@ieee.org>
parents:
14868
diff
changeset
|
760 %! assert (x, x_opt, 8*sqrt (eps)); |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
761 %! assert (obj, obj_opt, sqrt (eps)); |
10678
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
762 |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
763 %% Test input validation |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
764 %!error sqp () |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
765 %!error sqp (1) |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
766 %!error sqp (1,2,3,4,5,6,7,8,9) |
35338deff753
Guarantee equivalent results if sqp called with or wihout bounds
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
767 %!error sqp (1,2,3,4,5) |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
768 %!error sqp (ones (2,2)) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
769 %!error sqp (1, cell (4,1)) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
770 %!error sqp (1, cell (3,1), cell (3,1)) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
771 %!error sqp (1, cell (3,1), cell (2,1), cell (3,1)) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
772 %!error sqp (1, cell (3,1), cell (2,1), cell (2,1), ones (2,2),[]) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
773 %!error sqp (1, cell (3,1), cell (2,1), cell (2,1),[], ones (2,2)) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
774 %!error sqp (1, cell (3,1), cell (2,1), cell (2,1),1,-1) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
775 %!error sqp (1, cell (3,1), cell (2,1), cell (2,1),[],[], ones (2,2)) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
776 %!error sqp (1, cell (3,1), cell (2,1), cell (2,1),[],[],-1) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
777 %!error sqp (1, cell (3,1), cell (2,1), cell (2,1),[],[],1.5) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
778 %!error sqp (1, cell (3,1), cell (2,1), cell (2,1),[],[],[], ones (2,2)) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
779 %!error sqp (1, cell (3,1), cell (2,1), cell (2,1),[],[],[],-1) |
17338
1c89599167a6
maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents:
17336
diff
changeset
|
780 |