Home > matpower7.0 > mips > lib > t > t_qps_mips.m

t_qps_mips

PURPOSE ^

T_QPS_MIPS Tests of QPS_MIPS QP solver.

SYNOPSIS ^

function t_qps_mips(quiet)

DESCRIPTION ^

T_QPS_MIPS  Tests of QPS_MIPS QP solver.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function t_qps_mips(quiet)
0002 %T_QPS_MIPS  Tests of QPS_MIPS QP solver.
0003 
0004 %   MIPS
0005 %   Copyright (c) 2010-2016, Power Systems Engineering Research Center (PSERC)
0006 %   by Ray Zimmerman, PSERC Cornell
0007 %
0008 %   This file is part of MIPS.
0009 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0010 %   See https://github.com/MATPOWER/mips for more info.
0011 
0012 if nargin < 1
0013     quiet = 0;
0014 end
0015 
0016 algs = {'MIPS', 250};
0017 names = {'MIPS', 'sc-MIPS'};
0018 check = {[], []};
0019 does_qp = [1 1];
0020 
0021 n = 36;
0022 nqp = 28;
0023 t_begin(n*length(algs), quiet);
0024 
0025 for k = 1:length(algs)
0026     opt = struct('verbose', 0, 'alg', algs{k});
0027     if strcmp(names{k}, 'MIPS') || strcmp(names{k}, 'sc-MIPS')
0028         opt.comptol = 1e-8;
0029     end
0030 
0031     t = sprintf('%s - 3-d LP : ', names{k});
0032     %% based on example from 'doc linprog'
0033     c = [-5; -4; -6];
0034     A = [1 -1  1;
0035          -3  -2  -4;
0036          3  2  0];
0037     l = [-Inf; -42; -Inf];
0038     u = [20; Inf; 30];
0039     xmin = [0; 0; 0];
0040     x0 = [];
0041     [x, f, s, out, lam] = qps_mips([], c, A, l, u, xmin, [], [], opt);
0042     t_is(s, 1, 12, [t 'success']);
0043     t_is(x, [0; 15; 3], 6, [t 'x']);
0044     t_is(f, -78, 6, [t 'f']);
0045     t_is(lam.mu_l, [0;1.5;0], 9, [t 'lam.mu_l']);
0046     t_is(lam.mu_u, [0;0;0.5], 9, [t 'lam.mu_u']);
0047     if strcmp(algs{k}, 'CLP') && ~have_fcn('opti_clp')
0048         t_skip(2, [t 'lam.lower/upper : MEXCLP does not return multipliers on var bounds']);
0049     else
0050         t_is(lam.lower, [1;0;0], 9, [t 'lam.lower']);
0051         t_is(lam.upper, zeros(size(x)), 9, [t 'lam.upper']);
0052     end
0053 
0054     t = sprintf('%s - unconstrained 3-d quadratic : ', names{k});
0055     %% from http://www.akiti.ca/QuadProgEx0Constr.html
0056     H = [5 -2 -1; -2 4 3; -1 3 5];
0057     c = [2; -35; -47];
0058     x0 = [0; 0; 0];
0059     [x, f, s, out, lam] = qps_mips(H, c, [], [], [], [], [], [], opt);
0060     t_is(s, 1, 12, [t 'success']);
0061     t_is(x, [3; 5; 7], 8, [t 'x']);
0062     t_is(f, -249, 13, [t 'f']);
0063     t_ok(isempty(lam.mu_l), [t 'lam.mu_l']);
0064     t_ok(isempty(lam.mu_u), [t 'lam.mu_u']);
0065     t_is(lam.lower, zeros(size(x)), 13, [t 'lam.lower']);
0066     t_is(lam.upper, zeros(size(x)), 13, [t 'lam.upper']);
0067 
0068     t = sprintf('%s - constrained 2-d QP : ', names{k});
0069     %% example from 'doc quadprog'
0070     H = [   1   -1;
0071             -1  2   ];
0072     c = [-2; -6];
0073     A = [   1   1;
0074             -1  2;
0075             2   1   ];
0076     l = [];
0077     u = [2; 2; 3];
0078     xmin = [0; 0];
0079     x0 = [];
0080     [x, f, s, out, lam] = qps_mips(H, c, A, l, u, xmin, [], x0, opt);
0081     t_is(s, 1, 12, [t 'success']);
0082     t_is(x, [2; 4]/3, 7, [t 'x']);
0083     t_is(f, -74/9, 6, [t 'f']);
0084     t_is(lam.mu_l, [0;0;0], 13, [t 'lam.mu_l']);
0085     t_is(lam.mu_u, [28;4;0]/9, 4, [t 'lam.mu_u']);
0086     if strcmp(algs{k}, 'CLP') && ~have_fcn('opti_clp')
0087         t_skip(2, [t 'lam.lower/upper : MEXCLP does not return multipliers on var bounds']);
0088     else
0089         t_is(lam.lower, zeros(size(x)), 7, [t 'lam.lower']);
0090         t_is(lam.upper, zeros(size(x)), 13, [t 'lam.upper']);
0091     end
0092 
0093     t = sprintf('%s - constrained 4-d QP : ', names{k});
0094     %% from https://v8doc.sas.com/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     [x, f, s, out, lam] = qps_mips(H, c, A, l, u, xmin, [], x0, opt);
0107     t_is(s, 1, 12, [t 'success']);
0108     t_is(x, [0; 2.8; 0.2; 0]/3, 5, [t 'x']);
0109     t_is(f, 3.29/3, 6, [t 'f']);
0110     t_is(lam.mu_l, [6.58;0]/3, 6, [t 'lam.mu_l']);
0111     t_is(lam.mu_u, [0;0], 13, [t 'lam.mu_u']);
0112     if strcmp(algs{k}, 'CLP') && ~have_fcn('opti_clp')
0113         t_skip(2, [t 'lam.lower/upper : MEXCLP does not return multipliers on var bounds']);
0114     else
0115         t_is(lam.lower, [2.24;0;0;1.7667], 4, [t 'lam.lower']);
0116         t_is(lam.upper, zeros(size(x)), 13, [t 'lam.upper']);
0117     end
0118 
0119     t = sprintf('%s - (struct) constrained 4-d QP : ', names{k});
0120     p = struct('H', H, 'A', A, 'l', l, 'u', u, 'xmin', xmin, 'x0', x0, 'opt', opt);
0121     [x, f, s, out, lam] = qps_mips(p);
0122     t_is(s, 1, 12, [t 'success']);
0123     t_is(x, [0; 2.8; 0.2; 0]/3, 5, [t 'x']);
0124     t_is(f, 3.29/3, 6, [t 'f']);
0125     t_is(lam.mu_l, [6.58;0]/3, 6, [t 'lam.mu_l']);
0126     t_is(lam.mu_u, [0;0], 13, [t 'lam.mu_u']);
0127     if strcmp(algs{k}, 'CLP') && ~have_fcn('opti_clp')
0128         t_skip(2, [t 'lam.lower/upper : MEXCLP does not return multipliers on var bounds']);
0129     else
0130         t_is(lam.lower, [2.24;0;0;1.7667], 4, [t 'lam.lower']);
0131         t_is(lam.upper, zeros(size(x)), 13, [t 'lam.upper']);
0132     end
0133 
0134     t = sprintf('%s - infeasible LP : ', names{k});
0135     p = struct('A', sparse([1 1]), 'c', [1;1], 'u', -1, 'xmin', [0;0], 'opt', opt);
0136     [x, f, s, out, lam] = qps_mips(p);
0137     t_ok(s <= 0, [t 'no success']);
0138 end
0139 
0140 t_end;

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