Home > matpower5.1 > 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-2015 by Power System Engineering Research Center (PSERC)
0006 %   by Ray Zimmerman, PSERC Cornell
0007 %
0008 %   $Id: t_opf_minopf.m 2644 2015-03-11 19:34:22Z ray $
0009 %
0010 %   This file is part of MATPOWER.
0011 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0012 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0013 
0014 if nargin < 1
0015     quiet = 0;
0016 end
0017 
0018 num_tests = 89;
0019 
0020 t_begin(num_tests, quiet);
0021 
0022 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0023     VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0024 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0025     MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0026     QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0027 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0028     TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0029     ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0030 [PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost;
0031 
0032 casefile = 't_case9_opf';
0033 if quiet
0034     verbose = 0;
0035 else
0036     verbose = 0;
0037 end
0038 
0039 t0 = 'MINOPF : ';
0040 mpopt = mpoption('opf.violation', 1e-6, 'minopf.xtol', 1e-6);
0041 mpopt = mpoption(mpopt, 'out.all', 0, 'verbose', verbose, 'opf.ac.solver', 'MINOPF');
0042 
0043 if have_fcn('minopf')
0044     %% set up indices
0045     ib_data     = [1:BUS_AREA BASE_KV:VMIN];
0046     ib_voltage  = [VM VA];
0047     ib_lam      = [LAM_P LAM_Q];
0048     ib_mu       = [MU_VMAX MU_VMIN];
0049     ig_data     = [GEN_BUS QMAX QMIN MBASE:APF];
0050     ig_disp     = [PG QG VG];
0051     ig_mu       = (MU_PMAX:MU_QMIN);
0052     ibr_data    = (1:ANGMAX);
0053     ibr_flow    = (PF:QT);
0054     ibr_mu      = [MU_SF MU_ST];
0055     ibr_angmu   = [MU_ANGMIN MU_ANGMAX];
0056 
0057     %% get solved AC power flow case from MAT-file
0058     load soln9_opf;     %% defines bus_soln, gen_soln, branch_soln, f_soln
0059 
0060     %% run OPF
0061     t = t0;
0062     [baseMVA, bus, gen, gencost, branch, f, success, et] = runopf(casefile, mpopt);
0063     t_ok(success, [t 'success']);
0064     t_is(f, f_soln, 3, [t 'f']);
0065     t_is(   bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0066     t_is(   bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0067     t_is(   bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0068     t_is(   bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  2, [t 'bus mu']);
0069     t_is(   gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0070     t_is(   gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0071     t_is(   gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0072     t_is(branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0073     t_is(branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0074     t_is(branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0075 
0076     %% run with automatic conversion of single-block pwl to linear costs
0077     t = [t0 '(single-block PWL) : '];
0078     mpc = loadcase(casefile);
0079     mpc.gencost(3, NCOST) = 2;
0080     [r, success] = runopf(mpc, mpopt);
0081     [f, bus, gen, branch] = deal(r.f, r.bus, r.gen, r.branch);
0082     t_ok(success, [t 'success']);
0083     t_is(f, f_soln, 3, [t 'f']);
0084     t_is(   bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0085     t_is(   bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0086     t_is(   bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0087     t_is(   bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  2, [t 'bus mu']);
0088     t_is(   gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0089     t_is(   gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0090     t_is(   gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0091     t_is(branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0092     t_is(branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0093     t_is(branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0094     xr = [r.var.val.Va;r.var.val.Vm;r.var.val.Pg;r.var.val.Qg;0;r.var.val.y];
0095     t_is(r.x, xr, 8, [t 'check on raw x returned from OPF']);
0096 
0097 %     %% get solved AC power flow case from MAT-file
0098 %     load soln9_opf_Plim;       %% defines bus_soln, gen_soln, branch_soln, f_soln
0099 %
0100 %     %% run OPF with active power line limits
0101 %     t = [t0 '(P line lim) : '];
0102 %     mpopt1 = mpoption(mpopt, 'opf.flow_lim', 'P');
0103 %     [baseMVA, bus, gen, gencost, branch, f, success, et] = runopf(casefile, mpopt1);
0104 %     t_ok(success, [t 'success']);
0105 %     t_is(f, f_soln, 3, [t 'f']);
0106 %     t_is(   bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0107 %     t_is(   bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0108 %     t_is(   bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0109 %     t_is(   bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  2, [t 'bus mu']);
0110 %     t_is(   gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0111 %     t_is(   gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0112 %     t_is(   gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0113 %     t_is(branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0114 %     t_is(branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0115 %     t_is(branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0116 
0117     %%-----  test OPF with quadratic gen costs moved to generalized costs  -----
0118     mpc = loadcase(casefile);
0119     mpc.gencost = [
0120         2   1500    0   3   0.11    5   0;
0121         2   2000    0   3   0.085   1.2 0;
0122         2   3000    0   3   0.1225  1   0;
0123     ];
0124     [baseMVA, bus_soln, gen_soln, gencost, branch_soln, f_soln, success, et] = runopf(mpc, mpopt);
0125     branch_soln = branch_soln(:,1:MU_ST);
0126     
0127     A = sparse(0,0);
0128     l = [];
0129     u = [];
0130     nb = size(mpc.bus, 1);      % number of buses
0131     ng = size(mpc.gen, 1);      % number of gens
0132     thbas = 1;                thend    = thbas+nb-1;
0133     vbas     = thend+1;       vend     = vbas+nb-1;
0134     pgbas    = vend+1;        pgend    = pgbas+ng-1;
0135     qgbas    = pgend+1;       qgend    = qgbas+ng-1;
0136     nxyz = 2*nb + 2*ng;
0137     N = sparse((1:ng)', (pgbas:pgend)', mpc.baseMVA * ones(ng,1), ng, nxyz);
0138     fparm = ones(ng,1) * [ 1 0 0 1 ];
0139     [junk, ix] = sort(mpc.gen(:, 1));
0140     H = 2 * spdiags(mpc.gencost(ix, 5), 0, ng, ng);
0141     Cw = mpc.gencost(ix, 6);
0142     mpc.gencost(:, 5:7) = 0;
0143 
0144     %% run OPF with quadratic gen costs moved to generalized costs
0145     t = [t0 'w/quadratic generalized gen cost : '];
0146     [r, success] = opf(mpc, A, l, u, mpopt, N, fparm, H, Cw);
0147     [f, bus, gen, branch] = deal(r.f, r.bus, r.gen, r.branch);
0148     t_ok(success, [t 'success']);
0149     t_is(f, f_soln, 3, [t 'f']);
0150     t_is(   bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0151     t_is(   bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0152     t_is(   bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0153     t_is(   bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  2, [t 'bus mu']);
0154     t_is(   gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0155     t_is(   gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0156     t_is(   gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0157     t_is(branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0158     t_is(branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0159     t_is(branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0160     t_is(r.cost.usr, f, 12, [t 'user cost']);
0161 
0162     %%-----  run OPF with extra linear user constraints & costs  -----
0163     %% single new z variable constrained to be greater than or equal to
0164     %% deviation from 1 pu voltage at bus 1, linear cost on this z
0165     %% get solved AC power flow case from MAT-file
0166     load soln9_opf_extras1;   %% defines bus_soln, gen_soln, branch_soln, f_soln
0167     A = sparse([1;1;2;2],[10;25;10;25],[-1;1;1;1],2,25);
0168     u = [Inf; Inf];
0169     l = [-1; 1];
0170     
0171     N = sparse(1, 25, 1, 1, 25);    %% new z variable only
0172     fparm = [1 0 0 1];              %% w = r = z
0173     H = sparse(1,1);                %% no quadratic term
0174     Cw = 100;
0175 
0176     t = [t0 'w/extra constraints & costs 1 : '];
0177     [r, success] = opf(casefile, A, l, u, mpopt, N, fparm, H, Cw);
0178     [f, bus, gen, branch] = deal(r.f, r.bus, r.gen, r.branch);
0179     t_ok(success, [t 'success']);
0180     t_is(f, f_soln, 3, [t 'f']);
0181     t_is(   bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0182     t_is(   bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0183     t_is(   bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0184     t_is(   bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  2, [t 'bus mu']);
0185     t_is(   gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0186     t_is(   gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0187     t_is(   gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0188     t_is(branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0189     t_is(branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0190     t_is(branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0191     t_is(r.var.val.z, 0.025419, 6, [t 'user variable']);
0192     t_is(r.cost.usr, 2.5419, 4, [t 'user cost']);
0193 
0194     %%-----  test OPF with capability curves  -----
0195     mpc = loadcase('t_case9_opfv2');
0196     %% remove angle diff limits
0197     mpc.branch(1, ANGMAX) = 360;
0198     mpc.branch(9, ANGMIN) = -360;
0199     
0200     %% get solved AC power flow case from MAT-file
0201     load soln9_opf_PQcap;   %% defines bus_soln, gen_soln, branch_soln, f_soln
0202         
0203     %% run OPF with capability curves
0204     t = [t0 'w/capability curves : '];
0205     [baseMVA, bus, gen, gencost, branch, f, success, et] = runopf(mpc, mpopt);
0206     t_ok(success, [t 'success']);
0207     t_is(f, f_soln, 3, [t 'f']);
0208     t_is(   bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0209     t_is(   bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0210     t_is(   bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0211     t_is(   bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  2, [t 'bus mu']);
0212     t_is(   gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0213     t_is(   gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0214     t_is(   gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0215     t_is(branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0216     t_is(branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0217     t_is(branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0218 
0219     %%-----  test OPF with angle difference limits  -----
0220     mpc = loadcase('t_case9_opfv2');
0221     %% remove capability curves
0222     mpc.gen(2:3, [PC1, PC2, QC1MIN, QC1MAX, QC2MIN, QC2MAX]) = zeros(2,6);
0223     
0224     %% get solved AC power flow case from MAT-file
0225     load soln9_opf_ang;   %% defines bus_soln, gen_soln, branch_soln, f_soln
0226         
0227     %% run OPF with angle difference limits
0228     t = [t0 'w/angle difference limits : '];
0229     [baseMVA, bus, gen, gencost, branch, f, success, et] = runopf(mpc, mpopt);
0230     t_ok(success, [t 'success']);
0231     t_is(f, f_soln, 3, [t 'f']);
0232     t_is(   bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0233     t_is(   bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0234     t_is(   bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0235     t_is(   bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  1, [t 'bus mu']);
0236     t_is(   gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0237     t_is(   gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0238     t_is(   gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0239     t_is(branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0240     t_is(branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0241     t_is(branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0242     t_is(branch(:,ibr_angmu ), branch_soln(:,ibr_angmu ),  2, [t 'branch angle mu']);
0243 
0244     %%-----  test OPF with ignored angle difference limits  -----
0245     %% get solved AC power flow case from MAT-file
0246     load soln9_opf;   %% defines bus_soln, gen_soln, branch_soln, f_soln
0247     
0248     %% run OPF with ignored angle difference limits
0249     t = [t0 'w/ignored angle difference limits : '];
0250     mpopt1 = mpoption(mpopt, 'opf.ignore_angle_lim', 1);
0251     [baseMVA, bus, gen, gencost, branch, f, success, et] = runopf(mpc, mpopt1);
0252     %% ang limits are not in this solution data, so let's remove them
0253     branch(1, ANGMAX) = 360;
0254     branch(9, ANGMIN) = -360;
0255     t_ok(success, [t 'success']);
0256     t_is(f, f_soln, 3, [t 'f']);
0257     t_is(   bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0258     t_is(   bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0259     t_is(   bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0260     t_is(   bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  2, [t 'bus mu']);
0261     t_is(   gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0262     t_is(   gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0263     t_is(   gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0264     t_is(branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0265     t_is(branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0266     t_is(branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0267 else
0268     t_skip(num_tests, [t0 'not available']);
0269 end
0270 
0271 t_end;

Generated on Fri 20-Mar-2015 18:23:34 by m2html © 2005