Home > matpower5.0 > t > t_opf_softlims.m

t_opf_softlims

PURPOSE ^

T_OPF_SOFTLIMS Tests for userfcn callbacks (softlims) w/OPF.

SYNOPSIS ^

function t_opf_softlims(quiet)

DESCRIPTION ^

T_OPF_SOFTLIMS  Tests for userfcn callbacks (softlims) w/OPF.
   Includes high-level tests of soft limits implementations.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function t_opf_softlims(quiet)
0002 %T_OPF_SOFTLIMS  Tests for userfcn callbacks (softlims) w/OPF.
0003 %   Includes high-level tests of soft limits implementations.
0004 
0005 %   MATPOWER
0006 %   $Id: t_opf_softlims.m 2433 2014-12-03 14:45:50Z ray $
0007 %   by Ray Zimmerman, PSERC Cornell
0008 %   Copyright (c) 2009-2014 by Power System Engineering Research Center (PSERC)
0009 %
0010 %   This file is part of MATPOWER.
0011 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0012 %
0013 %   MATPOWER is free software: you can redistribute it and/or modify
0014 %   it under the terms of the GNU General Public License as published
0015 %   by the Free Software Foundation, either version 3 of the License,
0016 %   or (at your option) any later version.
0017 %
0018 %   MATPOWER is distributed in the hope that it will be useful,
0019 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0020 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0021 %   GNU General Public License for more details.
0022 %
0023 %   You should have received a copy of the GNU General Public License
0024 %   along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.
0025 %
0026 %   Additional permission under GNU GPL version 3 section 7
0027 %
0028 %   If you modify MATPOWER, or any covered work, to interface with
0029 %   other modules (such as MATLAB code and MEX-files) available in a
0030 %   MATLAB(R) or comparable environment containing parts covered
0031 %   under other licensing terms, the licensors of MATPOWER grant
0032 %   you additional permission to convey the resulting work.
0033 
0034 if nargin < 1
0035     quiet = 0;
0036 end
0037 
0038 casefile = 'case9';
0039 if quiet
0040     verbose = 0;
0041 else
0042     verbose = 0;
0043 end
0044 
0045 t_begin(55, quiet);
0046 
0047 %% define constants
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 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0052     MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0053     QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0054 [PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost;
0055 
0056 %% set options
0057 mpopt = mpoption('model', 'DC', 'opf.dc.solver', 'MIPS');
0058 mpopt = mpoption(mpopt, 'opf.violation', 1e-6, 'mips.gradtol', 1e-8, ...
0059         'mips.comptol', 1e-8, 'mips.costtol', 1e-9);
0060 if verbose <= 1
0061     mpopt = mpoption(mpopt, 'out.all', 0);
0062 end
0063 mpopt = mpoption(mpopt, 'verbose', verbose);
0064 
0065 %% load and modify case file
0066 mpc = loadcase(casefile);
0067 nl = size(mpc.branch, 1);
0068 mpc.gencost(:, NCOST) = 2;
0069 mpc.gencost(:, COST) = [];
0070 mpc.gencost(:, COST) = [50; 40; 25];
0071 mpc.gencost(:, COST+1) = 0;
0072 mpc.branch(2:6, RATE_A) = [0; 120; 0; 120; 0];
0073 mpc.branch(3, RATE_A) = 120;
0074 mpc.branch(5, RATE_A) = 120;
0075 mpc.branch = [mpc.branch(1:4, :); mpc.branch(4, :);  mpc.branch(5:end, :)];
0076 mpc.branch(5, BR_STATUS) = 0;
0077 
0078 nl = size(mpc.branch, 1);   %% number of branches
0079 
0080 %% create soft limit inputs
0081 mpc.softlims.idx = (2:nl)';
0082 mpc.softlims.cost = 100 * ones(nl-1, 1);
0083 
0084 t = 'hard limits : ';
0085 t_ok(~toggle_softlims(mpc, 'status'), 'toggle_softlims(mpc, ''status'') == 0');
0086 r = runopf(mpc, mpopt);
0087 t_ok(r.success, [t 'success']);
0088 t_ok(~isfield(r.softlims, 'overload'), [t 'no softlims.overload']);
0089 t_ok(~isfield(r.softlims, 'overload'), [t 'no softlims.ovl_cost']);
0090 t_is(r.f, 9126.87, 4, [t 'f']);
0091 t_is(r.gen(:, PG), [12.687; 62.3130; 240], 4, [t 'Pg']);
0092 t_is(r.branch(:, PF), [12.687; -30; -120; 240; 0; 120; 20; -62.3130; 82.3130; -42.687], 4, [t 'Pf']);
0093 t_is(r.branch(:, MU_SF)+r.branch(:, MU_ST), [0; 0; 35.6504; 0; 0; 7.9756; 0; 0; 0; 0], 4, [t 'mu Pf']);
0094 
0095 t = 'soft limits (satisfied) : ';
0096 mpc = toggle_softlims(mpc, 'on');
0097 t_ok(toggle_softlims(mpc, 'status'), 'toggle_softlims(mpc, ''status'') == 1');
0098 r = runopf(mpc, mpopt);
0099 t_ok(r.success, [t 'success']);
0100 t_ok(isfield(r.softlims, 'overload'), [t 'softlims.overload exists']);
0101 t_ok(isfield(r.softlims, 'overload'), [t 'softlims.ovl_cost exists']);
0102 t_is(r.f, 9126.87, 4, [t 'f']);
0103 t_is(r.gen(:, PG), [12.687; 62.3130; 240], 4, [t 'Pg']);
0104 t_is(r.branch(:, PF), [12.687; -30; -120; 240; 0; 120; 20; -62.3130; 82.3130; -42.687], 4, [t 'Pf']);
0105 t_is(r.branch(:, MU_SF)+r.branch(:, MU_ST), [0; 0; 35.6504; 0; 0; 7.9756; 0; 0; 0; 0], 4, [t 'mu Pf']);
0106 t_is(r.softlims.overload, zeros(10, 1), 12, [t 'softlims.overload']);
0107 t_is(r.softlims.ovl_cost, zeros(10, 1), 12, [t 'softlims.ovl_cost']);
0108 t_is(r.order.branch.status.on(r.order.int.softlims.idx), [3; 6; 8; 9; 10], 12, [t 'mu Pf']);
0109 
0110 t = 'savecase(fname, mpc) : ';
0111 fn = sprintf('softlims_savecase_test_%d', fix(1e8*rand));
0112 savecase(fn, mpc);
0113 mpc1 = loadcase(fn);
0114 delete([fn '.m']);
0115 t_ok(isfield(mpc1, 'softlims'), [t 'mpc.softlims']);
0116 t_ok(isfield(mpc1.softlims, 'idx'), [t 'mpc.softlims.idx']);
0117 t_is(mpc1.softlims.idx, mpc.softlims.idx, 5, [t 'mpc.softlims.idx']);
0118 t_ok(isfield(mpc1.softlims, 'cost'), [t 'mpc.softlims.cost']);
0119 t_is(mpc1.softlims.cost, mpc.softlims.cost, 5, [t 'mpc.softlims.cost']);
0120 
0121 t = 'savecase(fname, results) : ';
0122 fn = sprintf('softlims_savecase_test_%d', fix(1e8*rand));
0123 savecase(fn, r);
0124 mpc1 = loadcase(fn);
0125 delete([fn '.m']);
0126 t_ok(isfield(mpc1, 'softlims'), [t 'results.softlims']);
0127 t_ok(isfield(mpc1.softlims, 'idx'), [t 'results.softlims.idx']);
0128 t_is(mpc1.softlims.idx, r.softlims.idx, 5, [t 'results.softlims.idx']);
0129 t_ok(isfield(mpc1.softlims, 'cost'), [t 'results.softlims.cost']);
0130 t_is(mpc1.softlims.cost, r.softlims.cost, 5, [t 'results.softlims.cost']);
0131 t_ok(isfield(mpc1.softlims, 'overload'), [t 'results.softlims.overload']);
0132 t_is(mpc1.softlims.overload, r.softlims.overload, 5, [t 'results.softlims.overload']);
0133 t_ok(isfield(mpc1.softlims, 'ovl_cost'), [t 'results.softlims.ovl_cost']);
0134 t_is(mpc1.softlims.ovl_cost, r.softlims.ovl_cost, 4, [t 'results.softlims.ovl_cost']);
0135 
0136 t = 'soft limits (violated) : ';
0137 mpc = rmfield(mpc, 'softlims');
0138 mpc.softlims.cost = 20;
0139 r = runopf(mpc, mpopt);
0140 t_ok(r.success, [t 'success']);
0141 t_ok(isfield(r.softlims, 'overload'), [t 'softlims.overload exists']);
0142 t_ok(isfield(r.softlims, 'overload'), [t 'softlims.ovl_cost exists']);
0143 t_is(r.f, 9106.5059, 4, [t 'f']);
0144 t_is(r.gen(:, PG), [10; 63.6988; 241.3012], 4, [t 'Pg']);
0145 t_is(r.branch(:, PF), [10; -31.3012; -121.3012; 241.3012; 0; 120; 20; -63.6988; 83.6988; -41.3012], 4, [t 'Pf']);
0146 t_is(r.branch(:, MU_SF)+r.branch(:, MU_ST), [0; 0; 20; 0; 0; 13.2992; 0; 0; 0; 0], 4, [t 'mu Pf']);
0147 t_is(r.softlims.overload, [0; 0; 1.3011811; 0; 0; 0; 0; 0; 0; 0], 6, [t 'softlims.overload']);
0148 t_is(r.softlims.ovl_cost, [0; 0; 26.023622; 0; 0; 0; 0; 0; 0; 0], 6, [t 'softlims.ovl_cost']);
0149 
0150 t = 'savecase(fname, mpc) : ';
0151 fn = sprintf('softlims_savecase_test_%d', fix(1e8*rand));
0152 savecase(fn, mpc);
0153 mpc1 = loadcase(fn);
0154 delete([fn '.m']);
0155 t_ok(isfield(mpc1, 'softlims'), [t 'mpc.softlims']);
0156 t_ok(~isfield(mpc1.softlims, 'idx'), [t 'mpc.softlims.idx']);
0157 t_ok(isfield(mpc1.softlims, 'cost'), [t 'mpc.softlims.cost']);
0158 t_is(mpc1.softlims.cost, mpc.softlims.cost, 5, [t 'mpc.softlims.cost']);
0159 
0160 t = 'savecase(fname, results) : ';
0161 fn = sprintf('softlims_savecase_test_%d', fix(1e8*rand));
0162 savecase(fn, r);
0163 mpc1 = loadcase(fn);
0164 delete([fn '.m']);
0165 t_ok(isfield(mpc1, 'softlims'), [t 'results.softlims']);
0166 t_ok(isfield(mpc1.softlims, 'idx'), [t 'results.softlims.idx']);
0167 t_ok(isempty(mpc1.softlims.idx), [t 'results.softlims.idx']);
0168 t_ok(isfield(mpc1.softlims, 'cost'), [t 'results.softlims.cost']);
0169 t_is(mpc1.softlims.cost, r.softlims.cost, 5, [t 'results.softlims.cost']);
0170 t_ok(isfield(mpc1.softlims, 'overload'), [t 'results.softlims.overload']);
0171 t_is(mpc1.softlims.overload, r.softlims.overload, 5, [t 'results.softlims.overload']);
0172 t_ok(isfield(mpc1.softlims, 'ovl_cost'), [t 'results.softlims.ovl_cost']);
0173 t_is(mpc1.softlims.ovl_cost, r.softlims.ovl_cost, 4, [t 'results.softlims.ovl_cost']);
0174 
0175 t_end;

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