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

Generated on Fri 16-Dec-2016 12:45:37 by m2html © 2005