Home > matpower7.1 > mips > lib > qps_mips.m

qps_mips

PURPOSE ^

QPS_MIPS Quadratic Program Solver based on MIPS.

SYNOPSIS ^

function [x, f, eflag, output, lambda] = qps_mips(H, c, A, l, u, xmin, xmax, x0, opt)

DESCRIPTION ^

QPS_MIPS  Quadratic Program Solver based on MIPS.
   [X, F, EXITFLAG, OUTPUT, LAMBDA] = ...
       QPS_MIPS(H, C, A, L, U, XMIN, XMAX, X0, OPT)
   [X, F, EXITFLAG, OUTPUT, LAMBDA] = QPS_MIPS(PROBLEM)
   A wrapper function providing a MATPOWER standardized interface for using
   the MATPOWER Interior Point Solver (MIPS) to solve the following QP
   (quadratic programming) problem:

       min 1/2 X'*H*X + C'*X
        X

   subject to

       L <= A*X <= U       (linear constraints)
       XMIN <= X <= XMAX   (variable bounds)

   Inputs (all optional except H, C, A and L):
       H : matrix (possibly sparse) of quadratic cost coefficients
       C : vector of linear cost coefficients
       A, L, U : define the optional linear constraints. Default
           values for the elements of L and U are -Inf and Inf,
           respectively.
       XMIN, XMAX : optional lower and upper bounds on the
           X variables, defaults are -Inf and Inf, respectively.
       X0 : optional starting value of optimization vector X
       OPT : optional MIPS options struct (see MIPS for details)
       PROBLEM : The inputs can alternatively be supplied in a single
           PROBLEM struct with fields corresponding to the input arguments
           described above: H, c, A, l, u, xmin, xmax, x0, opt

   Outputs:
       X : solution vector
       F : final objective function value
       EXITFLAG : exit flag
           1 = first order optimality conditions satisfied
           0 = maximum number of iterations reached
           -1 = numerically failed
       OUTPUT : output struct with the following fields:
           iterations - number of iterations performed
           hist - struct array with trajectories of the following:
                   feascond, gradcond, compcond, costcond, gamma,
                   stepsize, obj, alphap, alphad
           message - exit message
       LAMBDA : struct containing the Langrange and Kuhn-Tucker
           multipliers on the constraints, with fields:
           mu_l - lower (left-hand) limit on linear constraints
           mu_u - upper (right-hand) limit on linear constraints
           lower - lower bound on optimization variables
           upper - upper bound on optimization variables

   Note the calling syntax is almost identical to that of QUADPROG
   from MathWorks' Optimization Toolbox. The main difference is that
   the linear constraints are specified with A, L, U instead of
   A, B, Aeq, Beq.

   Calling syntax options:
       [x, f, exitflag, output, lambda] = ...
           qps_mips(H, c, A, l, u, xmin, xmax, x0, opt)

       x = qps_mips(H, c, A, l, u)
       x = qps_mips(H, c, A, l, u, xmin, xmax)
       x = qps_mips(H, c, A, l, u, xmin, xmax, x0)
       x = qps_mips(H, c, A, l, u, xmin, xmax, x0, opt)
       x = qps_mips(problem), where problem is a struct with fields:
                       H, c, A, l, u, xmin, xmax, x0, opt
                       all fields except 'c', 'A' and 'l' or 'u' are optional
       x = qps_mips(...)
       [x, f] = qps_mips(...)
       [x, f, exitflag] = qps_mips(...)
       [x, f, exitflag, output] = qps_mips(...)
       [x, f, exitflag, output, lambda] = qps_mips(...)

   Example: (problem from from https://v8doc.sas.com/sashtml/iml/chap8/sect12.htm)
       H = [   1003.1  4.3     6.3     5.9;
               4.3     2.2     2.1     3.9;
               6.3     2.1     3.5     4.8;
               5.9     3.9     4.8     10  ];
       c = zeros(4,1);
       A = [   1       1       1       1;
               0.17    0.11    0.10    0.18    ];
       l = [1; 0.10];
       u = [1; Inf];
       xmin = zeros(4,1);
       x0 = [1; 0; 0; 1];
       opt = struct('verbose', 2);
       [x, f, s, out, lambda] = qps_mips(H, c, A, l, u, xmin, [], x0, opt);

   See also MIPS.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [x, f, eflag, output, lambda] = qps_mips(H, c, A, l, u, xmin, xmax, x0, opt)
0002 %QPS_MIPS  Quadratic Program Solver based on MIPS.
0003 %   [X, F, EXITFLAG, OUTPUT, LAMBDA] = ...
0004 %       QPS_MIPS(H, C, A, L, U, XMIN, XMAX, X0, OPT)
0005 %   [X, F, EXITFLAG, OUTPUT, LAMBDA] = QPS_MIPS(PROBLEM)
0006 %   A wrapper function providing a MATPOWER standardized interface for using
0007 %   the MATPOWER Interior Point Solver (MIPS) to solve the following QP
0008 %   (quadratic programming) problem:
0009 %
0010 %       min 1/2 X'*H*X + C'*X
0011 %        X
0012 %
0013 %   subject to
0014 %
0015 %       L <= A*X <= U       (linear constraints)
0016 %       XMIN <= X <= XMAX   (variable bounds)
0017 %
0018 %   Inputs (all optional except H, C, A and L):
0019 %       H : matrix (possibly sparse) of quadratic cost coefficients
0020 %       C : vector of linear cost coefficients
0021 %       A, L, U : define the optional linear constraints. Default
0022 %           values for the elements of L and U are -Inf and Inf,
0023 %           respectively.
0024 %       XMIN, XMAX : optional lower and upper bounds on the
0025 %           X variables, defaults are -Inf and Inf, respectively.
0026 %       X0 : optional starting value of optimization vector X
0027 %       OPT : optional MIPS options struct (see MIPS for details)
0028 %       PROBLEM : The inputs can alternatively be supplied in a single
0029 %           PROBLEM struct with fields corresponding to the input arguments
0030 %           described above: H, c, A, l, u, xmin, xmax, x0, opt
0031 %
0032 %   Outputs:
0033 %       X : solution vector
0034 %       F : final objective function value
0035 %       EXITFLAG : exit flag
0036 %           1 = first order optimality conditions satisfied
0037 %           0 = maximum number of iterations reached
0038 %           -1 = numerically failed
0039 %       OUTPUT : output struct with the following fields:
0040 %           iterations - number of iterations performed
0041 %           hist - struct array with trajectories of the following:
0042 %                   feascond, gradcond, compcond, costcond, gamma,
0043 %                   stepsize, obj, alphap, alphad
0044 %           message - exit message
0045 %       LAMBDA : struct containing the Langrange and Kuhn-Tucker
0046 %           multipliers on the constraints, with fields:
0047 %           mu_l - lower (left-hand) limit on linear constraints
0048 %           mu_u - upper (right-hand) limit on linear constraints
0049 %           lower - lower bound on optimization variables
0050 %           upper - upper bound on optimization variables
0051 %
0052 %   Note the calling syntax is almost identical to that of QUADPROG
0053 %   from MathWorks' Optimization Toolbox. The main difference is that
0054 %   the linear constraints are specified with A, L, U instead of
0055 %   A, B, Aeq, Beq.
0056 %
0057 %   Calling syntax options:
0058 %       [x, f, exitflag, output, lambda] = ...
0059 %           qps_mips(H, c, A, l, u, xmin, xmax, x0, opt)
0060 %
0061 %       x = qps_mips(H, c, A, l, u)
0062 %       x = qps_mips(H, c, A, l, u, xmin, xmax)
0063 %       x = qps_mips(H, c, A, l, u, xmin, xmax, x0)
0064 %       x = qps_mips(H, c, A, l, u, xmin, xmax, x0, opt)
0065 %       x = qps_mips(problem), where problem is a struct with fields:
0066 %                       H, c, A, l, u, xmin, xmax, x0, opt
0067 %                       all fields except 'c', 'A' and 'l' or 'u' are optional
0068 %       x = qps_mips(...)
0069 %       [x, f] = qps_mips(...)
0070 %       [x, f, exitflag] = qps_mips(...)
0071 %       [x, f, exitflag, output] = qps_mips(...)
0072 %       [x, f, exitflag, output, lambda] = qps_mips(...)
0073 %
0074 %   Example: (problem from from https://v8doc.sas.com/sashtml/iml/chap8/sect12.htm)
0075 %       H = [   1003.1  4.3     6.3     5.9;
0076 %               4.3     2.2     2.1     3.9;
0077 %               6.3     2.1     3.5     4.8;
0078 %               5.9     3.9     4.8     10  ];
0079 %       c = zeros(4,1);
0080 %       A = [   1       1       1       1;
0081 %               0.17    0.11    0.10    0.18    ];
0082 %       l = [1; 0.10];
0083 %       u = [1; Inf];
0084 %       xmin = zeros(4,1);
0085 %       x0 = [1; 0; 0; 1];
0086 %       opt = struct('verbose', 2);
0087 %       [x, f, s, out, lambda] = qps_mips(H, c, A, l, u, xmin, [], x0, opt);
0088 %
0089 %   See also MIPS.
0090 
0091 %   MIPS
0092 %   Copyright (c) 2010-2020, Power Systems Engineering Research Center (PSERC)
0093 %   by Ray Zimmerman, PSERC Cornell
0094 %
0095 %   This file is part of MIPS.
0096 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0097 %   See https://github.com/MATPOWER/mips for more info.
0098 
0099 %%----- input argument handling  -----
0100 %% gather inputs
0101 if nargin == 1 && isstruct(H)       %% problem struct
0102     p = H;
0103 else                                %% individual args
0104     p = struct('H', H, 'c', c, 'A', A, 'l', l, 'u', u);
0105     if nargin > 5
0106         p.xmin = xmin;
0107         if nargin > 6
0108             p.xmax = xmax;
0109             if nargin > 7
0110                 p.x0 = x0;
0111                 if nargin > 8
0112                     p.opt = opt;
0113                 end
0114             end
0115         end
0116     end
0117 end
0118 
0119 %% define nx, set default values for H and c
0120 if ~isfield(p, 'H') || isempty(p.H) || ~any(any(p.H))
0121     if (~isfield(p, 'A') || isempty(p.A)) && ...
0122             (~isfield(p, 'xmin') || isempty(p.xmin)) && ...
0123             (~isfield(p, 'xmax') || isempty(p.xmax))
0124         error('qps_mips: LP problem must include constraints or variable bounds');
0125     else
0126         if isfield(p, 'A') && ~isempty(p.A)
0127             nx = size(p.A, 2);
0128         elseif isfield(p, 'xmin') && ~isempty(p.xmin)
0129             nx = length(p.xmin);
0130         else    % if isfield(p, 'xmax') && ~isempty(p.xmax)
0131             nx = length(p.xmax);
0132         end
0133     end
0134     p.H = sparse(nx, nx);
0135 else
0136     nx = size(p.H, 1);
0137 end
0138 if ~isfield(p, 'c') || isempty(p.c)
0139     p.c = zeros(nx, 1);
0140 end
0141 if ~isfield(p, 'x0') || isempty(p.x0)
0142     p.x0 = zeros(nx, 1);
0143 end
0144 
0145 %%-----  run optimization  -----
0146 p.f_fcn = @(x)qp_f(x, p.H, p.c);
0147 [x, f, eflag, output, lambda] = mips(p);
0148 
0149 %%-----  objective function  -----
0150 function [f, df, d2f] = qp_f(x, H, c)
0151 f = 0.5 * x' * H * x + c' * x;
0152 if nargout > 1
0153     df = H * x + c;
0154     if nargout > 2
0155         d2f = H;
0156     end
0157 end

Generated on Fri 09-Oct-2020 11:21:31 by m2html © 2005