------------------------------ deprecated ------------------------------ MATLAB 6.x support to be removed in a future version. -------------------------------------------------------------------------- QPS_MIPS Quadratic Program Solver based on MIPS (for MATLAB 6.x). [X, F, EXITFLAG, OUTPUT, LAMBDA] = ... QPS_MIPS6(H, C, A, L, U, XMIN, XMAX, X0, OPT) Uses the MATLAB 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 options structure with the following fields, all of which are also optional (default values shown in parentheses) verbose (0) - controls level of progress output displayed 0 = no progress output 1 = some progress output 2 = verbose progress output feastol (1e-6) - termination tolerance for feasibility condition gradtol (1e-6) - termination tolerance for gradient condition comptol (1e-6) - termination tolerance for complementarity condition costtol (1e-6) - termination tolerance for cost condition max_it (150) - maximum number of iterations step_control (0) - set to 1 to enable step-size control max_red (20) - maximum number of step-size reductions if step-control is on cost_mult (1) - cost multiplier used to scale the objective function for improved conditioning. 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_mips6(H, c, A, l, u, xmin, xmax, x0, opt) x = qps_mips6(H, c, A, l, u) x = qps_mips6(H, c, A, l, u, xmin, xmax) x = qps_mips6(H, c, A, l, u, xmin, xmax, x0) x = qps_mips6(H, c, A, l, u, xmin, xmax, x0, opt) x = qps_mips6(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_mips6(...) [x, f] = qps_mips6(...) [x, f, exitflag] = qps_mips6(...) [x, f, exitflag, output] = qps_mips6(...) [x, f, exitflag, output, lambda] = qps_mips6(...) Example: (problem from from http://www.jmu.edu/docs/sasdoc/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_mips6(H, c, A, l, u, xmin, [], x0, opt); See also MIPS.
0001 function [x, f, eflag, output, lambda] = qps_mips6(H, c, A, l, u, xmin, xmax, x0, opt) 0002 %------------------------------ deprecated ------------------------------ 0003 % MATLAB 6.x support to be removed in a future version. 0004 %-------------------------------------------------------------------------- 0005 %QPS_MIPS Quadratic Program Solver based on MIPS (for MATLAB 6.x). 0006 % [X, F, EXITFLAG, OUTPUT, LAMBDA] = ... 0007 % QPS_MIPS6(H, C, A, L, U, XMIN, XMAX, X0, OPT) 0008 % Uses the MATLAB Interior Point Solver (MIPS) to solve the following 0009 % QP (quadratic programming) problem: 0010 % 0011 % min 1/2 X'*H*X + C'*X 0012 % X 0013 % 0014 % subject to 0015 % 0016 % L <= A*X <= U (linear constraints) 0017 % XMIN <= X <= XMAX (variable bounds) 0018 % 0019 % Inputs (all optional except H, C, A and L): 0020 % H : matrix (possibly sparse) of quadratic cost coefficients 0021 % C : vector of linear cost coefficients 0022 % A, L, U : define the optional linear constraints. Default 0023 % values for the elements of L and U are -Inf and Inf, 0024 % respectively. 0025 % XMIN, XMAX : optional lower and upper bounds on the 0026 % X variables, defaults are -Inf and Inf, respectively. 0027 % X0 : optional starting value of optimization vector X 0028 % OPT : optional options structure with the following fields, 0029 % all of which are also optional (default values shown in 0030 % parentheses) 0031 % verbose (0) - controls level of progress output displayed 0032 % 0 = no progress output 0033 % 1 = some progress output 0034 % 2 = verbose progress output 0035 % feastol (1e-6) - termination tolerance for feasibility 0036 % condition 0037 % gradtol (1e-6) - termination tolerance for gradient 0038 % condition 0039 % comptol (1e-6) - termination tolerance for complementarity 0040 % condition 0041 % costtol (1e-6) - termination tolerance for cost condition 0042 % max_it (150) - maximum number of iterations 0043 % step_control (0) - set to 1 to enable step-size control 0044 % max_red (20) - maximum number of step-size reductions if 0045 % step-control is on 0046 % cost_mult (1) - cost multiplier used to scale the objective 0047 % function for improved conditioning. 0048 % PROBLEM : The inputs can alternatively be supplied in a single 0049 % PROBLEM struct with fields corresponding to the input arguments 0050 % described above: H, c, A, l, u, xmin, xmax, x0, opt 0051 % 0052 % Outputs: 0053 % X : solution vector 0054 % F : final objective function value 0055 % EXITFLAG : exit flag 0056 % 1 = first order optimality conditions satisfied 0057 % 0 = maximum number of iterations reached 0058 % -1 = numerically failed 0059 % OUTPUT : output struct with the following fields: 0060 % iterations - number of iterations performed 0061 % hist - struct array with trajectories of the following: 0062 % feascond, gradcond, compcond, costcond, gamma, 0063 % stepsize, obj, alphap, alphad 0064 % message - exit message 0065 % LAMBDA : struct containing the Langrange and Kuhn-Tucker 0066 % multipliers on the constraints, with fields: 0067 % mu_l - lower (left-hand) limit on linear constraints 0068 % mu_u - upper (right-hand) limit on linear constraints 0069 % lower - lower bound on optimization variables 0070 % upper - upper bound on optimization variables 0071 % 0072 % Note the calling syntax is almost identical to that of QUADPROG 0073 % from MathWorks' Optimization Toolbox. The main difference is that 0074 % the linear constraints are specified with A, L, U instead of 0075 % A, B, Aeq, Beq. 0076 % 0077 % Calling syntax options: 0078 % [x, f, exitflag, output, lambda] = ... 0079 % qps_mips6(H, c, A, l, u, xmin, xmax, x0, opt) 0080 % 0081 % x = qps_mips6(H, c, A, l, u) 0082 % x = qps_mips6(H, c, A, l, u, xmin, xmax) 0083 % x = qps_mips6(H, c, A, l, u, xmin, xmax, x0) 0084 % x = qps_mips6(H, c, A, l, u, xmin, xmax, x0, opt) 0085 % x = qps_mips6(problem), where problem is a struct with fields: 0086 % H, c, A, l, u, xmin, xmax, x0, opt 0087 % all fields except 'c', 'A' and 'l' or 'u' are optional 0088 % x = qps_mips6(...) 0089 % [x, f] = qps_mips6(...) 0090 % [x, f, exitflag] = qps_mips6(...) 0091 % [x, f, exitflag, output] = qps_mips6(...) 0092 % [x, f, exitflag, output, lambda] = qps_mips6(...) 0093 % 0094 % Example: (problem from from http://www.jmu.edu/docs/sasdoc/sashtml/iml/chap8/sect12.htm) 0095 % H = [ 1003.1 4.3 6.3 5.9; 0096 % 4.3 2.2 2.1 3.9; 0097 % 6.3 2.1 3.5 4.8; 0098 % 5.9 3.9 4.8 10 ]; 0099 % c = zeros(4,1); 0100 % A = [ 1 1 1 1; 0101 % 0.17 0.11 0.10 0.18 ]; 0102 % l = [1; 0.10]; 0103 % u = [1; Inf]; 0104 % xmin = zeros(4,1); 0105 % x0 = [1; 0; 0; 1]; 0106 % opt = struct('verbose', 2); 0107 % [x, f, s, out, lambda] = qps_mips6(H, c, A, l, u, xmin, [], x0, opt); 0108 % 0109 % See also MIPS. 0110 0111 % MIPS 0112 % $Id: qps_mips6.m,v 1.12 2011/09/09 15:26:09 cvs Exp $ 0113 % by Ray Zimmerman, PSERC Cornell 0114 % Copyright (c) 2010 by Power System Engineering Research Center (PSERC) 0115 % 0116 % This file is part of MIPS. 0117 % See http://www.pserc.cornell.edu/matpower/ for more info. 0118 % 0119 % MIPS is free software: you can redistribute it and/or modify 0120 % it under the terms of the GNU General Public License as published 0121 % by the Free Software Foundation, either version 3 of the License, 0122 % or (at your option) any later version. 0123 % 0124 % MIPS is distributed in the hope that it will be useful, 0125 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0126 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0127 % GNU General Public License for more details. 0128 % 0129 % You should have received a copy of the GNU General Public License 0130 % along with MIPS. If not, see <http://www.gnu.org/licenses/>. 0131 % 0132 % Additional permission under GNU GPL version 3 section 7 0133 % 0134 % If you modify MIPS, or any covered work, to interface with 0135 % other modules (such as MATLAB code and MEX-files) available in a 0136 % MATLAB(R) or comparable environment containing parts covered 0137 % under other licensing terms, the licensors of MIPS grant 0138 % you additional permission to convey the resulting work. 0139 0140 %%----- input argument handling ----- 0141 %% gather inputs 0142 if nargin == 1 && isstruct(H) %% problem struct 0143 p = H; 0144 else %% individual args 0145 p = struct('H', H, 'c', c, 'A', A, 'l', l, 'u', u); 0146 if nargin > 5 0147 p.xmin = xmin; 0148 if nargin > 6 0149 p.xmax = xmax; 0150 if nargin > 7 0151 p.x0 = x0; 0152 if nargin > 8 0153 p.opt = opt; 0154 end 0155 end 0156 end 0157 end 0158 end 0159 0160 %% define nx, set default values for H and c 0161 if ~isfield(p, 'H') || isempty(p.H) || ~any(any(p.H)) 0162 if (~isfield(p, 'A') || isempty(p.A)) && ... 0163 (~isfield(p, 'xmin') || isempty(p.xmin)) && ... 0164 (~isfield(p, 'xmax') || isempty(p.xmax)) 0165 error('qps_mips6: LP problem must include constraints or variable bounds'); 0166 else 0167 if isfield(p, 'A') && ~isempty(p.A) 0168 nx = size(p.A, 2); 0169 elseif isfield(p, 'xmin') && ~isempty(p.xmin) 0170 nx = length(p.xmin); 0171 else % if isfield(p, 'xmax') && ~isempty(p.xmax) 0172 nx = length(p.xmax); 0173 end 0174 end 0175 p.H = sparse(nx, nx); 0176 else 0177 nx = size(p.H, 1); 0178 end 0179 if ~isfield(p, 'c') || isempty(p.c) 0180 p.c = zeros(nx, 1); 0181 end 0182 if ~isfield(p, 'x0') || isempty(p.x0) 0183 p.x0 = zeros(nx, 1); 0184 end 0185 0186 %%----- run optimization ----- 0187 p.f_fcn = @qp_f; 0188 [x, f, eflag, output, lambda] = mips6(p); 0189 0190 %%----- objective function ----- 0191 function [f, df, d2f] = qp_f(x, p) 0192 f = 0.5 * x' * p.H * x + p.c' * x; 0193 if nargout > 1 0194 df = p.H * x + p.c; 0195 if nargout > 2 0196 d2f = p.H; 0197 end 0198 end