📄 t_opf.m
字号:
function t_opf(quiet)%T_OPF Tests for optimal power flow.% MATPOWER% $Id: t_opf.m,v 1.7 2005/02/03 18:57:42 ray Exp $% by Ray Zimmerman, PSERC Cornell% Copyright (c) 2004 by Power System Engineering Research Center (PSERC)% See http://www.pserc.cornell.edu/matpower/ for more info.if nargin < 1 quiet = 0;endt_begin(55, quiet);casefile = 't_case9_opf';if quiet verbose = 0;else verbose = 0;endmpopt = mpoption('OUT_ALL', 0, 'VERBOSE', verbose);%% get solved AC power flow case from MAT-fileload soln9_opf; %% defines bus_soln, gen_soln, branch_soln%% run default OPFt = 'default OPF : ';[baseMVA, bus, gen, gencost, branch, f, success, et] = runopf(casefile, mpopt);t_ok(success, [t 'success']);t_is(f, f_soln, 3, [t 'f']);t_is(bus, bus_soln, 3, [t 'bus']);t_is(gen, gen_soln, 3, [t 'gen']);t_is(branch, branch_soln, 3, [t 'branch']);%% run minopf OPFif have_fcn('minopf') t = 'minopf OPF : '; mpopt = mpoption(mpopt, 'OPF_ALG', 500); [baseMVA, bus, gen, gencost, branch, f, success, et] = runopf(casefile, mpopt); t_ok(success, [t 'success']); t_is(f, f_soln, 2, [t 'f']); t_is(bus, bus_soln, 3, [t 'bus']); t_is(gen, gen_soln, 2, [t 'gen']); t_is(branch, branch_soln, 2, [t 'branch']);else t_skip(5, 'MINOPF not available');end%% run fmincon OPFif have_fcn('fmincon') t = 'fmincon OPF : '; mpopt = mpoption(mpopt, 'OPF_ALG', 520); [baseMVA, bus, gen, gencost, branch, f, success, et] = runopf(casefile, mpopt); t_ok(success, [t 'success']); t_is(f, f_soln, 2, [t 'f']); t_is(bus, bus_soln, 2, [t 'bus']); t_is(gen, gen_soln, 2, [t 'gen']); t_is(branch, branch_soln, 2, [t 'branch']);else t_skip(5, 'fmincon not available');end%% run constr OPFif have_fcn('constr') t = 'constr OPF : '; mpopt = mpoption(mpopt, 'OPF_ALG', 200); [baseMVA, bus, gen, gencost, branch, f, success, et] = runopf(casefile, mpopt); t_ok(success, [t 'success']); t_is(f, f_soln, 2, [t 'f']); t_is(bus, bus_soln, 2, [t 'bus']); t_is(gen, gen_soln, 2, [t 'gen']); t_is(branch, branch_soln, 2, [t 'branch']);else t_skip(5, 'constr not available');end%% run dense LP-based OPFt = 'dense LP-based OPF : ';mpopt = mpoption(mpopt, 'OPF_ALG', 220);[baseMVA, bus, gen, gencost, branch, f, success, et] = runopf(casefile, mpopt);t_ok(success, [t 'success']);t_is(f, f_soln, 2, [t 'f']);t_is(bus, bus_soln, 2, [t 'bus']);t_is(gen, gen_soln, 2, [t 'gen']);t_is(branch, branch_soln, 2, [t 'branch']);%% run sparse (relaxed) LP-based OPFt = 'sparse (relaxed) LP-based OPF : ';mpopt = mpoption(mpopt, 'OPF_ALG', 240);[baseMVA, bus, gen, gencost, branch, f, success, et] = runopf(casefile, mpopt);t_ok(success, [t 'success']);t_is(f, f_soln, 2, [t 'f']);t_is(bus, bus_soln, 2, [t 'bus']);t_is(gen, gen_soln, 2, [t 'gen']);t_is(branch, branch_soln, 2, [t 'branch']);%% run sparse (full) LP-based OPFt = 'sparse (full) LP-based OPF : ';mpopt = mpoption(mpopt, 'OPF_ALG', 260);[baseMVA, bus, gen, gencost, branch, f, success, et] = runopf(casefile, mpopt);t_ok(success, [t 'success']);t_is(f, f_soln, 2, [t 'f']);t_is(bus, bus_soln, 2, [t 'bus']);t_is(gen, gen_soln, 2, [t 'gen']);t_is(branch, branch_soln, 2, [t 'branch']);%% get solved AC power flow case from MAT-fileload soln9_opf_Plim; %% defines bus_soln, gen_soln, branch_soln, f_soln%% run fmincon OPF with active power line limitsmpopt = mpoption(mpopt, 'OPF_P_LINE_LIM', 1);if have_fcn('fmincon') t = 'fmincon OPF (P line lim) : '; mpopt = mpoption(mpopt, 'OPF_ALG', 520); [baseMVA, bus, gen, gencost, branch, f, success, et] = runopf(casefile, mpopt); t_ok(success, [t 'success']); t_is(f, f_soln, 2, [t 'f']); t_is(bus(:,1:15), bus_soln(:,1:15), 1, [t 'bus']); %% skip MU_VMAX, MU_VMIN multipliers t_is(gen, gen_soln, 1, [t 'gen']); t_is(branch, branch_soln, 1, [t 'branch']);else t_skip(5, 'fmincon not available');end%% run constr OPF with active power line limitsif have_fcn('constr') t = 'constr OPF (P line lim) : '; mpopt = mpoption(mpopt, 'OPF_ALG', 200); [baseMVA, bus, gen, gencost, branch, f, success, et] = runopf(casefile, mpopt); t_ok(success, [t 'success']); t_is(f, f_soln, 2, [t 'f']); t_is(bus, bus_soln, 2, [t 'bus']); t_is(gen, gen_soln, 2, [t 'gen']); t_is(branch, branch_soln, 2, [t 'branch']);else t_skip(5, 'constr not available');end%% run sparse (relaxed) LP-based OPF with active power line limitst = 'sparse (relaxed) LP-based OPF (P line lim) : ';mpopt = mpoption(mpopt, 'OPF_ALG', 240);[baseMVA, bus, gen, gencost, branch, f, success, et] = runopf(casefile, mpopt);t_ok(success, [t 'success']);t_is(f, f_soln, 2, [t 'f']);t_is(bus, bus_soln, 2, [t 'bus']);t_is(gen, gen_soln, 2, [t 'gen']);t_is(branch, branch_soln, 2, [t 'branch']);mpopt = mpoption(mpopt, 'OPF_P_LINE_LIM', 0);%% get solved AC power flow case from MAT-fileload soln9_dcopf; %% defines bus_soln, gen_soln, branch_soln%% run DC OPFt = 'DC OPF : ';[baseMVA, bus, gen, gencost, branch, f, success, et] = rundcopf(casefile, mpopt);t_ok(success, [t 'success']);t_is(f, f_soln, 3, [t 'f']);t_is(bus, bus_soln, 3, [t 'bus']);t_is(gen, gen_soln, 3, [t 'gen']);t_is(branch, branch_soln, 3, [t 'branch']);t_end;return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -