Home > matpower5.0 > t > t_opf_dc_mosek.m

t_opf_dc_mosek

PURPOSE ^

T_OPF_DC_MOSEK Tests for DC optimal power flow using MOSEK solver.

SYNOPSIS ^

function t_opf_dc_mosek(quiet)

DESCRIPTION ^

T_OPF_DC_MOSEK  Tests for DC optimal power flow using MOSEK solver.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function t_opf_dc_mosek(quiet)
0002 %T_OPF_DC_MOSEK  Tests for DC optimal power flow using MOSEK solver.
0003 
0004 %   MATPOWER
0005 %   $Id: t_opf_dc_mosek.m 2337 2014-06-17 20:08:52Z ray $
0006 %   by Ray Zimmerman, PSERC Cornell
0007 %   Copyright (c) 2004-2010 by Power System Engineering Research Center (PSERC)
0008 %
0009 %   This file is part of MATPOWER.
0010 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0011 %
0012 %   MATPOWER is free software: you can redistribute it and/or modify
0013 %   it under the terms of the GNU General Public License as published
0014 %   by the Free Software Foundation, either version 3 of the License,
0015 %   or (at your option) any later version.
0016 %
0017 %   MATPOWER is distributed in the hope that it will be useful,
0018 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0019 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0020 %   GNU General Public License for more details.
0021 %
0022 %   You should have received a copy of the GNU General Public License
0023 %   along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.
0024 %
0025 %   Additional permission under GNU GPL version 3 section 7
0026 %
0027 %   If you modify MATPOWER, or any covered work, to interface with
0028 %   other modules (such as MATLAB code and MEX-files) available in a
0029 %   MATLAB(R) or comparable environment containing parts covered
0030 %   under other licensing terms, the licensors of MATPOWER grant
0031 %   you additional permission to convey the resulting work.
0032 
0033 if nargin < 1
0034     quiet = 0;
0035 end
0036 
0037 algs = [0; 1; 4; 5; 6; 7; 10];
0038 num_tests = 23 * length(algs);
0039 
0040 t_begin(num_tests, quiet);
0041 
0042 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0043     VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0044 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0045     MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0046     QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0047 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0048     TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0049     ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0050 
0051 casefile = 't_case9_opf';
0052 if quiet
0053     verbose = 0;
0054 else
0055     verbose = 0;
0056 end
0057 
0058 mpopt = mpoption('out.all', 0, 'verbose', verbose);
0059 mpopt = mpoption(mpopt, 'opf.dc.solver', 'MOSEK');
0060 
0061 %% run DC OPF
0062 if have_fcn('mosek')
0063     for k = 1:length(algs)
0064         mpopt = mpoption(mpopt, 'mosek.lp_alg', algs(k));
0065         methods = {
0066             'free',
0067             'interior point',
0068             'primal simplex',
0069             'dual simplex',
0070             'primal dual simplex',
0071             'free simplex',
0072             'concurrent'
0073         };
0074     t0 = sprintf('DC OPF (MOSEK %s): ', methods{k});
0075 
0076     %% set up indices
0077     ib_data     = [1:BUS_AREA BASE_KV:VMIN];
0078     ib_voltage  = [VM VA];
0079     ib_lam      = [LAM_P LAM_Q];
0080     ib_mu       = [MU_VMAX MU_VMIN];
0081     ig_data     = [GEN_BUS QMAX QMIN MBASE:APF];
0082     ig_disp     = [PG QG VG];
0083     ig_mu       = (MU_PMAX:MU_QMIN);
0084     ibr_data    = (1:ANGMAX);
0085     ibr_flow    = (PF:QT);
0086     ibr_mu      = [MU_SF MU_ST];
0087     ibr_angmu   = [MU_ANGMIN MU_ANGMAX];
0088     
0089     %% get solved DC power flow case from MAT-file
0090     load soln9_dcopf;       %% defines bus_soln, gen_soln, branch_soln, f_soln
0091     
0092     %% run OPF
0093     t = t0;
0094     [baseMVA, bus, gen, gencost, branch, f, success, et] = rundcopf(casefile, mpopt);
0095     t_ok(success, [t 'success']);
0096     t_is(f, f_soln, 3, [t 'f']);
0097     t_is(   bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0098     t_is(   bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0099     t_is(   bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0100     t_is(   bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  2, [t 'bus mu']);
0101     t_is(   gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0102     t_is(   gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0103     t_is(   gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0104     t_is(branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0105     t_is(branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0106     t_is(branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0107 
0108     %%-----  run OPF with extra linear user constraints & costs  -----
0109     %% two new z variables
0110     %%      0 <= z1, P2 - P1 <= z1
0111     %%      0 <= z2, P2 - P3 <= z2
0112     %% with A and N sized for DC opf
0113     mpc = loadcase(casefile);
0114     mpc.A = sparse([1;1;1;2;2;2],[10;11;13;11;12;14],[-1;1;-1;1;-1;-1],2,14);
0115     mpc.u = [0; 0];
0116     mpc.l = [-Inf; -Inf];
0117     mpc.zl = [0; 0];
0118     
0119     mpc.N = sparse([1;2], [13;14], [1;1], 2, 14);   %% 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 1 : '];
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     %% with A and N sized for AC opf
0133     mpc = loadcase(casefile);
0134     mpc.A = sparse([1;1;1;2;2;2],[19;20;25;20;21;26],[-1;1;-1;1;-1;-1],2,26);
0135     mpc.u = [0; 0];
0136     mpc.l = [-Inf; -Inf];
0137     mpc.zl = [0; 0];
0138 
0139     mpc.N = sparse([1;2], [25;26], [1;1], 2, 26);   %% new z variables only
0140     mpc.fparm = ones(2,1) * [1 0 0 1];              %% w = r = z
0141     mpc.H = sparse(2,2);                            %% no quadratic term
0142     mpc.Cw = [1000;1];
0143 
0144     t = [t0 'w/extra constraints & costs 2 : '];
0145     [r, success] = rundcopf(mpc, mpopt);
0146     t_ok(success, [t 'success']);
0147     t_is(r.gen(1, PG), 116.15974, 5, [t 'Pg1 = 116.15974']);
0148     t_is(r.gen(2, PG), 116.15974, 5, [t 'Pg2 = 116.15974']);
0149     t_is(r.var.val.z, [0; 0.3348], 4, [t 'user vars']);
0150     t_is(r.cost.usr, 0.3348, 4, [t 'user costs']);
0151 
0152     t = [t0 'infeasible : '];
0153     %% with A and N sized for DC opf
0154     mpc = loadcase(casefile);
0155     mpc.A = sparse([1;1], [10;11], [1;1], 1, 14);   %% Pg1 + Pg2
0156     mpc.u = Inf;
0157     mpc.l = 600;
0158     [r, success] = rundcopf(mpc, mpopt);
0159     t_ok(~success, [t 'no success']);
0160 
0161     end
0162 else
0163     t_skip(num_tests, 'MOSEK not available');
0164 end
0165 
0166 t_end;

Generated on Mon 26-Jan-2015 15:21:31 by m2html © 2005