Home > matpower6.0 > t > t_opf_dc_gurobi.m

t_opf_dc_gurobi

PURPOSE ^

T_OPF_DC_GUROBI Tests for DC optimal power flow using Gurobi solver.

SYNOPSIS ^

function t_opf_dc_gurobi(quiet)

DESCRIPTION ^

T_OPF_DC_GUROBI  Tests for DC optimal power flow using Gurobi solver.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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

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