Home > matpower5.1 > t > t_opf_dc_ot.m

t_opf_dc_ot

PURPOSE ^

T_OPF_DC_OT Tests for DC optimal power flow using Opt Tbx solvers.

SYNOPSIS ^

function t_opf_dc_ot(quiet)

DESCRIPTION ^

T_OPF_DC_OT  Tests for DC optimal power flow using Opt Tbx solvers.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function t_opf_dc_ot(quiet)
0002 %T_OPF_DC_OT  Tests for DC optimal power flow using Opt Tbx solvers.
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_dc_ot.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 if have_fcn('quadprog_ls')
0019     if have_fcn('optimoptions')
0020         if have_fcn('linprog_ds')
0021             algs  = {'interior-point', 'active-set', 'simplex', 'dual-simplex'};
0022         else
0023             algs  = {'interior-point', 'active-set', 'simplex'};
0024         end
0025     else
0026         algs  = {'interior-point', 'active-set'};
0027     end
0028 else
0029     algs  = {''};
0030 end
0031 
0032 num_tests = 23 * length(algs);
0033 
0034 t_begin(num_tests, quiet);
0035 
0036 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0037     VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0038 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0039     MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0040     QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0041 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0042     TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0043     ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0044 
0045 casefile = 't_case9_opf';
0046 if quiet
0047     verbose = 0;
0048 else
0049     verbose = 0;
0050 end
0051 
0052 mpopt = mpoption('out.all', 0, 'verbose', verbose);
0053 mpopt = mpoption(mpopt, 'opf.dc.solver', 'OT');
0054 
0055 warning off optim:linprog:IgnoreStartPoint;
0056 warning off optim:linprog:AlgOptsWillError;
0057 
0058 %% run DC OPF
0059 if have_fcn('quadprog')
0060     v = ver('optim');
0061     for k = 1:length(algs)
0062         if ~isempty(algs)
0063             mpopt = mpoption(mpopt, 'linprog.Algorithm', algs{k});
0064         else
0065             mpopt = mpoption(mpopt, 'linprog', []);
0066         end
0067         if strcmp(algs{k}, 'dual-simplex') && strcmp(v.Version, '7.1')
0068             have_prices = 0;    %% dual-simplex did not return prices in Matlab R2014b!?!
0069         else
0070             have_prices = 1;
0071         end
0072     t0 = sprintf('DC OPF (OT %s): ', algs{k});
0073 
0074     %% set up indices
0075     ib_data     = [1:BUS_AREA BASE_KV:VMIN];
0076     ib_voltage  = [VM VA];
0077     ib_lam      = [LAM_P LAM_Q];
0078     ib_mu       = [MU_VMAX MU_VMIN];
0079     ig_data     = [GEN_BUS QMAX QMIN MBASE:APF];
0080     ig_disp     = [PG QG VG];
0081     ig_mu       = (MU_PMAX:MU_QMIN);
0082     ibr_data    = (1:ANGMAX);
0083     ibr_flow    = (PF:QT);
0084     ibr_mu      = [MU_SF MU_ST];
0085     ibr_angmu   = [MU_ANGMIN MU_ANGMAX];
0086     
0087     %% get solved DC power flow case from MAT-file
0088     load soln9_dcopf;       %% defines bus_soln, gen_soln, branch_soln, f_soln
0089     
0090     %% run OPF
0091     t = t0;
0092     [baseMVA, bus, gen, gencost, branch, f, success, et] = rundcopf(casefile, mpopt);
0093     t_ok(success, [t 'success']);
0094     t_is(f, f_soln, 3, [t 'f']);
0095     t_is(   bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0096     t_is(   bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0097     if have_prices
0098         t_is(   bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0099     else
0100         t_skip(1, [t 'bus lam: lambdas not computed']);
0101     end
0102     if have_prices
0103         t_is(   bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  2, [t 'bus mu']);
0104     else
0105         t_skip(1, [t 'bus mu: lambdas not computed']);
0106     end
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     if have_prices
0110         t_is(   gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0111     else
0112         t_skip(1, [t 'gen mu: lambdas not computed']);
0113     end
0114     t_is(branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0115     t_is(branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0116     if have_prices
0117         t_is(branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0118     else
0119         t_skip(1, [t 'branch mu: lambdas not computed']);
0120     end
0121 
0122     %%-----  run OPF with extra linear user constraints & costs  -----
0123     %% two new z variables
0124     %%      0 <= z1, P2 - P1 <= z1
0125     %%      0 <= z2, P2 - P3 <= z2
0126     %% with A and N sized for DC opf
0127     mpc = loadcase(casefile);
0128     mpc.A = sparse([1;1;1;2;2;2],[10;11;13;11;12;14],[-1;1;-1;1;-1;-1],2,14);
0129     mpc.u = [0; 0];
0130     mpc.l = [-Inf; -Inf];
0131     mpc.zl = [0; 0];
0132     
0133     mpc.N = sparse([1;2], [13;14], [1;1], 2, 14);   %% new z variables only
0134     mpc.fparm = ones(2,1) * [1 0 0 1];              %% w = r = z
0135     mpc.H = sparse(2,2);                            %% no quadratic term
0136     mpc.Cw = [1000;1];
0137 
0138     t = [t0 'w/extra constraints & costs 1 : '];
0139     [r, success] = rundcopf(mpc, mpopt);
0140     t_ok(success, [t 'success']);
0141     t_is(r.gen(1, PG), 116.15974, 5, [t 'Pg1 = 116.15974']);
0142     t_is(r.gen(2, PG), 116.15974, 5, [t 'Pg2 = 116.15974']);
0143     t_is(r.var.val.z, [0; 0.3348], 4, [t 'user vars']);
0144     t_is(r.cost.usr, 0.3348, 4, [t 'user costs']);
0145 
0146     %% with A and N sized for AC opf
0147     mpc = loadcase(casefile);
0148     mpc.A = sparse([1;1;1;2;2;2],[19;20;25;20;21;26],[-1;1;-1;1;-1;-1],2,26);
0149     mpc.u = [0; 0];
0150     mpc.l = [-Inf; -Inf];
0151     mpc.zl = [0; 0];
0152 
0153     mpc.N = sparse([1;2], [25;26], [1;1], 2, 26);   %% new z variables only
0154     mpc.fparm = ones(2,1) * [1 0 0 1];              %% w = r = z
0155     mpc.H = sparse(2,2);                            %% no quadratic term
0156     mpc.Cw = [1000;1];
0157 
0158     t = [t0 'w/extra constraints & costs 2 : '];
0159     [r, success] = rundcopf(mpc, mpopt);
0160     t_ok(success, [t 'success']);
0161     t_is(r.gen(1, PG), 116.15974, 5, [t 'Pg1 = 116.15974']);
0162     t_is(r.gen(2, PG), 116.15974, 5, [t 'Pg2 = 116.15974']);
0163     t_is(r.var.val.z, [0; 0.3348], 4, [t 'user vars']);
0164     t_is(r.cost.usr, 0.3348, 4, [t 'user costs']);
0165 
0166     t = [t0 'infeasible : '];
0167     %% with A and N sized for DC opf
0168     mpc = loadcase(casefile);
0169     mpc.A = sparse([1;1], [10;11], [1;1], 1, 14);   %% Pg1 + Pg2
0170     mpc.u = Inf;
0171     mpc.l = 600;
0172     %% Opt Tbx 5.1 has fatal bug here!
0173     try
0174         [r, success] = rundcopf(mpc, mpopt);
0175     catch
0176         success = 0;
0177     end
0178     t_ok(~success, [t 'no success']);
0179     end
0180 else
0181     t_skip(num_tests, 'Optimization Toolbox not available');
0182 end
0183 
0184 t_end;

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