Home > matpower7.0 > lib > t > t_opf_mips.m

t_opf_mips

PURPOSE ^

T_OPF_MIPS Tests for MIPS-based AC optimal power flow.

SYNOPSIS ^

function t_opf_mips(quiet)

DESCRIPTION ^

T_OPF_MIPS  Tests for MIPS-based AC optimal power flow.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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

Generated on Mon 24-Jun-2019 15:58:45 by m2html © 2005