Home > matpower5.0 > t > t_qps_matpower.m

t_qps_matpower

PURPOSE ^

T_QPS_MATPOWER Tests of QPS_MATPOWER QP solvers.

SYNOPSIS ^

function t_qps_matpower(quiet)

DESCRIPTION ^

T_QPS_MATPOWER  Tests of QPS_MATPOWER QP solvers.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function t_qps_matpower(quiet)
0002 %T_QPS_MATPOWER  Tests of QPS_MATPOWER QP solvers.
0003 
0004 %   MATPOWER
0005 %   $Id: t_qps_matpower.m 2338 2014-06-27 18:34:09Z ray $
0006 %   by Ray Zimmerman, PSERC Cornell
0007 %   Copyright (c) 2010-2013 by Power System Engineering Research Center (PSERC)
0008 %
0009 %   This file is part of MATPOWER.
0010 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0011 %
0012 %   MATPOWER is free software: you can redistribute it and/or modify
0013 %   it under the terms of the GNU General Public License as published
0014 %   by the Free Software Foundation, either version 3 of the License,
0015 %   or (at your option) any later version.
0016 %
0017 %   MATPOWER is distributed in the hope that it will be useful,
0018 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0019 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0020 %   GNU General Public License for more details.
0021 %
0022 %   You should have received a copy of the GNU General Public License
0023 %   along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.
0024 %
0025 %   Additional permission under GNU GPL version 3 section 7
0026 %
0027 %   If you modify MATPOWER, or any covered work, to interface with
0028 %   other modules (such as MATLAB code and MEX-files) available in a
0029 %   MATLAB(R) or comparable environment containing parts covered
0030 %   under other licensing terms, the licensors of MATPOWER grant
0031 %   you additional permission to convey the resulting work.
0032 
0033 if nargin < 1
0034     quiet = 0;
0035 end
0036 
0037 algs = {'BPMPD', 'MIPS', 250, 'IPOPT', 'OT', 'CPLEX', 'MOSEK', 'GUROBI', 'GLPK'};
0038 names = {'BPMPD_MEX', 'MIPS', 'sc-MIPS', 'IPOPT', 'linprog/quadprog', 'CPLEX', 'MOSEK', 'Gurobi', 'glpk'};
0039 check = {'bpmpd', [], [], 'ipopt', 'quadprog', 'cplex', 'mosek', 'gurobi', 'glpk'};
0040 does_qp = [1 1 1 1 1 1 1 1 0];
0041 
0042 n = 36;
0043 nqp = 28;
0044 t_begin(n*length(algs), quiet);
0045 
0046 for k = 1:length(algs)
0047     if ~isempty(check{k}) && ~have_fcn(check{k})
0048         t_skip(n, sprintf('%s not installed', names{k}));
0049     else
0050         opt = struct('verbose', 0, 'alg', algs{k});
0051         if strcmp(names{k}, 'MIPS') || strcmp(names{k}, 'sc-MIPS')
0052             opt.mips_opt.comptol = 1e-8;
0053         end
0054 %         if strcmp(names{k}, 'quadprog')
0055 %         end
0056         if strcmp(names{k}, 'CPLEX')
0057 %           alg = 0;        %% default uses barrier method with NaN bug in lower lim multipliers
0058             alg = 2;        %% use dual simplex
0059             mpopt = mpoption('cplex.lpmethod', alg, 'cplex.qpmethod', min([4 alg]));
0060             opt.cplex_opt = cplex_options([], mpopt);
0061         end
0062         if strcmp(names{k}, 'MOSEK')
0063 %             alg = 5;        %% use dual simplex
0064             mpopt = mpoption;
0065 %             mpopt = mpoption(mpopt, 'mosek.lp_alg', alg );
0066             mpopt = mpoption(mpopt, 'mosek.gap_tol', 1e-10);
0067             opt.mosek_opt = mosek_options([], mpopt);
0068         end
0069 
0070         t = sprintf('%s - 3-d LP : ', names{k});
0071         %% example from 'doc linprog'
0072         c = [-5; -4; -6];
0073         A = [1 -1  1;
0074              3  2  4;
0075              3  2  0];
0076         l = [];
0077         u = [20; 42; 30];
0078         xmin = [0; 0; 0];
0079         x0 = [];
0080         [x, f, s, out, lam] = qps_matpower([], c, A, l, u, xmin, [], [], opt);
0081         t_is(s, 1, 12, [t 'success']);
0082         t_is(x, [0; 15; 3], 6, [t 'x']);
0083         t_is(f, -78, 6, [t 'f']);
0084         t_is(lam.mu_l, [0;0;0], 9, [t 'lam.mu_l']);
0085         t_is(lam.mu_u, [0;1.5;0.5], 9, [t 'lam.mu_u']);
0086         t_is(lam.lower, [1;0;0], 9, [t 'lam.lower']);
0087         t_is(lam.upper, zeros(size(x)), 9, [t 'lam.upper']);
0088 
0089         if does_qp(k)
0090             t = sprintf('%s - unconstrained 3-d quadratic : ', names{k});
0091             %% from http://www.akiti.ca/QuadProgEx0Constr.html
0092             H = [5 -2 -1; -2 4 3; -1 3 5];
0093             c = [2; -35; -47];
0094             x0 = [0; 0; 0];
0095             [x, f, s, out, lam] = qps_matpower(H, c, [], [], [], [], [], [], opt);
0096             t_is(s, 1, 12, [t 'success']);
0097             t_is(x, [3; 5; 7], 8, [t 'x']);
0098             t_is(f, -249, 13, [t 'f']);
0099             t_ok(isempty(lam.mu_l), [t 'lam.mu_l']);
0100             t_ok(isempty(lam.mu_u), [t 'lam.mu_u']);
0101             t_is(lam.lower, zeros(size(x)), 13, [t 'lam.lower']);
0102             t_is(lam.upper, zeros(size(x)), 13, [t 'lam.upper']);
0103         
0104             t = sprintf('%s - constrained 2-d QP : ', names{k});
0105             %% example from 'doc quadprog'
0106             H = [   1   -1;
0107                     -1  2   ];
0108             c = [-2; -6];
0109             A = [   1   1;
0110                     -1  2;
0111                     2   1   ];
0112             l = [];
0113             u = [2; 2; 3];
0114             xmin = [0; 0];
0115             x0 = [];
0116             [x, f, s, out, lam] = qps_matpower(H, c, A, l, u, xmin, [], x0, opt);
0117             t_is(s, 1, 12, [t 'success']);
0118             t_is(x, [2; 4]/3, 7, [t 'x']);
0119             t_is(f, -74/9, 6, [t 'f']);
0120             t_is(lam.mu_l, [0;0;0], 13, [t 'lam.mu_l']);
0121             t_is(lam.mu_u, [28;4;0]/9, 7, [t 'lam.mu_u']);
0122             t_is(lam.lower, zeros(size(x)), 7, [t 'lam.lower']);
0123             t_is(lam.upper, zeros(size(x)), 13, [t 'lam.upper']);
0124 
0125             t = sprintf('%s - constrained 4-d QP : ', names{k});
0126             %% from http://www.jmu.edu/docs/sasdoc/sashtml/iml/chap8/sect12.htm
0127             H = [   1003.1  4.3     6.3     5.9;
0128                     4.3     2.2     2.1     3.9;
0129                     6.3     2.1     3.5     4.8;
0130                     5.9     3.9     4.8     10  ];
0131             c = zeros(4,1);
0132             A = [   1       1       1       1;
0133                     0.17    0.11    0.10    0.18    ];
0134             l = [1; 0.10];
0135             u = [1; Inf];
0136             xmin = zeros(4,1);
0137             x0 = [1; 0; 0; 1];
0138             [x, f, s, out, lam] = qps_matpower(H, c, A, l, u, xmin, [], x0, opt);
0139             t_is(s, 1, 12, [t 'success']);
0140             t_is(x, [0; 2.8; 0.2; 0]/3, 5, [t 'x']);
0141             t_is(f, 3.29/3, 6, [t 'f']);
0142             t_is(lam.mu_l, [6.58;0]/3, 6, [t 'lam.mu_l']);
0143             t_is(lam.mu_u, [0;0], 13, [t 'lam.mu_u']);
0144             t_is(lam.lower, [2.24;0;0;1.7667], 4, [t 'lam.lower']);
0145             t_is(lam.upper, zeros(size(x)), 13, [t 'lam.upper']);
0146 
0147             t = sprintf('%s - (struct) constrained 4-d QP : ', names{k});
0148             p = struct('H', H, 'A', A, 'l', l, 'u', u, 'xmin', xmin, 'x0', x0, 'opt', opt);
0149             [x, f, s, out, lam] = qps_matpower(p);
0150             t_is(s, 1, 12, [t 'success']);
0151             t_is(x, [0; 2.8; 0.2; 0]/3, 5, [t 'x']);
0152             t_is(f, 3.29/3, 6, [t 'f']);
0153             t_is(lam.mu_l, [6.58;0]/3, 6, [t 'lam.mu_l']);
0154             t_is(lam.mu_u, [0;0], 13, [t 'lam.mu_u']);
0155             t_is(lam.lower, [2.24;0;0;1.7667], 4, [t 'lam.lower']);
0156             t_is(lam.upper, zeros(size(x)), 13, [t 'lam.upper']);
0157         else
0158             t_skip(nqp, sprintf('%s does not handle QP problems', names{k}));
0159         end
0160 
0161         t = sprintf('%s - infeasible LP : ', names{k});
0162         p = struct('A', sparse([1 1]), 'c', [1;1], 'u', -1, 'xmin', [0;0], 'opt', opt);
0163         [x, f, s, out, lam] = qps_matpower(p);
0164         t_ok(s <= 0, [t 'no success']);
0165     end
0166 end
0167 
0168 t_end;

Generated on Mon 26-Jan-2015 15:21:31 by m2html © 2005