Optimization: principles and algorithms, by Michel Bierlaire
localSqp.m
Go to the documentation of this file.
1 %> \file
2 %> Algorithm 20.1: local SQP algorithm. Implementation of algorithm 20.1 of \cite Bier15-book
3 %>
4 %> @note Tested with \ref run2002.m
5 %> @note Tested with \ref run2003.m
6 %> @note Tested with \ref run2004.m
7 %>
8 %> @author Michel Bierlaire
9 %> @date Thu Mar 26 13:33:44 2015
10 %> @ingroup Algorithms
11 %> @ingroup chap20
12 
13 %> Applies the local SQP method to solve \f[\min_x f(x) \f] subject to \f[h(x)=0,\f] where \f$f:\mathbb{R}^n \to \mathbb{R}\f$ and \f$h:\mathbb{R}^n \to \mathbb{R}^m \f$.
14 %> @param problem the name of the Octave function defining f(x), h(x) and their derivatives. The funtion has two arguments: x and index. If index=0, the objective function \f$f\f$ and its derivatives are evaluated. If index=\f$i\f$, the constraint \f$h_i\f$ and its derivtives are evaluated.
15 %> @param x0 starting primal point (nx1)
16 %> @param lambda0 starting dual point (mx1)
17 %> @param eps algorithm stops if \f$\|\nabla L(x_k,\lambda_k\| \leq \varepsilon \f$ and \f$\|h(x_k)\|^2\f$.
18 %> @param maxiter maximum number of iterations (default: 100)
19 %> @return [solution,lambda]
20 %> @return x: primal solution
21 %> @return lambda: dual solution
22 function [solution,lambda] = localSqp(problem,x0,lambda0,eps,maxiter=100)
23  n = size(x0,1) ;
24  m = size(lambda0,1) ;
25  xk = x0 ;
26  lambdak = lambda0 ;
27  dx = [ 0 ; 0] ;
28 # printf("x(1)\tx(2)\tlambda\tdx1\tdx2\tnorm\n") ;
29  k = 0 ;
30  do
31  printf("%d\t\%12.5e\t%12.5e\t%12.5e\t",k,xk(1),xk(2),lambdak) ;
32 # printf("%f,%f\n",xk(1),xk(2)) ;
33  [f,g,H] = feval(problem,xk,0) ;
34  contr = [] ;
35  gradcontr = [] ;
36  hesslagrangien = H ;
37  for i=1:m
38  [fi,gi,Hi] = feval(problem,xk,i) ;
39  contr = [contr ; fi] ;
40  gradcontr = [gradcontr ; gi] ;
41  hesslagrangien += lambdak(i) * Hi ;
42  endfor
43  [dx,qobj,info,dl] = qp(xk,hesslagrangien,g,-gradcontr',contr);
44 
45  gradlagrangien = [g + gradcontr * lambdak ; contr] ;
46  printf("%12.5e\n", norm(gradlagrangien)) ;
47  xk = xk + dx ;
48  lambdak = dl ;
49  k = k + 1 ;
50  until (norm(gradlagrangien) <= eps || k >= maxiter)
51  solution = xk ;
52  lambda = lambdak ;
53 endfunction
function localSqp(in problem, in x0, in lambda0, in eps, in maxiter)
Applies the local SQP method to solve subject to where and .
Copyright 2015-2016 Michel Bierlaire