Home > matpower5.1 > t > t_opf_dc_glpk.m

t_opf_dc_glpk

PURPOSE ^

T_OPF_DC_GLPK Tests for DC optimal power flow using GLPK solver.

SYNOPSIS ^

function t_opf_dc_glpk(quiet)

DESCRIPTION ^

T_OPF_DC_GLPK  Tests for DC optimal power flow using GLPK solver.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function t_opf_dc_glpk(quiet)
0002 %T_OPF_DC_GLPK  Tests for DC optimal power flow using GLPK 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_glpk.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 algs  = [1; 1; 2];
0019 alg_names = {
0020     'primal simplex',
0021     'dual simplex',
0022     'interior',
0023 };
0024 if have_fcn('octave')
0025     if have_fcn('octave', 'vnum') < 3.007
0026         dual = [0; 1; 1];
0027     else
0028         dual = [1; 2; 1];
0029     end
0030 else
0031     dual = [0; 2; 1];
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', 'GLPK');
0064 
0065 %% run DC OPF
0066 if have_fcn('glpk')
0067     for k = 1:length(algs)
0068         mpopt = mpoption(mpopt, 'glpk.opts.lpsolver', algs(k), 'glpk.opts.dual', dual(k));
0069     t0 = sprintf('DC OPF (GLPK %s): ', alg_names{k});
0070 
0071     %% set up indices
0072     ib_data     = [1:BUS_AREA BASE_KV:VMIN];
0073     ib_voltage  = [VM VA];
0074     ib_lam      = [LAM_P LAM_Q];
0075     ib_mu       = [MU_VMAX MU_VMIN];
0076     ig_data     = [GEN_BUS QMAX QMIN MBASE:APF];
0077     ig_disp     = [PG QG VG];
0078     ig_mu       = (MU_PMAX:MU_QMIN);
0079     ibr_data    = (1:ANGMAX);
0080     ibr_flow    = (PF:QT);
0081     ibr_mu      = [MU_SF MU_ST];
0082     ibr_angmu   = [MU_ANGMIN MU_ANGMAX];
0083 
0084     %% get solved DC power flow case from MAT-file
0085     load soln9_dcopf;       %% defines bus_soln, gen_soln, branch_soln, f_soln
0086 
0087     %% run OPF
0088     t = t0;
0089     [baseMVA, bus, gen, gencost, branch, f, success, et] = rundcopf(casefile, mpopt);
0090     t_ok(success, [t 'success']);
0091     t_is(f, f_soln, 3, [t 'f']);
0092     t_is(   bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0093     t_is(   bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0094     t_is(   bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0095     t_is(   bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  2, [t 'bus mu']);
0096     t_is(   gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0097     t_is(   gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0098     t_is(   gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0099     t_is(branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0100     t_is(branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0101     t_is(branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0102 
0103     %%-----  run OPF with extra linear user constraints & costs  -----
0104     %% two new z variables
0105     %%      0 <= z1, P2 - P1 <= z1
0106     %%      0 <= z2, P2 - P3 <= z2
0107     %% with A and N sized for DC opf
0108     mpc = loadcase(casefile);
0109     mpc.A = sparse([1;1;1;2;2;2],[10;11;13;11;12;14],[-1;1;-1;1;-1;-1],2,14);
0110     mpc.u = [0; 0];
0111     mpc.l = [-Inf; -Inf];
0112     mpc.zl = [0; 0];
0113 
0114     mpc.N = sparse([1;2], [13;14], [1;1], 2, 14);   %% new z variables only
0115     mpc.fparm = ones(2,1) * [1 0 0 1];              %% w = r = z
0116     mpc.H = sparse(2,2);                            %% no quadratic term
0117     mpc.Cw = [1000;1];
0118 
0119     t = [t0 'w/extra constraints & costs 1 : '];
0120     [r, success] = rundcopf(mpc, mpopt);
0121     t_ok(success, [t 'success']);
0122     t_is(r.gen(1, PG), 116.15974, 5, [t 'Pg1 = 116.15974']);
0123     t_is(r.gen(2, PG), 116.15974, 5, [t 'Pg2 = 116.15974']);
0124     t_is(r.var.val.z, [0; 0.3348], 4, [t 'user vars']);
0125     t_is(r.cost.usr, 0.3348, 4, [t 'user costs']);
0126 
0127     %% with A and N sized for AC opf
0128     mpc = loadcase(casefile);
0129     mpc.A = sparse([1;1;1;2;2;2],[19;20;25;20;21;26],[-1;1;-1;1;-1;-1],2,26);
0130     mpc.u = [0; 0];
0131     mpc.l = [-Inf; -Inf];
0132     mpc.zl = [0; 0];
0133 
0134     mpc.N = sparse([1;2], [25;26], [1;1], 2, 26);   %% new z variables only
0135     mpc.fparm = ones(2,1) * [1 0 0 1];              %% w = r = z
0136     mpc.H = sparse(2,2);                            %% no quadratic term
0137     mpc.Cw = [1000;1];
0138 
0139     t = [t0 'w/extra constraints & costs 2 : '];
0140     [r, success] = rundcopf(mpc, mpopt);
0141     t_ok(success, [t 'success']);
0142     t_is(r.gen(1, PG), 116.15974, 5, [t 'Pg1 = 116.15974']);
0143     t_is(r.gen(2, PG), 116.15974, 5, [t 'Pg2 = 116.15974']);
0144     t_is(r.var.val.z, [0; 0.3348], 4, [t 'user vars']);
0145     t_is(r.cost.usr, 0.3348, 4, [t 'user costs']);
0146 
0147     t = [t0 'infeasible : '];
0148     %% with A and N sized for DC opf
0149     mpc = loadcase(casefile);
0150     mpc.A = sparse([1;1], [10;11], [1;1], 1, 14);   %% Pg1 + Pg2
0151     mpc.u = Inf;
0152     mpc.l = 600;
0153     [r, success] = rundcopf(mpc, mpopt);
0154     t_ok(~success, [t 'no success']);
0155 
0156     end
0157 else
0158     t_skip(num_tests, 'GLPK not available');
0159 end
0160 
0161 if have_fcn('octave')
0162     warning(s1.state, file_in_path_warn_id);
0163 end
0164 
0165 t_end;

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