0001 function t_opf_dc_cplex(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 = [0; 1; 2; 3; 4];
0038 num_tests = 23 * length(algs);
0039
0040 t_begin(num_tests, quiet);
0041
0042 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0043 VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0044 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0045 MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0046 QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0047 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0048 TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0049 ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0050
0051 casefile = 't_case9_opf';
0052 if quiet
0053 verbose = 0;
0054 else
0055 verbose = 0;
0056 end
0057
0058 mpopt = mpoption('OUT_ALL', 0, 'VERBOSE', verbose);
0059 mpopt = mpoption(mpopt, 'OPF_ALG_DC', 700);
0060
0061
0062 if have_fcn('gurobi')
0063 for k = 1:length(algs)
0064 mpopt = mpoption(mpopt, 'GRB_METHOD', algs(k));
0065 methods = {
0066 'automatic',
0067 'primal simplex',
0068 'dual simplex',
0069 'barrier',
0070 'concurrent',
0071 'deterministic concurrent',
0072 };
0073 t0 = sprintf('DC OPF (Gurobi %s): ', methods{k});
0074
0075
0076 ib_data = [1:BUS_AREA BASE_KV:VMIN];
0077 ib_voltage = [VM VA];
0078 ib_lam = [LAM_P LAM_Q];
0079 ib_mu = [MU_VMAX MU_VMIN];
0080 ig_data = [GEN_BUS QMAX QMIN MBASE:APF];
0081 ig_disp = [PG QG VG];
0082 ig_mu = (MU_PMAX:MU_QMIN);
0083 ibr_data = (1:ANGMAX);
0084 ibr_flow = (PF:QT);
0085 ibr_mu = [MU_SF MU_ST];
0086 ibr_angmu = [MU_ANGMIN MU_ANGMAX];
0087
0088
0089 load soln9_dcopf;
0090
0091
0092 t = t0;
0093 [baseMVA, bus, gen, gencost, branch, f, success, et] = rundcopf(casefile, mpopt);
0094 t_ok(success, [t 'success']);
0095 t_is(f, f_soln, 3, [t 'f']);
0096 t_is( bus(:,ib_data ), bus_soln(:,ib_data ), 10, [t 'bus data']);
0097 t_is( bus(:,ib_voltage), bus_soln(:,ib_voltage), 3, [t 'bus voltage']);
0098 t_is( bus(:,ib_lam ), bus_soln(:,ib_lam ), 3, [t 'bus lambda']);
0099 t_is( bus(:,ib_mu ), bus_soln(:,ib_mu ), 2, [t 'bus mu']);
0100 t_is( gen(:,ig_data ), gen_soln(:,ig_data ), 10, [t 'gen data']);
0101 t_is( gen(:,ig_disp ), gen_soln(:,ig_disp ), 3, [t 'gen dispatch']);
0102 t_is( gen(:,ig_mu ), gen_soln(:,ig_mu ), 3, [t 'gen mu']);
0103 t_is(branch(:,ibr_data ), branch_soln(:,ibr_data ), 10, [t 'branch data']);
0104 t_is(branch(:,ibr_flow ), branch_soln(:,ibr_flow ), 3, [t 'branch flow']);
0105 t_is(branch(:,ibr_mu ), branch_soln(:,ibr_mu ), 2, [t 'branch mu']);
0106
0107
0108
0109
0110
0111
0112 mpc = loadcase(casefile);
0113 mpc.A = sparse([1;1;1;2;2;2],[10;11;13;11;12;14],[-1;1;-1;1;-1;-1],2,14);
0114 mpc.u = [0; 0];
0115 mpc.l = [-Inf; -Inf];
0116 mpc.zl = [0; 0];
0117
0118 mpc.N = sparse([1;2], [13;14], [1;1], 2, 14);
0119 mpc.fparm = ones(2,1) * [1 0 0 1];
0120 mpc.H = sparse(2,2);
0121 mpc.Cw = [1000;1];
0122
0123 t = [t0 'w/extra constraints & costs 1 : '];
0124 [r, success] = rundcopf(mpc, mpopt);
0125 t_ok(success, [t 'success']);
0126 t_is(r.gen(1, PG), 116.15974, 5, [t 'Pg1 = 116.15974']);
0127 t_is(r.gen(2, PG), 116.15974, 5, [t 'Pg2 = 116.15974']);
0128 t_is(r.var.val.z, [0; 0.3348], 4, [t 'user vars']);
0129 t_is(r.cost.usr, 0.3348, 4, [t 'user costs']);
0130
0131
0132 mpc = loadcase(casefile);
0133 mpc.A = sparse([1;1;1;2;2;2],[19;20;25;20;21;26],[-1;1;-1;1;-1;-1],2,26);
0134 mpc.u = [0; 0];
0135 mpc.l = [-Inf; -Inf];
0136 mpc.zl = [0; 0];
0137
0138 mpc.N = sparse([1;2], [25;26], [1;1], 2, 26);
0139 mpc.fparm = ones(2,1) * [1 0 0 1];
0140 mpc.H = sparse(2,2);
0141 mpc.Cw = [1000;1];
0142
0143 t = [t0 'w/extra constraints & costs 2 : '];
0144 [r, success] = rundcopf(mpc, mpopt);
0145 t_ok(success, [t 'success']);
0146 t_is(r.gen(1, PG), 116.15974, 5, [t 'Pg1 = 116.15974']);
0147 t_is(r.gen(2, PG), 116.15974, 5, [t 'Pg2 = 116.15974']);
0148 t_is(r.var.val.z, [0; 0.3348], 4, [t 'user vars']);
0149 t_is(r.cost.usr, 0.3348, 4, [t 'user costs']);
0150
0151 t = [t0 'infeasible : '];
0152
0153 mpc = loadcase(casefile);
0154 mpc.A = sparse([1;1], [10;11], [1;1], 1, 14);
0155 mpc.u = Inf;
0156 mpc.l = 600;
0157 [r, success] = rundcopf(mpc, mpopt);
0158 t_ok(~success, [t 'no success']);
0159
0160 end
0161 else
0162 t_skip(num_tests, 'CPLEX not available');
0163 end
0164
0165 t_end;