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 = {'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
0055
0056 if strcmp(names{k}, 'CPLEX')
0057
0058 alg = 2;
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
0064 mpopt = mpoption;
0065
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
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
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
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
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;