Home > matpower5.1 > t > t_opf_dc_clp.m

t_opf_dc_clp

PURPOSE ^

T_OPF_DC_CLP Tests for DC optimal power flow using CLP solver.

SYNOPSIS ^

function t_opf_dc_clp(quiet)

DESCRIPTION ^

T_OPF_DC_CLP  Tests for DC optimal power flow using CLP solver.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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

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