Home > matpower7.0 > lib > 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-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 https://matpower.org for more info.
0011 
0012 if nargin < 1
0013     quiet = 0;
0014 end
0015 
0016 s = have_fcn('mosek', 'all');
0017 
0018 if s.av
0019     sc = mosek_symbcon;
0020     if s.vnum < 7
0021         alg_names = {           %% version 6.x
0022             'default',              %%  0 : MSK_OPTIMIZER_FREE
0023             'interior point',       %%  1 : MSK_OPTIMIZER_INTPNT
0024             '<conic>',              %%  2 : MSK_OPTIMIZER_CONIC
0025             '<qcone>',              %%  3 : MSK_OPTIMIZER_QCONE
0026             'primal simplex',       %%  4 : MSK_OPTIMIZER_PRIMAL_SIMPLEX
0027             'dual simplex',         %%  5 : MSK_OPTIMIZER_DUAL_SIMPLEX
0028             'primal dual simplex',  %%  6 : MSK_OPTIMIZER_PRIMAL_DUAL_SIMPLEX
0029             'automatic simplex',    %%  7 : MSK_OPTIMIZER_FREE_SIMPLEX
0030             '<mixed int>',          %%  8 : MSK_OPTIMIZER_MIXED_INT
0031             '<nonconvex>',          %%  9 : MSK_OPTIMIZER_NONCONVEX
0032             'concurrent'            %% 10 : MSK_OPTIMIZER_CONCURRENT
0033         };
0034     elseif s.vnum < 8
0035         alg_names = {           %% version 7.x
0036             'default',              %%  0 : MSK_OPTIMIZER_FREE
0037             'interior point',       %%  1 : MSK_OPTIMIZER_INTPNT
0038             '<conic>',              %%  2 : MSK_OPTIMIZER_CONIC
0039             'primal simplex',       %%  3 : MSK_OPTIMIZER_PRIMAL_SIMPLEX
0040             'dual simplex',         %%  4 : MSK_OPTIMIZER_DUAL_SIMPLEX
0041             'primal dual simplex',  %%  5 : MSK_OPTIMIZER_PRIMAL_DUAL_SIMPLEX
0042             'automatic simplex',    %%  6 : MSK_OPTIMIZER_FREE_SIMPLEX
0043             'network simplex',      %%  7 : MSK_OPTIMIZER_NETWORK_PRIMAL_SIMPLEX
0044             '<mixed int conic>',    %%  8 : MSK_OPTIMIZER_MIXED_INT_CONIC
0045             '<mixed int>',          %%  9 : MSK_OPTIMIZER_MIXED_INT
0046             'concurrent',           %% 10 : MSK_OPTIMIZER_CONCURRENT
0047             '<nonconvex>'           %% 11 : MSK_OPTIMIZER_NONCONVEX
0048         };
0049     else
0050         alg_names = {           %% version 8.x
0051             '<conic>',              %%  0 : MSK_OPTIMIZER_CONIC
0052             'dual simplex',         %%  1 : MSK_OPTIMIZER_DUAL_SIMPLEX
0053             'default',              %%  2 : MSK_OPTIMIZER_FREE
0054             'automatic simplex',    %%  3 : MSK_OPTIMIZER_FREE_SIMPLEX
0055             'interior point',       %%  4 : MSK_OPTIMIZER_INTPNT
0056             '<mixed int>',          %%  5 : MSK_OPTIMIZER_MIXED_INT
0057             'primal simplex'        %%  6 : MSK_OPTIMIZER_PRIMAL_SIMPLEX
0058         };
0059     end
0060     algs = [                                        %% v6.x v7.x v8.x
0061         sc.MSK_OPTIMIZER_FREE;                      %%  0    0    2
0062         sc.MSK_OPTIMIZER_INTPNT;                    %%  1    1    4
0063         sc.MSK_OPTIMIZER_PRIMAL_SIMPLEX;            %%  4    3    6
0064         sc.MSK_OPTIMIZER_DUAL_SIMPLEX;              %%  5    4    1
0065         sc.MSK_OPTIMIZER_FREE_SIMPLEX;              %%  7    6    3
0066     ];
0067     if s.vnum < 8
0068         algs(end+1) = ...
0069             sc.MSK_OPTIMIZER_PRIMAL_DUAL_SIMPLEX;   %%  6    5    -
0070         algs(end+1) = ...
0071             sc.MSK_OPTIMIZER_CONCURRENT;            %% 10   10    -
0072     end
0073 %     if s.vnum >= 7 && s.vnum < 8    %% MOSEK claims OPF is not a network problem
0074 %         algs(end+1) = ...
0075 %             sc.MSK_OPTIMIZER_NETWORK_PRIMAL_SIMPLEX;%%  -    7    -
0076 %     end
0077 else
0078     algs = 0;
0079 end
0080 
0081 num_tests = 24 * length(algs);
0082 
0083 t_begin(num_tests, quiet);
0084 
0085 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0086     VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0087 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0088     MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0089     QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0090 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0091     TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0092     ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0093 
0094 casefile = 't_case9_opf';
0095 if quiet
0096     verbose = 0;
0097 else
0098     verbose = 0;
0099 end
0100 
0101 mpopt = mpoption('out.all', 0, 'verbose', verbose);
0102 mpopt = mpoption(mpopt, 'opf.dc.solver', 'MOSEK');
0103 
0104 %% run DC OPF
0105 if s.av     %% if have_fcn('mosek')
0106     for k = 1:length(algs)
0107         mpopt = mpoption(mpopt, 'mosek.lp_alg', algs(k));
0108     t0 = sprintf('DC OPF (MOSEK %s): ', alg_names{algs(k)+1});
0109 
0110     %% set up indices
0111     ib_data     = [1:BUS_AREA BASE_KV:VMIN];
0112     ib_voltage  = [VM VA];
0113     ib_lam      = [LAM_P LAM_Q];
0114     ib_mu       = [MU_VMAX MU_VMIN];
0115     ig_data     = [GEN_BUS QMAX QMIN MBASE:APF];
0116     ig_disp     = [PG QG VG];
0117     ig_mu       = (MU_PMAX:MU_QMIN);
0118     ibr_data    = (1:ANGMAX);
0119     ibr_flow    = (PF:QT);
0120     ibr_mu      = [MU_SF MU_ST];
0121     ibr_angmu   = [MU_ANGMIN MU_ANGMAX];
0122     
0123     %% get solved DC power flow case from MAT-file
0124     load soln9_dcopf;       %% defines bus_soln, gen_soln, branch_soln, f_soln
0125     
0126     %% run OPF
0127     t = t0;
0128     [baseMVA, bus, gen, gencost, branch, f, success, et] = rundcopf(casefile, mpopt);
0129     t_ok(success, [t 'success']);
0130     t_is(f, f_soln, 3, [t 'f']);
0131     t_is(   bus(:,ib_data   ),    bus_soln(:,ib_data   ), 10, [t 'bus data']);
0132     t_is(   bus(:,ib_voltage),    bus_soln(:,ib_voltage),  3, [t 'bus voltage']);
0133     t_is(   bus(:,ib_lam    ),    bus_soln(:,ib_lam    ),  3, [t 'bus lambda']);
0134     t_is(   bus(:,ib_mu     ),    bus_soln(:,ib_mu     ),  2, [t 'bus mu']);
0135     t_is(   gen(:,ig_data   ),    gen_soln(:,ig_data   ), 10, [t 'gen data']);
0136     t_is(   gen(:,ig_disp   ),    gen_soln(:,ig_disp   ),  3, [t 'gen dispatch']);
0137     t_is(   gen(:,ig_mu     ),    gen_soln(:,ig_mu     ),  3, [t 'gen mu']);
0138     t_is(branch(:,ibr_data  ), branch_soln(:,ibr_data  ), 10, [t 'branch data']);
0139     t_is(branch(:,ibr_flow  ), branch_soln(:,ibr_flow  ),  3, [t 'branch flow']);
0140     t_is(branch(:,ibr_mu    ), branch_soln(:,ibr_mu    ),  2, [t 'branch mu']);
0141 
0142     %%-----  run OPF with extra linear user constraints & costs  -----
0143     %% two new z variables
0144     %%      0 <= z1, P3 - P1 <= z1
0145     %%      0 <= z2, P3 - P2 <= z2
0146     %% with A and N sized for DC opf
0147     mpc = loadcase(casefile);
0148     mpc.A = sparse([1;1;1;2;2;2],[10;12;13;12;11;14],[-1;1;-1;1;-1;-1],2,14);
0149     mpc.u = [0; 0];
0150     mpc.l = [-Inf; -Inf];
0151     mpc.zl = [0; 0];
0152     
0153     mpc.N = sparse([1;2], [13;14], [1;1], 2, 14);   %% new z variables only
0154     mpc.fparm = ones(2,1) * [1 0 0 1];              %% w = r = z
0155     mpc.H = sparse(2,2);                            %% no quadratic term
0156     mpc.Cw = [1000;1];
0157 
0158     t = [t0 'w/extra constraints & costs 1 : '];
0159     [r, success] = rundcopf(mpc, mpopt);
0160     t_ok(success, [t 'success']);
0161     t_is(r.gen(1, PG), 116.15974, 5, [t 'Pg1 = 116.15974']);
0162     t_is(r.gen(3, PG), 116.15974, 5, [t 'Pg3 = 116.15974']);
0163     t_is(r.var.val.z, [0; 0.3348], 4, [t 'user vars']);
0164     t_is(r.cost.usr, 0.3348, 4, [t 'user costs']);
0165 
0166     %% with A and N sized for AC opf
0167     mpc = loadcase(casefile);
0168     mpc.A = sparse([1;1;1;2;2;2],[19;21;25;21;20;26],[-1;1;-1;1;-1;-1],2,26);
0169     mpc.u = [0; 0];
0170     mpc.l = [-Inf; -Inf];
0171     mpc.zl = [0; 0];
0172 
0173     mpc.N = sparse([1;2], [25;26], [1;1], 2, 26);   %% new z variables only
0174     mpc.fparm = ones(2,1) * [1 0 0 1];              %% w = r = z
0175     mpc.H = sparse(2,2);                            %% no quadratic term
0176     mpc.Cw = [1000;1];
0177 
0178     t = [t0 'w/extra constraints & costs 2 : '];
0179     [r, success] = rundcopf(mpc, mpopt);
0180     t_ok(success, [t 'success']);
0181     t_is(r.gen(1, PG), 116.15974, 5, [t 'Pg1 = 116.15974']);
0182     t_is(r.gen(3, PG), 116.15974, 5, [t 'Pg3 = 116.15974']);
0183     t_is(r.var.val.z, [0; 0.3348], 4, [t 'user vars']);
0184     t_is(r.cost.usr, 0.3348, 4, [t 'user costs']);
0185 
0186     t = [t0 'infeasible : '];
0187     %% with A and N sized for DC opf
0188     mpc = loadcase(casefile);
0189     mpc.A = sparse([1;1], [10;11], [1;1], 1, 14);   %% Pg1 + Pg2
0190     mpc.u = Inf;
0191     mpc.l = 600;
0192     [r, success] = rundcopf(mpc, mpopt);
0193     t_ok(~success, [t 'no success']);
0194 
0195     %% OPF with all buses isolated
0196     t = [t0 'all buses isolated : '];
0197     mpc = loadcase(casefile);
0198     mpc.bus(:, BUS_TYPE) = NONE;
0199     try
0200         r = rundcopf(mpc, mpopt);
0201         t_is(r.success, 0, 12, [t 'success = 0']);
0202     catch
0203         t_ok(0, [t 'unexpected fatal error']);
0204     end
0205 
0206     end
0207 else
0208     t_skip(num_tests, 'MOSEK not available');
0209 end
0210 
0211 t_end;

Generated on Mon 24-Jun-2019 15:58:45 by m2html © 2005