Home > matpower5.1 > t > t_mpoption.m

t_mpoption

PURPOSE ^

T_MPOPTION Tests for MPOPTION.

SYNOPSIS ^

function t_mpoption(quiet)

DESCRIPTION ^

T_MPOPTION  Tests for MPOPTION.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function t_mpoption(quiet)
0002 %T_MPOPTION  Tests for MPOPTION.
0003 
0004 %   MATPOWER
0005 %   Copyright (c) 2013-2015 by Power System Engineering Research Center (PSERC)
0006 %   by Ray Zimmerman, PSERC Cornell
0007 %
0008 %   $Id: t_mpoption.m 2660 2015-03-20 02:10:18Z 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 v = 8;
0019 
0020 t_begin(138, quiet);
0021 
0022 %% default options struct
0023 t = 'mpoption() : ';
0024 mpopt = mpoption();
0025 t_ok(isstruct(mpopt), [t 'isstruct mpopt']);
0026 t_ok(isfield(mpopt, 'v'), [t ' isfield mpopt.v']);
0027 t_is(mpopt.v, v, 12, [t '         mpopt.v == ' sprintf('%d', v)]);
0028 
0029 t_ok(isfield(mpopt, 'model'), [t ' isfield mpopt.model']);
0030 t_ok(strcmp(mpopt.model, 'AC'), [t '         mpopt.model = ''AC''']);
0031 
0032 t_ok(isfield(mpopt, 'pf'), [t ' isfield mpopt.pf']);
0033 t_ok(isstruct(mpopt.pf), [t 'isstruct mpopt.pf']);
0034 t_ok(isfield(mpopt.pf, 'alg'), [t ' isfield mpopt.pf.alg']);
0035 t_ok(strcmp(mpopt.pf.alg, 'NR'), [t '         mpopt.pf.alg = ''NR''']);
0036 t_ok(isfield(mpopt.pf, 'tol'), [t ' isfield mpopt.pf.tol']);
0037 t_is(mpopt.pf.tol, 1e-8, 12, [t '         mpopt.pf.tol == 1e-8']);
0038 t_ok(isfield(mpopt.pf, 'nr'), [t ' isfield mpopt.pf.nr']);
0039 t_ok(isstruct(mpopt.pf.nr), [t 'isstruct mpopt.pf.nr']);
0040 t_ok(isfield(mpopt.pf.nr, 'max_it'), [t ' isfield mpopt.pf.nr.max_it']);
0041 t_is(mpopt.pf.nr.max_it, 10, 12, [t '         mpopt.pf.nr.max_it == 10']);
0042 t_ok(isfield(mpopt.pf, 'fd'), [t ' isfield mpopt.pf.fd']);
0043 t_ok(isstruct(mpopt.pf.fd), [t 'isstruct mpopt.pf.fd']);
0044 t_ok(isfield(mpopt.pf.fd, 'max_it'), [t ' isfield mpopt.pf.fd.max_it']);
0045 t_is(mpopt.pf.fd.max_it, 30, 12, [t '         mpopt.pf.fd.max_it == 30']);
0046 t_ok(isfield(mpopt.pf, 'gs'), [t ' isfield mpopt.pf.gs']);
0047 t_ok(isstruct(mpopt.pf.gs), [t 'isstruct mpopt.pf.gs']);
0048 t_ok(isfield(mpopt.pf.gs, 'max_it'), [t ' isfield mpopt.pf.gs.max_it']);
0049 t_is(mpopt.pf.gs.max_it, 1000, 12, [t '         mpopt.pf.gs.max_it == 1000']);
0050 t_ok(isfield(mpopt.pf, 'enforce_q_lims'), [t ' isfield mpopt.pf.enforce_q_lims']);
0051 t_is(mpopt.pf.enforce_q_lims, 0, 12, [t '         mpopt.pf.enforce_q_lims == 0']);
0052 
0053 t_ok(isfield(mpopt, 'opf'), [t ' isfield mpopt.opf']);
0054 t_ok(isstruct(mpopt.opf), [t 'isstruct mpopt.opf']);
0055 t_ok(isfield(mpopt.opf, 'ac'), [t ' isfield mpopt.opf.ac']);
0056 t_ok(isstruct(mpopt.opf.ac), [t 'isstruct mpopt.opf.ac']);
0057 t_ok(isfield(mpopt.opf.ac, 'solver'), [t ' isfield mpopt.opf.ac.solver']);
0058 t_ok(strcmp(mpopt.opf.ac.solver, 'DEFAULT'), [t '         mpopt.opf.ac.solver = ''DEFAULT''']);
0059 t_ok(isfield(mpopt.opf, 'dc'), [t ' isfield mpopt.opf.dc']);
0060 t_ok(isstruct(mpopt.opf.dc), [t 'isstruct mpopt.opf.dc']);
0061 t_ok(isfield(mpopt.opf.dc, 'solver'), [t ' isfield mpopt.opf.dc.solver']);
0062 t_ok(strcmp(mpopt.opf.dc.solver, 'DEFAULT'), [t '         mpopt.opf.dc.solver = ''DEFAULT''']);
0063 t_ok(isfield(mpopt.opf, 'violation'), [t ' isfield mpopt.opf.violation']);
0064 t_is(mpopt.opf.violation, 5e-6, 12, [t '         mpopt.opf.violation == 5e-6']);
0065 t_ok(isfield(mpopt.opf, 'flow_lim'), [t ' isfield mpopt.opf.flow_lim']);
0066 t_ok(strcmp(upper(mpopt.opf.flow_lim), 'S'), [t '         mpopt.opf.flow_lim = ''S''']);
0067 t_ok(isfield(mpopt.opf, 'ignore_angle_lim'), [t ' isfield mpopt.opf.ignore_angle_lim']);
0068 t_is(mpopt.opf.ignore_angle_lim, 0, 12, [t '         mpopt.opf.ignore_angle_lim == 0']);
0069 t_ok(isfield(mpopt.opf, 'return_raw_der'), [t ' isfield mpopt.opf.return_raw_der']);
0070 t_is(mpopt.opf.return_raw_der, 0, 12, [t '         mpopt.opf.return_raw_der == 0']);
0071 
0072 t_ok(isfield(mpopt, 'out'), [t ' isfield mpopt.out']);
0073 t_ok(isstruct(mpopt.out), [t 'isstruct mpopt.out']);
0074 t_ok(isfield(mpopt.out, 'all'), [t ' isfield mpopt.out.all']);
0075 t_is(mpopt.out.all, -1, 12, [t '         mpopt.out.all == -1']);
0076 t_ok(isfield(mpopt.out, 'sys_sum'), [t ' isfield mpopt.out.sys_sum']);
0077 t_is(mpopt.out.sys_sum, 1, 12, [t '         mpopt.out.sys_sum == 1']);
0078 t_ok(isfield(mpopt.out, 'area_sum'), [t ' isfield mpopt.out.area_sum']);
0079 t_is(mpopt.out.area_sum, 0, 12, [t '         mpopt.out.area_sum == 0']);
0080 t_ok(isfield(mpopt.out, 'bus'), [t ' isfield mpopt.out.bus']);
0081 t_is(mpopt.out.bus, 1, 12, [t '         mpopt.out.bus == 1']);
0082 t_ok(isfield(mpopt.out, 'branch'), [t ' isfield mpopt.out.branch']);
0083 t_is(mpopt.out.branch, 1, 12, [t '         mpopt.out.branch == 1']);
0084 t_ok(isfield(mpopt.out, 'gen'), [t ' isfield mpopt.out.gen']);
0085 t_is(mpopt.out.gen, 0, 12, [t '         mpopt.out.gen == 0']);
0086 t_ok(isfield(mpopt.out, 'lim'), [t ' isfield mpopt.out.lim']);
0087 t_ok(isstruct(mpopt.out.lim), [t 'isstruct mpopt.out.lim']);
0088 t_ok(isfield(mpopt.out.lim, 'all'), [t ' isfield mpopt.out.lim.all']);
0089 t_is(mpopt.out.lim.all, -1, 12, [t '         mpopt.out.lim.all == -1']);
0090 t_ok(isfield(mpopt.out.lim, 'v'), [t ' isfield mpopt.out.lim.v']);
0091 t_is(mpopt.out.lim.v, 1, 12, [t '         mpopt.out.lim.v == 1']);
0092 t_ok(isfield(mpopt.out.lim, 'line'), [t ' isfield mpopt.out.lim.line']);
0093 t_is(mpopt.out.lim.line, 1, 12, [t '         mpopt.out.lim.line == 1']);
0094 t_ok(isfield(mpopt.out.lim, 'pg'), [t ' isfield mpopt.out.lim.pg']);
0095 t_is(mpopt.out.lim.pg, 1, 12, [t '         mpopt.out.lim.pg == 1']);
0096 t_ok(isfield(mpopt.out.lim, 'qg'), [t ' isfield mpopt.out.lim.qg']);
0097 t_is(mpopt.out.lim.qg, 1, 12, [t '         mpopt.out.lim.qg == 1']);
0098 t_ok(isfield(mpopt.out, 'force'), [t ' isfield mpopt.out.force']);
0099 t_is(mpopt.out.force, 0, 12, [t '         mpopt.out.force == 0']);
0100 
0101 t_ok(isfield(mpopt, 'verbose'), [t ' isfield mpopt.verbose']);
0102 t_is(mpopt.verbose, 1, 12, [t '         mpopt.verbose == 1']);
0103 
0104 mpopt0 = mpopt;
0105 
0106 t = 'mpoption(mpoption(), []) == mpoption_old()';
0107 mpopt_v = mpoption_old;
0108 t_is(mpoption(mpopt0, []), mpopt_v, 12, t);
0109 
0110 t = 'mpoption(ov) : ';
0111 ov = struct('verbose', 3, 'model', 'DC', 'opf', struct('dc', struct('solver', 'MIPS')));
0112 mpopt = mpoption(ov);
0113 t_is(mpopt.verbose, 3, 12, [t 'mpopt.verbose']);
0114 t_ok(strcmp(upper(mpopt.model), 'DC'), [t 'mpopt.model']);
0115 t_ok(strcmp(mpopt.opf.dc.solver, 'MIPS'), [t 'mpopt.opf.dc.solver']);
0116 mpopt.verbose = 1;
0117 mpopt.model = 'AC';
0118 mpopt.opf.dc.solver = 'DEFAULT';
0119 %% The following line appears to work around a bizarre bug in Matlab 7.0.4 (Mac)
0120 %% that caused the next test, and subsequent 'everything else' tests, to fail
0121 %% mysteriously (but not if a debugger breakpoint was set).
0122 isequal(mpopt, mpopt0);
0123 t_ok(isequal(mpopt, mpopt0), [t 'everything else']);
0124 
0125 t = 'mpoption(''t_mpoption_ov'') : ';
0126 mpopt = mpoption('t_mpoption_ov');
0127 t_is(mpopt.verbose, 2, 12, [t 'mpopt.verbose']);
0128 t_ok(strcmp(upper(mpopt.model), 'DC'), [t 'mpopt.model']);
0129 t_ok(strcmp(mpopt.opf.dc.solver, 'CPLEX'), [t 'mpopt.opf.dc.solver']);
0130 mpopt.verbose = 1;
0131 mpopt.model = 'AC';
0132 mpopt.opf.dc.solver = 'DEFAULT';
0133 t_ok(isequal(mpopt, mpopt0), [t 'everything else']);
0134 
0135 t = 'mpoption(<new-style pairs>) : ';
0136 mpopt = mpoption('verbose', 3, 'opf.dc.solver', 'MIPS', 'model', 'DC');
0137 t_is(mpopt.verbose, 3, 12, [t 'mpopt.verbose']);
0138 t_ok(strcmp(upper(mpopt.model), 'DC'), [t 'mpopt.model']);
0139 t_ok(strcmp(mpopt.opf.dc.solver, 'MIPS'), [t 'mpopt.opf.dc.solver']);
0140 mpopt.verbose = 1;
0141 mpopt.model = 'AC';
0142 mpopt.opf.dc.solver = 'DEFAULT';
0143 t_ok(isequal(mpopt, mpopt0), [t 'everything else']);
0144 
0145 t = 'mpoption(<old-style pairs>) : ';
0146 mpopt = mpoption('VERBOSE', 0, 'PF_DC', 1, 'OPF_ALG_DC', 250);
0147 t_is(mpopt.verbose, 0, 12, [t 'mpopt.verbose']);
0148 t_ok(strcmp(upper(mpopt.model), 'DC'), [t 'mpopt.model']);
0149 t_ok(strcmp(mpopt.opf.dc.solver, 'MIPS'), [t 'mpopt.opf.dc.solver']);
0150 t_is(mpopt.mips.step_control, 1, 12, [t 'mpopt.mips.step_control']);
0151 mpopt.verbose = 1;
0152 mpopt.model = 'AC';
0153 mpopt.opf.dc.solver = 'DEFAULT';
0154 mpopt.mips.step_control = 0;
0155 mpopt = delete_missing_optional_fields(mpopt, mpopt0);
0156 t_ok(isequal(mpopt, mpopt0), [t 'everything else']);
0157 
0158 t = 'mpoption(default_mpopt_v) : ';
0159 mpopt = mpoption(mpopt_v);
0160 mpopt = delete_missing_optional_fields(mpopt, mpopt0);
0161 t_ok(isequal(mpopt, mpopt0), t);
0162 
0163 t = 'mpoption(mpopt_v) : ';
0164 mpopt_v1 = mpoption_old('VERBOSE', 0, 'PF_DC', 1, 'OPF_ALG_DC', 250);
0165 mpopt = mpoption(mpopt_v1);
0166 t_is(mpopt.verbose, 0, 12, [t 'mpopt.verbose']);
0167 t_ok(strcmp(upper(mpopt.model), 'DC'), [t 'mpopt.model']);
0168 t_ok(strcmp(mpopt.opf.dc.solver, 'MIPS'), [t 'mpopt.opf.dc.solver']);
0169 t_is(mpopt.mips.step_control, 1, 12, [t 'mpopt.mips.step_control']);
0170 mpopt.verbose = 1;
0171 mpopt.model = 'AC';
0172 mpopt.opf.dc.solver = 'DEFAULT';
0173 mpopt.mips.step_control = 0;
0174 mpopt = delete_missing_optional_fields(mpopt, mpopt0);
0175 t_ok(isequal(mpopt, mpopt0), [t 'everything else']);
0176 
0177 t = 'mpoption(mpopt_v, ov) : ';
0178 ov = struct('verbose', 3, 'model', 'AC', 'opf', struct('ac', struct('solver', 'MIPS')));
0179 mpopt = mpoption(mpopt_v1, ov);
0180 t_is(mpopt.verbose, 3, 12, [t 'mpopt.verbose']);
0181 t_ok(strcmp(upper(mpopt.model), 'AC'), [t 'mpopt.model']);
0182 t_ok(strcmp(mpopt.opf.dc.solver, 'MIPS'), [t 'mpopt.opf.dc.solver']);
0183 t_is(mpopt.mips.step_control, 1, 12, [t 'mpopt.mips.step_control']);
0184 t_ok(strcmp(mpopt.opf.ac.solver, 'MIPS'), [t 'mpopt.opf.ac.solver']);
0185 mpopt.verbose = 1;
0186 mpopt.opf.dc.solver = 'DEFAULT';
0187 mpopt.mips.step_control = 0;
0188 mpopt.opf.ac.solver = 'DEFAULT';
0189 mpopt = delete_missing_optional_fields(mpopt, mpopt0);
0190 t_ok(isequal(mpopt, mpopt0), [t 'everything else']);
0191 
0192 t = 'mpoption(mpopt_v, ''t_mpoption_ov'') : ';
0193 mpopt = mpoption(mpopt_v1, 't_mpoption_ov');
0194 t_is(mpopt.verbose, 2, 12, [t 'mpopt.verbose']);
0195 t_ok(strcmp(upper(mpopt.model), 'DC'), [t 'mpopt.model']);
0196 t_ok(strcmp(mpopt.opf.dc.solver, 'CPLEX'), [t 'mpopt.opf.dc.solver']);
0197 t_is(mpopt.mips.step_control, 1, 12, [t 'mpopt.mips.step_control']);
0198 mpopt.verbose = 1;
0199 mpopt.model = 'AC';
0200 mpopt.opf.dc.solver = 'DEFAULT';
0201 mpopt.mips.step_control = 0;
0202 mpopt = delete_missing_optional_fields(mpopt, mpopt0);
0203 t_ok(isequal(mpopt, mpopt0), [t 'everything else']);
0204 
0205 %%-----  this doesn't work, and isn't intended to  -----
0206 % t = 'mpoption(mpopt_v, <new-style pairs>) : ';
0207 % mpopt = mpoption(mpopt_v1, 'verbose', 3, 'model', 'AC', 'opf.ac.solver', 'MIPS');
0208 % t_is(mpopt.verbose, 3, 12, [t 'mpopt.verbose']);
0209 % t_ok(strcmp(upper(mpopt.model), 'AC'), [t 'mpopt.model']);
0210 % t_ok(strcmp(mpopt.opf.dc.solver, 'MIPS'), [t 'mpopt.opf.dc.solver']);
0211 % t_is(mpopt.mips.step_control, 1, 12, [t 'mpopt.mips.step_control']);
0212 % t_ok(strcmp(mpopt.opf.ac.solver, 'MIPS'), [t 'mpopt.opf.ac.solver']);
0213 % mpopt.verbose = 1;
0214 % mpopt.opf.dc.solver = 'DEFAULT';
0215 % mpopt.mips.step_control = 0;
0216 % mpopt.opf.ac.solver = 'DEFAULT';
0217 % mpopt = delete_missing_optional_fields(mpopt, mpopt0);
0218 % t_ok(isequal(mpopt, mpopt0), [t 'everything else']);
0219 
0220 t = 'mpoption(mpopt_v, <old-style pairs>) : ';
0221 mpopt = mpoption(mpopt_v1, 'VERBOSE', 3, 'PF_DC', 0, 'OPF_ALG', 520);
0222 t_is(mpopt.verbose, 3, 12, [t 'mpopt.verbose']);
0223 t_ok(strcmp(upper(mpopt.model), 'AC'), [t 'mpopt.model']);
0224 t_ok(strcmp(mpopt.opf.dc.solver, 'MIPS'), [t 'mpopt.opf.dc.solver']);
0225 t_is(mpopt.mips.step_control, 1, 12, [t 'mpopt.mips.step_control']);
0226 t_ok(strcmp(mpopt.opf.ac.solver, 'FMINCON'), [t 'mpopt.opf.ac.solver']);
0227 mpopt.verbose = 1;
0228 mpopt.opf.dc.solver = 'DEFAULT';
0229 mpopt.mips.step_control = 0;
0230 mpopt.opf.ac.solver = 'DEFAULT';
0231 mpopt = delete_missing_optional_fields(mpopt, mpopt0);
0232 t_ok(isequal(mpopt, mpopt0), [t 'everything else']);
0233 
0234 t = 'mpoption(mpopt) : ';
0235 mpopt1 = mpoption('verbose', 0, 'model', 'DC', 'out.gen', 1, 'opf.dc.solver', 'GUROBI');
0236 mpopt = mpoption(mpopt1);
0237 t_ok(isequal(mpopt, mpopt1), [t 'unchanged']);
0238 
0239 t = 'mpoption(mpopt, ov) : ';
0240 ov = struct('verbose', 3, 'model', 'AC', 'opf', struct('ac', struct('solver', 'KNITRO')));
0241 mpopt = mpoption(mpopt1, ov);
0242 t_is(mpopt.verbose, 3, 12, [t 'mpopt.verbose']);
0243 t_ok(strcmp(upper(mpopt.model), 'AC'), [t 'mpopt.model']);
0244 t_ok(strcmp(mpopt.opf.dc.solver, 'GUROBI'), [t 'mpopt.opf.dc.solver']);
0245 t_is(mpopt.out.gen, 1, 12, [t 'mpopt.out.gen']);
0246 t_ok(strcmp(mpopt.opf.ac.solver, 'KNITRO'), [t 'mpopt.opf.ac.solver']);
0247 mpopt.verbose = 1;
0248 mpopt.opf.dc.solver = 'DEFAULT';
0249 mpopt.out.gen = 0;
0250 mpopt.opf.ac.solver = 'DEFAULT';
0251 t_ok(isequal(mpopt, mpopt0), [t 'everything else']);
0252 
0253 t = 'mpoption(mpopt, ''t_mpoption_ov'') : ';
0254 mpopt = mpoption(mpopt1, 't_mpoption_ov');
0255 t_is(mpopt.verbose, 2, 12, [t 'mpopt.verbose']);
0256 t_ok(strcmp(upper(mpopt.model), 'DC'), [t 'mpopt.model']);
0257 t_ok(strcmp(mpopt.opf.dc.solver, 'CPLEX'), [t 'mpopt.opf.dc.solver']);
0258 t_is(mpopt.out.gen, 1, 12, [t 'mpopt.out.gen']);
0259 mpopt.verbose = 1;
0260 mpopt.model = 'AC';
0261 mpopt.opf.dc.solver = 'DEFAULT';
0262 mpopt.out.gen = 0;
0263 t_ok(isequal(mpopt, mpopt0), [t 'everything else']);
0264 
0265 t = 'mpoption(mpopt, <new-style pairs>) : ';
0266 mpopt = mpoption(mpopt1, 'verbose', 3, 'model', 'AC', 'opf.ac.solver', 'KNITRO');
0267 t_is(mpopt.verbose, 3, 12, [t 'mpopt.verbose']);
0268 t_ok(strcmp(upper(mpopt.model), 'AC'), [t 'mpopt.model']);
0269 t_ok(strcmp(mpopt.opf.dc.solver, 'GUROBI'), [t 'mpopt.opf.dc.solver']);
0270 t_is(mpopt.out.gen, 1, 12, [t 'mpopt.out.gen']);
0271 t_ok(strcmp(mpopt.opf.ac.solver, 'KNITRO'), [t 'mpopt.opf.ac.solver']);
0272 mpopt.verbose = 1;
0273 mpopt.opf.dc.solver = 'DEFAULT';
0274 mpopt.out.gen = 0;
0275 mpopt.opf.ac.solver = 'DEFAULT';
0276 t_ok(isequal(mpopt, mpopt0), [t 'everything else']);
0277 
0278 t = 'mpoption(mpopt, <old-style pairs>) : ';
0279 mpopt = mpoption(mpopt1, 'VERBOSE', 3, 'PF_DC', 0, 'OPF_ALG', 580);
0280 t_is(mpopt.verbose, 3, 12, [t 'mpopt.verbose']);
0281 t_ok(strcmp(upper(mpopt.model), 'AC'), [t 'mpopt.model']);
0282 t_ok(strcmp(mpopt.opf.dc.solver, 'GUROBI'), [t 'mpopt.opf.dc.solver']);
0283 t_is(mpopt.out.gen, 1, 12, [t 'mpopt.out.gen']);
0284 t_ok(strcmp(mpopt.opf.ac.solver, 'IPOPT'), [t 'mpopt.opf.ac.solver']);
0285 mpopt.verbose = 1;
0286 mpopt.opf.dc.solver = 'DEFAULT';
0287 mpopt.out.gen = 0;
0288 mpopt.opf.ac.solver = 'DEFAULT';
0289 t_ok(isequal(mpopt, mpopt0), [t 'everything else']);
0290 
0291 t_end;
0292 
0293 
0294 function opt = delete_missing_optional_fields(opt, unless)
0295 %% deletes the fields from opt, unless they are found in unless
0296 %% (which is empty by default)
0297 %pkgs = {'cplex', 'sdp_pf', 'sopf', 'yalmip'};
0298 pkgs = {...
0299     'cplex', 'fmincon', 'gurobi', 'ipopt', 'knitro', 'minopf', ...
0300     'mosek', 'sopf', 'pdipm', 'tralm', ...
0301 };
0302 if nargin < 2
0303     unless = struct;
0304 end
0305 for k = 1:length(pkgs)
0306     if ~isfield(unless, pkgs{k}) && isfield(opt, pkgs{k})
0307         opt = rmfield(opt, pkgs{k});
0308     end
0309 end

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