Home > matpower7.1 > 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-2020, 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     t_is(lam.lower, [1;0;0], 9, [t 'lam.lower']);
0048     t_is(lam.upper, zeros(size(x)), 9, [t 'lam.upper']);
0049 
0050     t = sprintf('%s - unconstrained 3-d quadratic : ', names{k});
0051     %% from http://www.akiti.ca/QuadProgEx0Constr.html
0052     H = [5 -2 -1; -2 4 3; -1 3 5];
0053     c = [2; -35; -47];
0054     x0 = [0; 0; 0];
0055     [x, f, s, out, lam] = qps_mips(H, c, [], [], [], [], [], [], opt);
0056     t_is(s, 1, 12, [t 'success']);
0057     t_is(x, [3; 5; 7], 8, [t 'x']);
0058     t_is(f, -249, 13, [t 'f']);
0059     t_ok(isempty(lam.mu_l), [t 'lam.mu_l']);
0060     t_ok(isempty(lam.mu_u), [t 'lam.mu_u']);
0061     t_is(lam.lower, zeros(size(x)), 13, [t 'lam.lower']);
0062     t_is(lam.upper, zeros(size(x)), 13, [t 'lam.upper']);
0063 
0064     t = sprintf('%s - constrained 2-d QP : ', names{k});
0065     %% example from 'doc quadprog'
0066     H = [   1   -1;
0067             -1  2   ];
0068     c = [-2; -6];
0069     A = [   1   1;
0070             -1  2;
0071             2   1   ];
0072     l = [];
0073     u = [2; 2; 3];
0074     xmin = [0; 0];
0075     x0 = [];
0076     [x, f, s, out, lam] = qps_mips(H, c, A, l, u, xmin, [], x0, opt);
0077     t_is(s, 1, 12, [t 'success']);
0078     t_is(x, [2; 4]/3, 7, [t 'x']);
0079     t_is(f, -74/9, 6, [t 'f']);
0080     t_is(lam.mu_l, [0;0;0], 13, [t 'lam.mu_l']);
0081     t_is(lam.mu_u, [28;4;0]/9, 4, [t 'lam.mu_u']);
0082     t_is(lam.lower, zeros(size(x)), 7, [t 'lam.lower']);
0083     t_is(lam.upper, zeros(size(x)), 13, [t 'lam.upper']);
0084 
0085     t = sprintf('%s - constrained 4-d QP : ', names{k});
0086     %% from https://v8doc.sas.com/sashtml/iml/chap8/sect12.htm
0087     H = [   1003.1  4.3     6.3     5.9;
0088             4.3     2.2     2.1     3.9;
0089             6.3     2.1     3.5     4.8;
0090             5.9     3.9     4.8     10  ];
0091     c = zeros(4,1);
0092     A = [   1       1       1       1;
0093             0.17    0.11    0.10    0.18    ];
0094     l = [1; 0.10];
0095     u = [1; Inf];
0096     xmin = zeros(4,1);
0097     x0 = [1; 0; 0; 1];
0098     [x, f, s, out, lam] = qps_mips(H, c, A, l, u, xmin, [], x0, opt);
0099     t_is(s, 1, 12, [t 'success']);
0100     t_is(x, [0; 2.8; 0.2; 0]/3, 5, [t 'x']);
0101     t_is(f, 3.29/3, 6, [t 'f']);
0102     t_is(lam.mu_l, [6.58;0]/3, 6, [t 'lam.mu_l']);
0103     t_is(lam.mu_u, [0;0], 13, [t 'lam.mu_u']);
0104     t_is(lam.lower, [2.24;0;0;1.7667], 4, [t 'lam.lower']);
0105     t_is(lam.upper, zeros(size(x)), 13, [t 'lam.upper']);
0106 
0107     t = sprintf('%s - (struct) constrained 4-d QP : ', names{k});
0108     p = struct('H', H, 'A', A, 'l', l, 'u', u, 'xmin', xmin, 'x0', x0, 'opt', opt);
0109     [x, f, s, out, lam] = qps_mips(p);
0110     t_is(s, 1, 12, [t 'success']);
0111     t_is(x, [0; 2.8; 0.2; 0]/3, 5, [t 'x']);
0112     t_is(f, 3.29/3, 6, [t 'f']);
0113     t_is(lam.mu_l, [6.58;0]/3, 6, [t 'lam.mu_l']);
0114     t_is(lam.mu_u, [0;0], 13, [t 'lam.mu_u']);
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 
0118     t = sprintf('%s - infeasible LP : ', names{k});
0119     p = struct('A', sparse([1 1]), 'c', [1;1], 'u', -1, 'xmin', [0;0], 'opt', opt);
0120     [x, f, s, out, lam] = qps_mips(p);
0121     t_ok(s <= 0, [t 'no success']);
0122 end
0123 
0124 t_end;

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