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

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