Home > matpower7.1 > lib > t > t_opf_minopf.m

t_opf_minopf

PURPOSE ^

T_OPF_MINOPF Tests for MINOS-based optimal power flow.

SYNOPSIS ^

function t_opf_minopf(quiet)

DESCRIPTION ^

T_OPF_MINOPF  Tests for MINOS-based optimal power flow.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function t_opf_minopf(quiet)
0002 %T_OPF_MINOPF  Tests for MINOS-based optimal power flow.
0003 
0004 %   MATPOWER
0005 %   Copyright (c) 2004-2017, Power Systems Engineering Research Center (PSERC)
0006 %   by Ray Zimmerman, PSERC Cornell
0007 %
0008 %   This file is part of MATPOWER.
0009 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0010 %   See https://matpower.org for more info.
0011 
0012 if nargin < 1
0013     quiet = 0;
0014 end
0015 
0016 num_tests = 136;
0017 
0018 t_begin(num_tests, quiet);
0019 
0020 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0021     VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0022 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0023     MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0024     QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0025 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0026     TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0027     ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0028 [PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost;
0029 
0030 casefile = 't_case9_opf';
0031 if quiet
0032     verbose = 0;
0033 else
0034     verbose = 0;
0035 end
0036 
0037 t0 = 'MINOPF : ';
0038 mpopt = mpoption('opf.violation', 1e-6, 'minopf.xtol', 1e-6);
0039 mpopt = mpoption(mpopt, 'out.all', 0, 'verbose', verbose, 'opf.ac.solver', 'MINOPF');
0040 
0041 if have_feature('minopf')
0042     %% set up indices
0043     ib_data     = [1:BUS_AREA BASE_KV:VMIN];
0044     ib_voltage  = [VM VA];
0045     ib_lam      = [LAM_P LAM_Q];
0046     ib_mu       = [MU_VMAX MU_VMIN];
0047     ig_data     = [GEN_BUS QMAX QMIN MBASE:APF];
0048     ig_disp     = [PG QG VG];
0049     ig_mu       = (MU_PMAX:MU_QMIN);
0050     ibr_data    = (1:ANGMAX);
0051     ibr_flow    = (PF:QT);
0052     ibr_mu      = [MU_SF MU_ST];
0053     ibr_angmu   = [MU_ANGMIN MU_ANGMAX];
0054 
0055     %% get solved AC OPF case from MAT-file
0056     load soln9_opf;     %% defines bus_soln, gen_soln, branch_soln, f_soln
0057 
0058     %% run OPF
0059     t = t0;
0060     [baseMVA, bus, gen, gencost, branch, f, success, et] = runopf(casefile, mpopt);
0061     t_ok(success, [t 'success']);
0062     t_is(f, f_soln, 3, [t 'f']);
0063     t_is(   bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0064     t_is(   bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0065     t_is(   bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0066     t_is(   bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  2, [t 'bus mu']);
0067     t_is(   gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0068     t_is(   gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0069     t_is(   gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0070     t_is(branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0071     t_is(branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0072     t_is(branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0073 
0074     %% run with automatic conversion of single-block pwl to linear costs
0075     t = [t0 '(single-block PWL) : '];
0076     mpc = loadcase(casefile);
0077     mpc.gencost(2, NCOST) = 2;
0078     [r, success] = runopf(mpc, mpopt);
0079     [f, bus, gen, branch] = deal(r.f, r.bus, r.gen, r.branch);
0080     t_ok(success, [t 'success']);
0081     t_is(f, f_soln, 3, [t 'f']);
0082     t_is(   bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0083     t_is(   bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0084     t_is(   bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0085     t_is(   bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  2, [t 'bus mu']);
0086     t_is(   gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0087     t_is(   gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0088     t_is(   gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0089     t_is(branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0090     t_is(branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0091     t_is(branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0092     xr = [r.var.val.Va;r.var.val.Vm;r.var.val.Pg;r.var.val.Qg;0;r.var.val.y];
0093     t_is(r.x, xr, 8, [t 'raw x returned from OPF']);
0094 
0095 %     %% get solved AC OPF case from MAT-file
0096 %     load soln9_opf_Plim;       %% defines bus_soln, gen_soln, branch_soln, f_soln
0097 %
0098 %     %% run OPF with active power line limits
0099 %     t = [t0 '(P line lim) : '];
0100 %     mpopt1 = mpoption(mpopt, 'opf.flow_lim', 'P');
0101 %     [baseMVA, bus, gen, gencost, branch, f, success, et] = runopf(casefile, mpopt1);
0102 %     t_ok(success, [t 'success']);
0103 %     t_is(f, f_soln, 3, [t 'f']);
0104 %     t_is(   bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0105 %     t_is(   bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0106 %     t_is(   bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0107 %     t_is(   bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  2, [t 'bus mu']);
0108 %     t_is(   gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0109 %     t_is(   gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0110 %     t_is(   gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0111 %     t_is(branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0112 %     t_is(branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0113 %     t_is(branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0114 %
0115 %     %% run OPF with active power line limits
0116 %     t = [t0 '(P^2 line lim) : '];
0117 %     mpopt1 = mpoption(mpopt, 'opf.flow_lim', '2');
0118 %     [baseMVA, bus, gen, gencost, branch, f, success, et] = runopf(casefile, mpopt1);
0119 %     t_ok(success, [t 'success']);
0120 %     t_is(f, f_soln, 3, [t 'f']);
0121 %     t_is(   bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0122 %     t_is(   bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0123 %     t_is(   bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0124 %     t_is(   bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  2, [t 'bus mu']);
0125 %     t_is(   gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0126 %     t_is(   gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0127 %     t_is(   gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0128 %     t_is(branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0129 %     t_is(branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0130 %     t_is(branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0131 
0132     %%-----  test OPF with quadratic gen costs moved to generalized costs  -----
0133     mpc = loadcase(casefile);
0134     mpc.gencost = [
0135         2   1500    0   3   0.11    5   0;
0136         2   2000    0   3   0.085   1.2 0;
0137         2   3000    0   3   0.1225  1   0;
0138     ];
0139     [baseMVA, bus_soln, gen_soln, gencost, branch_soln, f_soln, success, et] = runopf(mpc, mpopt);
0140     branch_soln = branch_soln(:,1:MU_ST);
0141 
0142     A = sparse(0,0);
0143     l = [];
0144     u = [];
0145     nb = size(mpc.bus, 1);      % number of buses
0146     ng = size(mpc.gen, 1);      % number of gens
0147     thbas = 1;                thend    = thbas+nb-1;
0148     vbas     = thend+1;       vend     = vbas+nb-1;
0149     pgbas    = vend+1;        pgend    = pgbas+ng-1;
0150     qgbas    = pgend+1;       qgend    = qgbas+ng-1;
0151     nxyz = 2*nb + 2*ng;
0152     N = sparse((1:ng)', (pgbas:pgend)', mpc.baseMVA * ones(ng,1), ng, nxyz);
0153     fparm = [ 1    0   0 1;
0154               1 -100 100 1;
0155               1  -10  10 1 ];
0156     H = 2 * spdiags(mpc.gencost(:, 5), 0, ng, ng);
0157     Cw = mpc.gencost(:, 6);
0158     mpc.gencost(:, 5:7) = 0;
0159 
0160     %% run OPF with quadratic gen costs moved to generalized costs
0161     t = [t0 'w/quadratic generalized gen cost : '];
0162     [r, success] = opf(mpc, A, l, u, mpopt, N, fparm, H, Cw);
0163     [f, bus, gen, branch] = deal(r.f, r.bus, r.gen, r.branch);
0164     t_ok(success, [t 'success']);
0165     t_is(f, f_soln, 3, [t 'f']);
0166     t_is(   bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0167     t_is(   bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0168     t_is(   bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0169     t_is(   bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  2, [t 'bus mu']);
0170     t_is(   gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0171     t_is(   gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0172     t_is(   gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0173     t_is(branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0174     t_is(branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0175     t_is(branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0176     t_is(r.cost.usr, f, 12, [t 'user cost']);
0177 
0178 % DOES NOT CONVERGE
0179 %     %%-----  run OPF with legacy costs and deadzone  -----
0180 %     load soln9_opf;
0181 %     mpc = loadcase(casefile);
0182 %     mpc.N = sparse((1:nb)', (vbas:vend)', ones(nb,1), nb, nxyz);
0183 %     mpc.fparm = ones(nb,1) * [ 2 1.08 0.01 1e8 ];
0184 %     mpc.Cw = ones(nb, 1);
0185 %     t = [t0 'w/legacy cost, in deadzone : '];
0186 %     r = runopf(mpc, mpopt);
0187 %     [f, bus, gen, branch] = deal(r.f, r.bus, r.gen, r.branch);
0188 %     t_ok(r.success, [t 'success']);
0189 %     t_is(f, f_soln, 3, [t 'f']);
0190 %     t_is(   bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0191 %     t_is(   bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0192 %     t_is(   bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0193 %     t_is(   bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  2, [t 'bus mu']);
0194 %     t_is(   gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0195 %     t_is(   gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0196 %     t_is(   gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0197 %     t_is(branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0198 %     t_is(branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0199 %     t_is(branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0200 %     t_is(r.cost.usr, 0, 12, [t 'user cost']);
0201 %
0202 %     t = [t0 'w/legacy cost, not in deadzone : '];
0203 %     mpc.fparm = ones(nb,1) * [ 2 1.08 0.01 1e8 ];
0204 %     r = runopf(mpc, mpopt);
0205 %     [f, bus, gen, branch] = deal(r.f, r.bus, r.gen, r.branch);
0206 %     t_ok(r.success, [t 'success']);
0207 %     t_is(f, 9009.0890, 3, [t 'f']);
0208 %     t_is([min(bus(:, VM)) mean(bus(:, VM)) max(bus(:, VM))], ...
0209 %         [1.066624, 1.083980, 1.091698], 5, [t 'bus voltage']);
0210 %     t_is(r.cost.usr, 1673.065465, 5, [t 'user cost']);
0211 
0212     %%-----  run OPF with extra linear user constraints & costs  -----
0213     %% single new z variable constrained to be greater than or equal to
0214     %% deviation from 1 pu voltage at bus 1, linear cost on this z
0215     %% get solved AC OPF case from MAT-file
0216     load soln9_opf_extras1;   %% defines bus_soln, gen_soln, branch_soln, f_soln
0217     A = sparse([1;1;2;2],[10;25;10;25],[-1;1;1;1],2,25);
0218     u = [Inf; Inf];
0219     l = [-1; 1];
0220 
0221     N = sparse(1, 25, 1, 1, 25);    %% new z variable only
0222     fparm = [1 0 0 1];              %% w = r = z
0223     H = sparse(1,1);                %% no quadratic term
0224     Cw = 100;
0225 
0226     t = [t0 'w/extra constraints & costs 1 : '];
0227     [r, success] = opf(casefile, A, l, u, mpopt, N, fparm, H, Cw);
0228     [f, bus, gen, branch] = deal(r.f, r.bus, r.gen, r.branch);
0229     t_ok(success, [t 'success']);
0230     t_is(f, f_soln, 3, [t 'f']);
0231     t_is(   bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0232     t_is(   bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0233     t_is(   bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0234     t_is(   bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  2, [t 'bus mu']);
0235     t_is(   gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0236     t_is(   gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0237     t_is(   gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0238     t_is(branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0239     t_is(branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0240     t_is(branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0241     t_is(r.var.val.z, 0.025419, 6, [t 'user variable']);
0242     t_is(r.cost.usr, 2.5419, 4, [t 'user cost']);
0243 
0244     %%-----  test OPF with capability curves  -----
0245     mpc = loadcase('t_case9_opfv2');
0246     %% remove angle diff limits
0247     mpc.branch(1, ANGMAX) = 360;
0248     mpc.branch(9, ANGMIN) = -360;
0249 
0250     %% get solved AC OPF case from MAT-file
0251     load soln9_opf_PQcap;   %% defines bus_soln, gen_soln, branch_soln, f_soln
0252     
0253     %% run OPF with capability curves
0254     t = [t0 'w/capability curves : '];
0255     [baseMVA, bus, gen, gencost, branch, f, success, et] = runopf(mpc, mpopt);
0256     t_ok(success, [t 'success']);
0257     t_is(f, f_soln, 3, [t 'f']);
0258     t_is(   bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0259     t_is(   bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0260     t_is(   bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0261     t_is(   bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  2, [t 'bus mu']);
0262     t_is(   gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0263     t_is(   gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0264     t_is(   gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0265     t_is(branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0266     t_is(branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0267     t_is(branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0268 
0269     %%-----  test OPF with angle difference limits  -----
0270     mpc = loadcase('t_case9_opfv2');
0271     %% remove capability curves
0272     mpc.gen(2:3, [PC1, PC2, QC1MIN, QC1MAX, QC2MIN, QC2MAX]) = zeros(2,6);
0273 
0274     %% get solved AC OPF case from MAT-file
0275     load soln9_opf_ang;   %% defines bus_soln, gen_soln, branch_soln, f_soln
0276     
0277     %% run OPF with angle difference limits
0278     t = [t0 'w/angle difference limits : '];
0279     [baseMVA, bus, gen, gencost, branch, f, success, et] = runopf(mpc, mpopt);
0280     t_ok(success, [t 'success']);
0281     t_is(f, f_soln, 3, [t 'f']);
0282     t_is(   bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0283     t_is(   bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0284     t_is(   bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0285     t_is(   bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  1, [t 'bus mu']);
0286     t_is(   gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0287     t_is(   gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0288     t_is(   gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0289     t_is(branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0290     t_is(branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0291     t_is(branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0292     t_is(branch(:,ibr_angmu ), branch_soln(:,ibr_angmu ),  2, [t 'branch angle mu']);
0293 
0294     %%-----  test OPF with ignored angle difference limits  -----
0295     %% get solved AC OPF case from MAT-file
0296     load soln9_opf;   %% defines bus_soln, gen_soln, branch_soln, f_soln
0297 
0298     %% run OPF with ignored angle difference limits
0299     t = [t0 'w/ignored angle difference limits : '];
0300     mpopt1 = mpoption(mpopt, 'opf.ignore_angle_lim', 1);
0301     [baseMVA, bus, gen, gencost, branch, f, success, et] = runopf(mpc, mpopt1);
0302     %% ang limits are not in this solution data, so let's remove them
0303     branch(1, ANGMAX) = 360;
0304     branch(9, ANGMIN) = -360;
0305     t_ok(success, [t 'success']);
0306     t_is(f, f_soln, 3, [t 'f']);
0307     t_is(   bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0308     t_is(   bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0309     t_is(   bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0310     t_is(   bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  2, [t 'bus mu']);
0311     t_is(   gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0312     t_is(   gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0313     t_is(   gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0314     t_is(branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0315     t_is(branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0316     t_is(branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0317 
0318     %% angle bounded above by 0, unbounded below
0319     %% for issue/18
0320     t = [t0 'w/angle difference limit = 0 : '];
0321     mpc = loadcase(casefile);
0322     b = 5;
0323     mpc.branch(b, ANGMAX) = 0;
0324     r = runopf(mpc, mpopt);
0325     t_ok(success, [t 'success']);
0326     diff = r.bus(r.branch(b, F_BUS), VA) - r.bus(r.branch(b, T_BUS), VA);
0327     t_is(diff, 0, 5, [t 'angle diff']);
0328 
0329     %%-----  OPF with ref bus not = bus 1, ref angle not = 0  -----
0330     t = [t0 'ref bus ~= 1, ref ang ~= 0 : '];
0331     mpc = loadcase(casefile);
0332     mpc.bus([1;3], BUS_TYPE) = [PV; REF];   %% swap bus types
0333     bus_soln([1;3], BUS_TYPE) = bus_soln([3;1], BUS_TYPE);   %% swap bus types
0334     mpc.bus(3, VA) = 3.3014277;
0335     r = runopf(mpc, mpopt);
0336     [success, f, bus, gen, branch] = deal(r.success, r.f, r.bus, r.gen, r.branch);
0337     t_ok(success, [t 'success']);
0338     t_is(f, f_soln, 3, [t 'f']);
0339     t_is(   bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0340     t_is(   bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0341     t_is(   bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0342     t_is(   bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  2, [t 'bus mu']);
0343     t_is(   gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0344     t_is(   gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0345     t_is(   gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0346     t_is(branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0347     t_is(branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0348     t_is(branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0349 
0350     %%-----  test OPF with opf.use_vg  -----
0351     %% get solved AC OPF case from MAT-file
0352     load soln9_opf_vg;  %% defines bus_soln, gen_soln, branch_soln, f_soln
0353                         %%    and bus_soln1, gen_soln1, branch_soln1, f_soln1
0354     
0355     %% run with opf.use_vg = 1
0356     t = [t0 'w/opf.use_vg = 1 : '];
0357     mpc = loadcase(casefile);
0358     mpc.gen = mpc.gen([1 2 1 3], :);
0359     mpc.gencost = mpc.gencost([1 2 1 3], :);
0360     mpc.gen([1 3], [PMAX PMIN]) = mpc.gen([1 3], [PMAX PMIN]) / 2;
0361     mpc.gen(3, [QMIN, QMAX]) = 0;   %% no reactive capability for gen 3
0362     mpc.gencost([1 3], COST:end) = mpc.gencost([1 3], COST:end) / 2;
0363     mpc.gen(1, VG) = 1.05;
0364     mpc.gen(3, VG) = 1.06;
0365     mpopt1 = mpoption(mpopt, 'opf.use_vg', 1);
0366     r = runopf(mpc, mpopt1);
0367     t_ok(r.success, [t 'success']);
0368     t_is(r.f, f_soln, 3, [t 'f']);
0369     t_is(   r.bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0370     t_is(   r.bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0371     t_is(   r.bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0372     t_is(   r.bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  2, [t 'bus mu']);
0373     t_is(   r.gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0374     t_is(   r.gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0375     t_is(   r.gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0376     t_is(r.branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0377     t_is(r.branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0378     t_is(r.branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0379 
0380     %% run with opf.use_vg = 0.9
0381     t = [t0 'w/opf.use_vg = 0.9 : '];
0382     mpopt1 = mpoption(mpopt, 'opf.use_vg', 0.9);
0383     r = runopf(mpc, mpopt1);
0384     t_ok(r.success, [t 'success']);
0385     t_is(r.f, f_soln1, 3, [t 'f']);
0386     t_is(   r.bus(:,ib_data   ),    bus_soln1(:,ib_data   ), 10, [t 'bus data']);
0387     t_is(   r.bus(:,ib_voltage),    bus_soln1(:,ib_voltage),  3, [t 'bus voltage']);
0388     t_is(   r.bus(:,ib_lam    ),    bus_soln1(:,ib_lam    ),  3, [t 'bus lambda']);
0389     t_is(   r.bus(:,ib_mu     ),    bus_soln1(:,ib_mu     ),  2, [t 'bus mu']);
0390     t_is(   r.gen(:,ig_data   ),    gen_soln1(:,ig_data   ), 10, [t 'gen data']);
0391     t_is(   r.gen(:,ig_disp   ),    gen_soln1(:,ig_disp   ),  3, [t 'gen dispatch']);
0392     t_is(   r.gen(:,ig_mu     ),    gen_soln1(:,ig_mu     ),  3, [t 'gen mu']);
0393     t_is(r.branch(:,ibr_data  ), branch_soln1(:,ibr_data  ), 10, [t 'branch data']);
0394     t_is(r.branch(:,ibr_flow  ), branch_soln1(:,ibr_flow  ),  3, [t 'branch flow']);
0395     t_is(r.branch(:,ibr_mu    ), branch_soln1(:,ibr_mu    ),  2, [t 'branch mu']);
0396 
0397     t = [t0 'hi-deg polynomial costs : '];
0398     mpc = loadcase(casefile);
0399     mpc.gencost = [
0400         2   1500    0   6   1e-6/5  0   0   0   0   0;
0401         2   3000    0   5   1e-4/4  0   0   0   0   0;
0402         2   2000    0   3   1/2     0   0   0   0   0;
0403     ];
0404     r = runopf(mpc, mpopt);
0405     [f, bus, gen, branch] = deal(r.f, r.bus, r.gen, r.branch);
0406     t_ok(r.success, [t 'success']);
0407     t_is(f, 11899.4652, 4, [t 'f']);
0408     t_is(gen(:, PG), [100.703628; 88.719864; 128.679485], 5, [t 'Pg']);
0409     t_is([min(bus(:, VM)) mean(bus(:, VM)) max(bus(:, VM))], ...
0410         [1.059191 1.079404 1.1], 5, [t 'bus voltage']);
0411 
0412 %     %% OPF with user-defined nonlinear constraints
0413 %     t = [t0 'w/nonlin eq constraint : '];
0414 %     mpc = loadcase('case30');
0415 %     mpc.user_constraints.nle = {
0416 %         {'Pg_usr', 1, 'opf_nle_fcn1', 'opf_nle_hess1', {'Pg'}, {}}
0417 %     };
0418 %     r = runopf(mpc, mpopt);
0419 %     t_ok(r.success, [t 'success']);
0420 %     t_is(r.gen(1, PG) * r.gen(2, PG) / 100, r.gen(6, PG), 8, t);
0421 %     t_is(r.gen(6, PG), 20.751163, 5, t);
0422 %     %% check for indexing error, issue #77
0423 %     t_is(r.raw.pimul(61), 0, 6, [t 'issue #77']);
0424 %     t_is(r.mu.nln.u(61), 0, 6, [t 'issue #77']);
0425 
0426     %% OPF with all buses isolated
0427     t = [t0 'all buses isolated : '];
0428     mpc.bus(:, BUS_TYPE) = NONE;
0429     try
0430         r = runopf(mpc, mpopt);
0431         t_is(r.success, 0, 12, [t 'success = 0']);
0432     catch
0433         t_ok(0, [t 'unexpected fatal error']);
0434     end
0435 
0436     %% OPF with no branch limits
0437     t = [t0 'w/no branch limits : '];
0438     mpc = loadcase(casefile);
0439     mpc.branch(:, RATE_A) = 0;
0440     r = runopf(mpc, mpopt);
0441     t_ok(r.success, [t 'success']);
0442     t_is(r.f, 5496.128635, 4, [t 'f']);
0443     t_is(r.gen(:, PG), [90; 220.463932; 10], 5, [t 'Pg']);
0444     t_is([min(r.bus(:, VM)) mean(r.bus(:, VM)) max(r.bus(:, VM))], ...
0445         [1.070692 1.090449 1.1], 5, [t 'bus voltage']);
0446 else
0447     t_skip(num_tests, [t0 'not available']);
0448 end
0449 
0450 t_end;

Generated on Fri 09-Oct-2020 11:21:31 by m2html © 2005