0001 function t_qps_matpower(quiet)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033 if nargin < 1
0034 quiet = 0;
0035 end
0036
0037 algs = [100 200 250 400 300 500 600];
0038 names = {'BPMPD_MEX', 'MIPS', 'sc-MIPS', 'IPOPT', 'quadprog', 'CPLEX', 'MOSEK'};
0039 check = {'bpmpd', [], [], 'ipopt', 'quadprog', 'cplex', 'mosek'};
0040
0041 n = 36;
0042 t_begin(n*length(algs), quiet);
0043
0044 for k = 1:length(algs)
0045 if ~isempty(check{k}) && ~have_fcn(check{k})
0046 t_skip(n, sprintf('%s not installed', names{k}));
0047 else
0048 opt = struct('verbose', 0, 'alg', algs(k));
0049 if strcmp(names{k}, 'MIPS') || strcmp(names{k}, 'sc-MIPS')
0050 opt.mips_opt.comptol = 1e-8;
0051 end
0052
0053
0054 if strcmp(names{k}, 'CPLEX')
0055
0056 alg = 2;
0057 mpopt = mpoption('CPLEX_LPMETHOD', alg, 'CPLEX_QPMETHOD', min([4 alg]));
0058 opt.cplex_opt = cplex_options([], mpopt);
0059 end
0060 if strcmp(names{k}, 'MOSEK')
0061
0062 mpopt = mpoption;
0063
0064 mpopt = mpoption(mpopt, 'MOSEK_GAP_TOL', 1e-9);
0065 opt.mosek_opt = mosek_options([], mpopt);
0066 end
0067
0068 t = sprintf('%s - 3-d LP : ', names{k});
0069
0070 c = [-5; -4; -6];
0071 A = [1 -1 1;
0072 3 2 4;
0073 3 2 0];
0074 l = [];
0075 u = [20; 42; 30];
0076 xmin = [0; 0; 0];
0077 x0 = [];
0078 [x, f, s, out, lam] = qps_matpower([], c, A, l, u, xmin, [], [], opt);
0079 t_is(s, 1, 12, [t 'success']);
0080 t_is(x, [0; 15; 3], 6, [t 'x']);
0081 t_is(f, -78, 6, [t 'f']);
0082 t_is(lam.mu_l, [0;0;0], 13, [t 'lam.mu_l']);
0083 t_is(lam.mu_u, [0;1.5;0.5], 9, [t 'lam.mu_u']);
0084 t_is(lam.lower, [1;0;0], 9, [t 'lam.lower']);
0085 t_is(lam.upper, zeros(size(x)), 13, [t 'lam.upper']);
0086
0087 t = sprintf('%s - unconstrained 3-d quadratic : ', names{k});
0088
0089 H = [5 -2 -1; -2 4 3; -1 3 5];
0090 c = [2; -35; -47];
0091 x0 = [0; 0; 0];
0092 [x, f, s, out, lam] = qps_matpower(H, c, [], [], [], [], [], [], opt);
0093 t_is(s, 1, 12, [t 'success']);
0094 t_is(x, [3; 5; 7], 8, [t 'x']);
0095 t_is(f, -249, 13, [t 'f']);
0096 t_ok(isempty(lam.mu_l), [t 'lam.mu_l']);
0097 t_ok(isempty(lam.mu_u), [t 'lam.mu_u']);
0098 t_is(lam.lower, zeros(size(x)), 13, [t 'lam.lower']);
0099 t_is(lam.upper, zeros(size(x)), 13, [t 'lam.upper']);
0100
0101 t = sprintf('%s - constrained 2-d QP : ', names{k});
0102
0103 H = [ 1 -1;
0104 -1 2 ];
0105 c = [-2; -6];
0106 A = [ 1 1;
0107 -1 2;
0108 2 1 ];
0109 l = [];
0110 u = [2; 2; 3];
0111 xmin = [0; 0];
0112 x0 = [];
0113 [x, f, s, out, lam] = qps_matpower(H, c, A, l, u, xmin, [], x0, opt);
0114 t_is(s, 1, 12, [t 'success']);
0115 t_is(x, [2; 4]/3, 7, [t 'x']);
0116 t_is(f, -74/9, 6, [t 'f']);
0117 t_is(lam.mu_l, [0;0;0], 13, [t 'lam.mu_l']);
0118 t_is(lam.mu_u, [28;4;0]/9, 7, [t 'lam.mu_u']);
0119 t_is(lam.lower, zeros(size(x)), 8, [t 'lam.lower']);
0120 t_is(lam.upper, zeros(size(x)), 13, [t 'lam.upper']);
0121
0122 t = sprintf('%s - constrained 4-d QP : ', names{k});
0123
0124 H = [ 1003.1 4.3 6.3 5.9;
0125 4.3 2.2 2.1 3.9;
0126 6.3 2.1 3.5 4.8;
0127 5.9 3.9 4.8 10 ];
0128 c = zeros(4,1);
0129 A = [ 1 1 1 1;
0130 0.17 0.11 0.10 0.18 ];
0131 l = [1; 0.10];
0132 u = [1; Inf];
0133 xmin = zeros(4,1);
0134 x0 = [1; 0; 0; 1];
0135 [x, f, s, out, lam] = qps_matpower(H, c, A, l, u, xmin, [], x0, opt);
0136 t_is(s, 1, 12, [t 'success']);
0137 t_is(x, [0; 2.8; 0.2; 0]/3, 5, [t 'x']);
0138 t_is(f, 3.29/3, 6, [t 'f']);
0139 t_is(lam.mu_l, [6.58;0]/3, 6, [t 'lam.mu_l']);
0140 t_is(lam.mu_u, [0;0], 13, [t 'lam.mu_u']);
0141 t_is(lam.lower, [2.24;0;0;1.7667], 4, [t 'lam.lower']);
0142 t_is(lam.upper, zeros(size(x)), 13, [t 'lam.upper']);
0143
0144 t = sprintf('%s - (struct) constrained 4-d QP : ', names{k});
0145 p = struct('H', H, 'A', A, 'l', l, 'u', u, 'xmin', xmin, 'x0', x0, 'opt', opt);
0146 [x, f, s, out, lam] = qps_matpower(p);
0147 t_is(s, 1, 12, [t 'success']);
0148 t_is(x, [0; 2.8; 0.2; 0]/3, 5, [t 'x']);
0149 t_is(f, 3.29/3, 6, [t 'f']);
0150 t_is(lam.mu_l, [6.58;0]/3, 6, [t 'lam.mu_l']);
0151 t_is(lam.mu_u, [0;0], 13, [t 'lam.mu_u']);
0152 t_is(lam.lower, [2.24;0;0;1.7667], 4, [t 'lam.lower']);
0153 t_is(lam.upper, zeros(size(x)), 13, [t 'lam.upper']);
0154
0155 t = sprintf('%s - infeasible LP : ', names{k});
0156 p = struct('A', sparse([1 1]), 'c', [1;1], 'u', -1, 'xmin', [0;0], 'opt', opt);
0157 [x, f, s, out, lam] = qps_matpower(p);
0158 t_ok(s <= 0, [t 'no success']);
0159 end
0160 end
0161
0162 t_end;