0001 function t_opf_dc_mosek(quiet)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 if nargin < 1
0013 quiet = 0;
0014 end
0015
0016 s = have_feature('mosek', 'all');
0017
0018 if s.av
0019 sc = mosek_symbcon;
0020 if s.vnum < 7
0021 alg_names = {
0022 'default',
0023 'interior point',
0024 '<conic>',
0025 '<qcone>',
0026 'primal simplex',
0027 'dual simplex',
0028 'primal dual simplex',
0029 'automatic simplex',
0030 '<mixed int>',
0031 '<nonconvex>',
0032 'concurrent'
0033 };
0034 elseif s.vnum < 8
0035 alg_names = {
0036 'default',
0037 'interior point',
0038 '<conic>',
0039 'primal simplex',
0040 'dual simplex',
0041 'primal dual simplex',
0042 'automatic simplex',
0043 'network simplex',
0044 '<mixed int conic>',
0045 '<mixed int>',
0046 'concurrent',
0047 '<nonconvex>'
0048 };
0049 else
0050 alg_names = {
0051 '<conic>',
0052 'dual simplex',
0053 'default',
0054 'automatic simplex',
0055 'interior point',
0056 '<mixed int>',
0057 'primal simplex'
0058 };
0059 end
0060 algs = [
0061 sc.MSK_OPTIMIZER_FREE;
0062 sc.MSK_OPTIMIZER_INTPNT;
0063 sc.MSK_OPTIMIZER_PRIMAL_SIMPLEX;
0064 sc.MSK_OPTIMIZER_DUAL_SIMPLEX;
0065 sc.MSK_OPTIMIZER_FREE_SIMPLEX;
0066 ];
0067 if s.vnum < 8
0068 algs(end+1) = ...
0069 sc.MSK_OPTIMIZER_PRIMAL_DUAL_SIMPLEX;
0070 algs(end+1) = ...
0071 sc.MSK_OPTIMIZER_CONCURRENT;
0072 end
0073
0074
0075
0076
0077 else
0078 algs = 0;
0079 end
0080
0081 num_tests = 24 * length(algs);
0082
0083 t_begin(num_tests, quiet);
0084
0085 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0086 VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0087 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0088 MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0089 QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0090 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0091 TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0092 ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0093
0094 casefile = 't_case9_opf';
0095 if quiet
0096 verbose = 0;
0097 else
0098 verbose = 0;
0099 end
0100
0101 mpopt = mpoption('out.all', 0, 'verbose', verbose);
0102 mpopt = mpoption(mpopt, 'opf.dc.solver', 'MOSEK');
0103
0104
0105 if s.av
0106 for k = 1:length(algs)
0107 mpopt = mpoption(mpopt, 'mosek.lp_alg', algs(k));
0108 t0 = sprintf('DC OPF (MOSEK %s): ', alg_names{algs(k)+1});
0109
0110
0111 ib_data = [1:BUS_AREA BASE_KV:VMIN];
0112 ib_voltage = [VM VA];
0113 ib_lam = [LAM_P LAM_Q];
0114 ib_mu = [MU_VMAX MU_VMIN];
0115 ig_data = [GEN_BUS QMAX QMIN MBASE:APF];
0116 ig_disp = [PG QG VG];
0117 ig_mu = (MU_PMAX:MU_QMIN);
0118 ibr_data = (1:ANGMAX);
0119 ibr_flow = (PF:QT);
0120 ibr_mu = [MU_SF MU_ST];
0121 ibr_angmu = [MU_ANGMIN MU_ANGMAX];
0122
0123
0124 load soln9_dcopf;
0125
0126
0127 t = t0;
0128 [baseMVA, bus, gen, gencost, branch, f, success, et] = rundcopf(casefile, mpopt);
0129 t_ok(success, [t 'success']);
0130 t_is(f, f_soln, 3, [t 'f']);
0131 t_is( bus(:,ib_data ), bus_soln(:,ib_data ), 10, [t 'bus data']);
0132 t_is( bus(:,ib_voltage), bus_soln(:,ib_voltage), 3, [t 'bus voltage']);
0133 t_is( bus(:,ib_lam ), bus_soln(:,ib_lam ), 3, [t 'bus lambda']);
0134 t_is( bus(:,ib_mu ), bus_soln(:,ib_mu ), 2, [t 'bus mu']);
0135 t_is( gen(:,ig_data ), gen_soln(:,ig_data ), 10, [t 'gen data']);
0136 t_is( gen(:,ig_disp ), gen_soln(:,ig_disp ), 3, [t 'gen dispatch']);
0137 t_is( gen(:,ig_mu ), gen_soln(:,ig_mu ), 3, [t 'gen mu']);
0138 t_is(branch(:,ibr_data ), branch_soln(:,ibr_data ), 10, [t 'branch data']);
0139 t_is(branch(:,ibr_flow ), branch_soln(:,ibr_flow ), 3, [t 'branch flow']);
0140 t_is(branch(:,ibr_mu ), branch_soln(:,ibr_mu ), 2, [t 'branch mu']);
0141
0142
0143
0144
0145
0146
0147 mpc = loadcase(casefile);
0148 mpc.A = sparse([1;1;1;2;2;2],[10;12;13;12;11;14],[-1;1;-1;1;-1;-1],2,14);
0149 mpc.u = [0; 0];
0150 mpc.l = [-Inf; -Inf];
0151 mpc.zl = [0; 0];
0152
0153 mpc.N = sparse([1;2], [13;14], [1;1], 2, 14);
0154 mpc.fparm = ones(2,1) * [1 0 0 1];
0155 mpc.H = sparse(2,2);
0156 mpc.Cw = [1000;1];
0157
0158 t = [t0 'w/extra constraints & costs 1 : '];
0159 [r, success] = rundcopf(mpc, mpopt);
0160 t_ok(success, [t 'success']);
0161 t_is(r.gen(1, PG), 116.15974, 5, [t 'Pg1 = 116.15974']);
0162 t_is(r.gen(3, PG), 116.15974, 5, [t 'Pg3 = 116.15974']);
0163 t_is(r.var.val.z, [0; 0.3348], 4, [t 'user vars']);
0164 t_is(r.cost.usr, 0.3348, 4, [t 'user costs']);
0165
0166
0167 mpc = loadcase(casefile);
0168 mpc.A = sparse([1;1;1;2;2;2],[19;21;25;21;20;26],[-1;1;-1;1;-1;-1],2,26);
0169 mpc.u = [0; 0];
0170 mpc.l = [-Inf; -Inf];
0171 mpc.zl = [0; 0];
0172
0173 mpc.N = sparse([1;2], [25;26], [1;1], 2, 26);
0174 mpc.fparm = ones(2,1) * [1 0 0 1];
0175 mpc.H = sparse(2,2);
0176 mpc.Cw = [1000;1];
0177
0178 t = [t0 'w/extra constraints & costs 2 : '];
0179 [r, success] = rundcopf(mpc, mpopt);
0180 t_ok(success, [t 'success']);
0181 t_is(r.gen(1, PG), 116.15974, 5, [t 'Pg1 = 116.15974']);
0182 t_is(r.gen(3, PG), 116.15974, 5, [t 'Pg3 = 116.15974']);
0183 t_is(r.var.val.z, [0; 0.3348], 4, [t 'user vars']);
0184 t_is(r.cost.usr, 0.3348, 4, [t 'user costs']);
0185
0186 t = [t0 'infeasible : '];
0187
0188 mpc = loadcase(casefile);
0189 mpc.A = sparse([1;1], [10;11], [1;1], 1, 14);
0190 mpc.u = Inf;
0191 mpc.l = 600;
0192 [r, success] = rundcopf(mpc, mpopt);
0193 t_ok(~success, [t 'no success']);
0194
0195
0196 t = [t0 'all buses isolated : '];
0197 mpc = loadcase(casefile);
0198 mpc.bus(:, BUS_TYPE) = NONE;
0199 try
0200 r = rundcopf(mpc, mpopt);
0201 t_is(r.success, 0, 12, [t 'success = 0']);
0202 catch
0203 t_ok(0, [t 'unexpected fatal error']);
0204 end
0205
0206 end
0207 else
0208 t_skip(num_tests, 'MOSEK not available');
0209 end
0210
0211 t_end;