Home > matpower5.1 > t > t_opf_dc_cplex.m

t_opf_dc_cplex

PURPOSE ^

T_OPF_DC_CPLEX Tests for DC optimal power flow using CPLEX solver.

SYNOPSIS ^

function t_opf_dc_cplex(quiet)

DESCRIPTION ^

T_OPF_DC_CPLEX  Tests for DC optimal power flow using CPLEX solver.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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

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