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

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