Home > matpower4.0 > t > t_opf_tspopf_tralm.m

t_opf_tspopf_tralm

PURPOSE ^

T_OPF_TSPOPF_TRALM Tests for TRALM-based optimal power flow.

SYNOPSIS ^

function t_opf_tspopf_tralm(quiet)

DESCRIPTION ^

T_OPF_TSPOPF_TRALM  Tests for TRALM-based optimal power flow.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function t_opf_tspopf_tralm(quiet)
0002 %T_OPF_TSPOPF_TRALM  Tests for TRALM-based optimal power flow.
0003 
0004 %   MATPOWER
0005 %   $Id: t_opf_tspopf_tralm.m,v 1.13 2010/11/30 21:29:11 cvs Exp $
0006 %   by Ray Zimmerman, PSERC Cornell
0007 %   Copyright (c) 2004-2010 by Power System Engineering Research Center (PSERC)
0008 %
0009 %   This file is part of MATPOWER.
0010 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0011 %
0012 %   MATPOWER is free software: you can redistribute it and/or modify
0013 %   it under the terms of the GNU General Public License as published
0014 %   by the Free Software Foundation, either version 3 of the License,
0015 %   or (at your option) any later version.
0016 %
0017 %   MATPOWER is distributed in the hope that it will be useful,
0018 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0019 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0020 %   GNU General Public License for more details.
0021 %
0022 %   You should have received a copy of the GNU General Public License
0023 %   along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.
0024 %
0025 %   Additional permission under GNU GPL version 3 section 7
0026 %
0027 %   If you modify MATPOWER, or any covered work, to interface with
0028 %   other modules (such as MATLAB code and MEX-files) available in a
0029 %   MATLAB(R) or comparable environment containing parts covered
0030 %   under other licensing terms, the licensors of MATPOWER grant
0031 %   you additional permission to convey the resulting work.
0032 
0033 if nargin < 1
0034     quiet = 0;
0035 end
0036 
0037 num_tests = 89;
0038 
0039 t_begin(num_tests, quiet);
0040 
0041 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0042     VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0043 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0044     MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0045     QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0046 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0047     TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0048     ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0049 [PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost;
0050 
0051 casefile = 't_case9_opf';
0052 if quiet
0053     verbose = 0;
0054 else
0055     verbose = 0;
0056 end
0057 
0058 t0 = 'TRALMOPF : ';
0059 mpopt = mpoption('OPF_VIOLATION', 1e-6, 'TRALM_PRIMETOL', 1e-6, ...
0060         'TRALM_DUALTOL', 5e-6, 'TRALM_COSTTOL', 1e-7, 'SMOOTHING_RATIO', 0.04);
0061 mpopt = mpoption(mpopt, 'OUT_ALL', 0, 'VERBOSE', verbose, 'OPF_ALG', 550);
0062         
0063 if have_fcn('tralmopf')
0064     %% set up indices
0065     ib_data     = [1:BUS_AREA BASE_KV:VMIN];
0066     ib_voltage  = [VM VA];
0067     ib_lam      = [LAM_P LAM_Q];
0068     ib_mu       = [MU_VMAX MU_VMIN];
0069     ig_data     = [GEN_BUS QMAX QMIN MBASE:APF];
0070     ig_disp     = [PG QG VG];
0071     ig_mu       = (MU_PMAX:MU_QMIN);
0072     ibr_data    = (1:ANGMAX);
0073     ibr_flow    = (PF:QT);
0074     ibr_mu      = [MU_SF MU_ST];
0075     ibr_angmu   = [MU_ANGMIN MU_ANGMAX];
0076 
0077     %% get solved AC power flow case from MAT-file
0078     load soln9_opf;     %% defines bus_soln, gen_soln, branch_soln, f_soln
0079 
0080     %% run OPF
0081     t = t0;
0082     [baseMVA, bus, gen, gencost, branch, f, success, et] = runopf(casefile, mpopt);
0083     t_ok(success, [t 'success']);
0084     t_is(f, f_soln, 3, [t 'f']);
0085     t_is(   bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0086     t_is(   bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0087     t_is(   bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0088     t_is(   bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  2, [t 'bus mu']);
0089     t_is(   gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0090     t_is(   gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0091     t_is(   gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0092     t_is(branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0093     t_is(branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0094     t_is(branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0095 
0096     %% run with automatic conversion of single-block pwl to linear costs
0097     t = [t0 '(single-block PWL) : '];
0098     mpc = loadcase(casefile);
0099     mpc.gencost(3, NCOST) = 2;
0100     r = runopf(mpc, mpopt);
0101     t_ok(success, [t 'success']);
0102     t_is(f, f_soln, 3, [t 'f']);
0103     t_is(   bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0104     t_is(   bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0105     t_is(   bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0106     t_is(   bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  2, [t 'bus mu']);
0107     t_is(   gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0108     t_is(   gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0109     t_is(   gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0110     t_is(branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0111     t_is(branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0112     t_is(branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0113     xr = [r.var.val.Va;r.var.val.Vm;r.var.val.Pg;r.var.val.Qg];
0114     t_is(r.x, xr, 8, [t [t 'check on raw x returned from OPF']]);
0115 
0116 %     %% get solved AC power flow case from MAT-file
0117 %     load soln9_opf_Plim;       %% defines bus_soln, gen_soln, branch_soln, f_soln
0118 %
0119 %     %% run OPF with active power line limits
0120 %     t = [t0 '(P line lim) : '];
0121 %     mpopt1 = mpoption(mpopt, 'OPF_FLOW_LIM', 1);
0122 %     [baseMVA, bus, gen, gencost, branch, f, success, et] = runopf(casefile, mpopt1);
0123 %     t_ok(success, [t 'success']);
0124 %     t_is(f, f_soln, 3, [t 'f']);
0125 %     t_is(   bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0126 %     t_is(   bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0127 %     t_is(   bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0128 %     t_is(   bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  2, [t 'bus mu']);
0129 %     t_is(   gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0130 %     t_is(   gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0131 %     t_is(   gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0132 %     t_is(branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0133 %     t_is(branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0134 %     t_is(branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0135 
0136     %%-----  test OPF with quadratic gen costs moved to generalized costs  -----
0137     mpc = loadcase(casefile);
0138     mpc.gencost = [
0139         2   1500    0   3   0.11    5   0;
0140         2   2000    0   3   0.085   1.2 0;
0141         2   3000    0   3   0.1225  1   0;
0142     ];
0143     [baseMVA, bus_soln, gen_soln, gencost, branch_soln, f_soln, success, et] = runopf(mpc, mpopt);
0144     branch_soln = branch_soln(:,1:MU_ST);
0145     
0146     A = sparse(0,0);
0147     l = [];
0148     u = [];
0149     nb = size(mpc.bus, 1);      % number of buses
0150     ng = size(mpc.gen, 1);      % number of gens
0151     thbas = 1;                thend    = thbas+nb-1;
0152     vbas     = thend+1;       vend     = vbas+nb-1;
0153     pgbas    = vend+1;        pgend    = pgbas+ng-1;
0154     qgbas    = pgend+1;       qgend    = qgbas+ng-1;
0155     nxyz = 2*nb + 2*ng;
0156     N = sparse((1:ng)', (pgbas:pgend)', mpc.baseMVA * ones(ng,1), ng, nxyz);
0157     fparm = ones(ng,1) * [ 1 0 0 1 ];
0158     [junk, ix] = sort(mpc.gen(:, 1));
0159     H = 2 * spdiags(mpc.gencost(ix, 5), 0, ng, ng);
0160     Cw = mpc.gencost(ix, 6);
0161     mpc.gencost(:, 5:7) = 0;
0162 
0163     %% run OPF with quadratic gen costs moved to generalized costs
0164     t = [t0 'w/quadratic generalized gen cost : '];
0165     [r, success] = opf(mpc, A, l, u, mpopt, N, fparm, H, Cw);
0166     [f, bus, gen, branch] = deal(r.f, r.bus, r.gen, r.branch);
0167     t_ok(success, [t 'success']);
0168     t_is(f, f_soln, 3, [t 'f']);
0169     t_is(   bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0170     t_is(   bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0171     t_is(   bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0172     t_is(   bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  2, [t 'bus mu']);
0173     t_is(   gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0174     t_is(   gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0175     t_is(   gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0176     t_is(branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0177     t_is(branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0178     t_is(branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0179     t_is(r.cost.usr, f, 12, [t 'user cost']);
0180 
0181     %%-----  run OPF with extra linear user constraints & costs  -----
0182     %% single new z variable constrained to be greater than or equal to
0183     %% deviation from 1 pu voltage at bus 1, linear cost on this z
0184     %% get solved AC power flow case from MAT-file
0185     load soln9_opf_extras1;   %% defines bus_soln, gen_soln, branch_soln, f_soln
0186     A = sparse([1;1;2;2],[10;25;10;25],[-1;1;1;1],2,25);
0187     u = [Inf; Inf];
0188     l = [-1; 1];
0189     
0190     N = sparse(1, 25, 1, 1, 25);    %% new z variable only
0191     fparm = [1 0 0 1];              %% w = r = z
0192     H = sparse(1,1);                %% no quadratic term
0193     Cw = 100;
0194 
0195     t = [t0 'w/extra constraints & costs 1 : '];
0196     [r, success] = opf(casefile, A, l, u, mpopt, N, fparm, H, Cw);
0197     [f, bus, gen, branch] = deal(r.f, r.bus, r.gen, r.branch);
0198     t_ok(success, [t 'success']);
0199     t_is(f, f_soln, 3, [t 'f']);
0200     t_is(   bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0201     t_is(   bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0202     t_is(   bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0203     t_is(   bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  2, [t 'bus mu']);
0204     t_is(   gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0205     t_is(   gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0206     t_is(   gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0207     t_is(branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0208     t_is(branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0209     t_is(branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0210     t_is(r.var.val.z, 0.025419, 6, [t 'user variable']);
0211     t_is(r.cost.usr, 2.5419, 4, [t 'user cost']);
0212 
0213     %%-----  test OPF with capability curves  -----
0214     mpc = loadcase('t_case9_opfv2');
0215     %% remove angle diff limits
0216     mpc.branch(1, ANGMAX) = 360;
0217     mpc.branch(9, ANGMIN) = -360;
0218     
0219     %% get solved AC power flow case from MAT-file
0220     load soln9_opf_PQcap;   %% defines bus_soln, gen_soln, branch_soln, f_soln
0221         
0222     %% run OPF with capability curves
0223     t = [t0 'w/capability curves : '];
0224     [baseMVA, bus, gen, gencost, branch, f, success, et] = runopf(mpc, mpopt);
0225     t_ok(success, [t 'success']);
0226     t_is(f, f_soln, 3, [t 'f']);
0227     t_is(   bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0228     t_is(   bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0229     t_is(   bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0230     t_is(   bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  2, [t 'bus mu']);
0231     t_is(   gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0232     t_is(   gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0233     t_is(   gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0234     t_is(branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0235     t_is(branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0236     t_is(branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0237 
0238     %%-----  test OPF with angle difference limits  -----
0239     mpc = loadcase('t_case9_opfv2');
0240     %% remove capability curves
0241     mpc.gen(2:3, [PC1, PC2, QC1MIN, QC1MAX, QC2MIN, QC2MAX]) = zeros(2,6);
0242     
0243     %% get solved AC power flow case from MAT-file
0244     load soln9_opf_ang;   %% defines bus_soln, gen_soln, branch_soln, f_soln
0245         
0246     %% run OPF with angle difference limits
0247     t = [t0 'w/angle difference limits : '];
0248     [baseMVA, bus, gen, gencost, branch, f, success, et] = runopf(mpc, mpopt);
0249     t_ok(success, [t 'success']);
0250     t_is(f, f_soln, 3, [t 'f']);
0251     t_is(   bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0252     t_is(   bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0253     t_is(   bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0254     t_is(   bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  1, [t 'bus mu']);
0255     t_is(   gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0256     t_is(   gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0257     t_is(   gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0258     t_is(branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0259     t_is(branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0260     t_is(branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0261     t_is(branch(:,ibr_angmu ), branch_soln(:,ibr_angmu ),  2, [t 'branch angle mu']);
0262 
0263     %%-----  test OPF with ignored angle difference limits  -----
0264     %% get solved AC power flow case from MAT-file
0265     load soln9_opf;   %% defines bus_soln, gen_soln, branch_soln, f_soln
0266     
0267     %% run OPF with ignored angle difference limits
0268     t = [t0 'w/ignored angle difference limits : '];
0269     mpopt1 = mpoption(mpopt, 'OPF_IGNORE_ANG_LIM', 1);
0270     [baseMVA, bus, gen, gencost, branch, f, success, et] = runopf(mpc, mpopt1);
0271     %% ang limits are not in this solution data, so let's remove them
0272     branch(1, ANGMAX) = 360;
0273     branch(9, ANGMIN) = -360;
0274     t_ok(success, [t 'success']);
0275     t_is(f, f_soln, 3, [t 'f']);
0276     t_is(   bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0277     t_is(   bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0278     t_is(   bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0279     t_is(   bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  2, [t 'bus mu']);
0280     t_is(   gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0281     t_is(   gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0282     t_is(   gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0283     t_is(branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0284     t_is(branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0285     t_is(branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0286 else
0287     t_skip(num_tests, [t0 'not available']);
0288 end
0289 
0290 t_end;

Generated on Mon 26-Jan-2015 14:56:45 by m2html © 2005