0001 function t_qps_mips(quiet)
0002
0003
0004
0005
0006
0007
0008
0009
0010
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
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
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
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
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;