Home > matpower7.0 > lib > 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 %   Copyright (c) 2010-2016, Power Systems Engineering Research Center (PSERC)
0006 %   by Ray Zimmerman, PSERC Cornell
0007 %
0008 %   This file is part of MATPOWER.
0009 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0010 %   See https://matpower.org for more info.
0011 
0012 if nargin < 1
0013     quiet = 0;
0014 end
0015 
0016 algs = {'BPMPD', 'MIPS', 250, 'IPOPT', 'OT', 'CPLEX', 'MOSEK', 'GUROBI', 'CLP', 'GLPK'};
0017 names = {'BPMPD_MEX', 'MIPS', 'sc-MIPS', 'IPOPT', 'linprog/quadprog', 'CPLEX', 'MOSEK', 'Gurobi', 'CLP', 'glpk'};
0018 check = {'bpmpd', [], [], 'ipopt', 'quadprog', 'cplex', 'mosek', 'gurobi', 'clp', 'glpk'};
0019 does_qp = [1 1 1 1 1 1 1 1 1 0];
0020 
0021 n = 36;
0022 nqp = 28;
0023 t_begin(n*length(algs), quiet);
0024 
0025 diff_alg_warn_id = 'optim:linprog:WillRunDiffAlg';
0026 if have_fcn('quadprog') && have_fcn('quadprog', 'vnum') == 7.005
0027     s1 = warning('query', diff_alg_warn_id);
0028     warning('off', diff_alg_warn_id);
0029 end
0030 
0031 for k = 1:length(algs)
0032     if ~isempty(check{k}) && ~have_fcn(check{k})
0033         t_skip(n, sprintf('%s not installed', names{k}));
0034     else
0035         opt = struct('verbose', 0, 'alg', algs{k});
0036         if strcmp(names{k}, 'MIPS') || strcmp(names{k}, 'sc-MIPS')
0037             opt.mips_opt.comptol = 1e-8;
0038         end
0039 %         if strcmp(names{k}, 'linprog/quadprog')
0040 %             opt.verbose = 2;
0041 %             opt.linprog_opt.Algorithm = 'interior-point';
0042 %             opt.linprog_opt.Algorithm = 'active-set';
0043 %             opt.linprog_opt.Algorithm = 'simplex';
0044 %             opt.linprog_opt.Algorithm = 'dual-simplex';
0045 %         end
0046         if strcmp(names{k}, 'CPLEX')
0047 %           alg = 0;        %% default uses barrier method with NaN bug in lower lim multipliers
0048             alg = 2;        %% use dual simplex
0049             mpopt = mpoption('cplex.lpmethod', alg, 'cplex.qpmethod', min([4 alg]));
0050             opt.cplex_opt = cplex_options([], mpopt);
0051         end
0052         if strcmp(names{k}, 'MOSEK')
0053             mpopt = mpoption;
0054 %             sc = mosek_symbcon;
0055 %             alg = sc.MSK_OPTIMIZER_DUAL_SIMPLEX;    %% use dual simplex
0056 %             alg = sc.MSK_OPTIMIZER_INTPNT;          %% use interior point
0057 %             mpopt = mpoption(mpopt, 'mosek.lp_alg', alg );
0058             mpopt = mpoption(mpopt, 'mosek.gap_tol', 1e-10);
0059 %             mpopt = mpoption(mpopt, 'mosek.opts.MSK_DPAR_INTPNT_TOL_PFEAS', 1e-10);
0060 %             mpopt = mpoption(mpopt, 'mosek.opts.MSK_DPAR_INTPNT_TOL_DFEAS', 1e-10);
0061 %             mpopt = mpoption(mpopt, 'mosek.opts.MSK_DPAR_INTPNT_TOL_INFEAS', 1e-10);
0062 %             mpopt = mpoption(mpopt, 'mosek.opts.MSK_DPAR_INTPNT_TOL_REL_GAP', 1e-10);
0063             vnum = have_fcn('mosek', 'vnum');
0064             if vnum >= 8
0065 %                 mpopt = mpoption(mpopt, 'mosek.opts.MSK_DPAR_INTPNT_QO_TOL_PFEAS', 1e-10);
0066 %                 mpopt = mpoption(mpopt, 'mosek.opts.MSK_DPAR_INTPNT_QO_TOL_DFEAS', 1e-10);
0067 %                 mpopt = mpoption(mpopt, 'mosek.opts.MSK_DPAR_INTPNT_QO_TOL_INFEAS', 1e-10);
0068 %                 mpopt = mpoption(mpopt, 'mosek.opts.MSK_DPAR_INTPNT_QO_TOL_MU_RED', 1e-10);
0069                 mpopt = mpoption(mpopt, 'mosek.opts.MSK_DPAR_INTPNT_QO_TOL_REL_GAP', 1e-10);
0070             end
0071 %             opt.verbose = 3;
0072             opt.mosek_opt = mosek_options([], mpopt);
0073         end
0074 
0075         t = sprintf('%s - 3-d LP : ', names{k});
0076         %% based on example from 'doc linprog'
0077         c = [-5; -4; -6];
0078         A = [1 -1  1;
0079              -3  -2  -4;
0080              3  2  0];
0081         l = [-Inf; -42; -Inf];
0082         u = [20; Inf; 30];
0083         xmin = [0; 0; 0];
0084         x0 = [];
0085         [x, f, s, out, lam] = qps_matpower([], c, A, l, u, xmin, [], [], opt);
0086         t_is(s, 1, 12, [t 'success']);
0087         t_is(x, [0; 15; 3], 6, [t 'x']);
0088         t_is(f, -78, 6, [t 'f']);
0089         t_is(lam.mu_l, [0;1.5;0], 9, [t 'lam.mu_l']);
0090         t_is(lam.mu_u, [0;0;0.5], 9, [t 'lam.mu_u']);
0091         if strcmp(algs{k}, 'CLP') && ~have_fcn('opti_clp')
0092             t_skip(2, [t 'lam.lower/upper : MEXCLP does not return multipliers on var bounds']);
0093         else
0094             t_is(lam.lower, [1;0;0], 9, [t 'lam.lower']);
0095             t_is(lam.upper, zeros(size(x)), 9, [t 'lam.upper']);
0096         end
0097 
0098         if does_qp(k)
0099             t = sprintf('%s - unconstrained 3-d quadratic : ', names{k});
0100             %% from http://www.akiti.ca/QuadProgEx0Constr.html
0101             H = [5 -2 -1; -2 4 3; -1 3 5];
0102             c = [2; -35; -47];
0103             x0 = [0; 0; 0];
0104             [x, f, s, out, lam] = qps_matpower(H, c, [], [], [], [], [], [], opt);
0105             t_is(s, 1, 12, [t 'success']);
0106             t_is(x, [3; 5; 7], 8, [t 'x']);
0107             t_is(f, -249, 13, [t 'f']);
0108             t_ok(isempty(lam.mu_l), [t 'lam.mu_l']);
0109             t_ok(isempty(lam.mu_u), [t 'lam.mu_u']);
0110             t_is(lam.lower, zeros(size(x)), 13, [t 'lam.lower']);
0111             t_is(lam.upper, zeros(size(x)), 13, [t 'lam.upper']);
0112         
0113             t = sprintf('%s - constrained 2-d QP : ', names{k});
0114             %% example from 'doc quadprog'
0115             H = [   1   -1;
0116                     -1  2   ];
0117             c = [-2; -6];
0118             A = [   1   1;
0119                     -1  2;
0120                     2   1   ];
0121             l = [];
0122             u = [2; 2; 3];
0123             xmin = [0; 0];
0124             x0 = [];
0125             [x, f, s, out, lam] = qps_matpower(H, c, A, l, u, xmin, [], x0, opt);
0126             t_is(s, 1, 12, [t 'success']);
0127             t_is(x, [2; 4]/3, 7, [t 'x']);
0128             t_is(f, -74/9, 6, [t 'f']);
0129             t_is(lam.mu_l, [0;0;0], 13, [t 'lam.mu_l']);
0130             t_is(lam.mu_u, [28;4;0]/9, 4, [t 'lam.mu_u']);
0131             if strcmp(algs{k}, 'CLP') && ~have_fcn('opti_clp')
0132                 t_skip(2, [t 'lam.lower/upper : MEXCLP does not return multipliers on var bounds']);
0133             else
0134                 t_is(lam.lower, zeros(size(x)), 7, [t 'lam.lower']);
0135                 t_is(lam.upper, zeros(size(x)), 13, [t 'lam.upper']);
0136             end
0137 
0138             t = sprintf('%s - constrained 4-d QP : ', names{k});
0139             %% from https://v8doc.sas.com/sashtml/iml/chap8/sect12.htm
0140             H = [   1003.1  4.3     6.3     5.9;
0141                     4.3     2.2     2.1     3.9;
0142                     6.3     2.1     3.5     4.8;
0143                     5.9     3.9     4.8     10  ];
0144             c = zeros(4,1);
0145             A = [   1       1       1       1;
0146                     0.17    0.11    0.10    0.18    ];
0147             l = [1; 0.10];
0148             u = [1; Inf];
0149             xmin = zeros(4,1);
0150             x0 = [1; 0; 0; 1];
0151             [x, f, s, out, lam] = qps_matpower(H, c, A, l, u, xmin, [], x0, opt);
0152             t_is(s, 1, 12, [t 'success']);
0153             t_is(x, [0; 2.8; 0.2; 0]/3, 5, [t 'x']);
0154             t_is(f, 3.29/3, 6, [t 'f']);
0155             t_is(lam.mu_l, [6.58;0]/3, 6, [t 'lam.mu_l']);
0156             t_is(lam.mu_u, [0;0], 13, [t 'lam.mu_u']);
0157             if strcmp(algs{k}, 'CLP') && ~have_fcn('opti_clp')
0158                 t_skip(2, [t 'lam.lower/upper : MEXCLP does not return multipliers on var bounds']);
0159             else
0160                 t_is(lam.lower, [2.24;0;0;1.7667], 4, [t 'lam.lower']);
0161                 t_is(lam.upper, zeros(size(x)), 13, [t 'lam.upper']);
0162             end
0163 
0164             t = sprintf('%s - (struct) constrained 4-d QP : ', names{k});
0165             p = struct('H', H, 'A', A, 'l', l, 'u', u, 'xmin', xmin, 'x0', x0, 'opt', opt);
0166             [x, f, s, out, lam] = qps_matpower(p);
0167             t_is(s, 1, 12, [t 'success']);
0168             t_is(x, [0; 2.8; 0.2; 0]/3, 5, [t 'x']);
0169             t_is(f, 3.29/3, 6, [t 'f']);
0170             t_is(lam.mu_l, [6.58;0]/3, 6, [t 'lam.mu_l']);
0171             t_is(lam.mu_u, [0;0], 13, [t 'lam.mu_u']);
0172             if strcmp(algs{k}, 'CLP') && ~have_fcn('opti_clp')
0173                 t_skip(2, [t 'lam.lower/upper : MEXCLP does not return multipliers on var bounds']);
0174             else
0175                 t_is(lam.lower, [2.24;0;0;1.7667], 4, [t 'lam.lower']);
0176                 t_is(lam.upper, zeros(size(x)), 13, [t 'lam.upper']);
0177             end
0178         else
0179             t_skip(nqp, sprintf('%s does not handle QP problems', names{k}));
0180         end
0181 
0182         t = sprintf('%s - infeasible LP : ', names{k});
0183         p = struct('A', sparse([1 1]), 'c', [1;1], 'u', -1, 'xmin', [0;0], 'opt', opt);
0184         [x, f, s, out, lam] = qps_matpower(p);
0185         t_ok(s <= 0, [t 'no success']);
0186     end
0187 end
0188 
0189 if have_fcn('quadprog') && have_fcn('quadprog', 'vnum') == 7.005
0190     warning(s1.state, diff_alg_warn_id);
0191 end
0192 
0193 t_end;

Generated on Mon 24-Jun-2019 15:58:45 by m2html © 2005