Home > matpower7.1 > extras > syngrid > lib > t > t_sg_options.m

t_sg_options

PURPOSE ^

T_SG_OPTIONS Tests for sg_options().

SYNOPSIS ^

function t_sg_options(quiet)

DESCRIPTION ^

T_SG_OPTIONS  Tests for sg_options().

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function t_sg_options(quiet)
0002 %T_SG_OPTIONS  Tests for sg_options().
0003 
0004 %   SynGrid
0005 %   Copyright (c) 2018, Power Systems Engineering Research Center (PSERC)
0006 %   by Ray Zimmerman, PSERC Cornell
0007 %
0008 %   This file is part of SynGrid.
0009 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0010 
0011 if nargin < 1
0012     quiet = 0;
0013 end
0014 
0015 t_begin(93, quiet);
0016 
0017 t = 'sg_options() : ';
0018 sgopt = sg_options();
0019 t_is(sgopt.verbose, 0, 12, [t 'verbose']);
0020 t_is(sgopt.bm.refsys, 2, 12, [t 'bm.refsys']);
0021 t_ok(isequal(sgopt.bm.loading, 'D'), [t 'bm.loading']);
0022 t_is(sgopt.bm.br2b_ratio, 1.5, 12, [t 'bm.br2b_ratio']);
0023 t_is(sgopt.bm.br_overload, 0, 12, [t 'bm.br_overload']);
0024 t_is(sgopt.bm.bta_method, 0, 12, [t 'bm.bta_method']);
0025 t_is(sgopt.bm.cost_model, 2, 12, [t 'bm.cost_model']);
0026 t_ok(sgopt.mpoptprint == 0, [t 'mpoptprint']);
0027 t_ok(isempty(sgopt.vm.opflogpath), [t 'vm.opflogpath']);
0028 t_is(sgopt.vm.ea.generations, 5, 12, [t 'vm.ea.generations'])
0029 t_is(sgopt.vm.ea.inds, 4, 12, [t 'vm.ea.inds'])
0030 t_is(sgopt.vm.ea.select, 5, 12, [t 'vm.ea.select'])
0031 t_is(sgopt.vm.ea.randnew, 0, 12, [t 'vm.ea.randnew'])
0032 t_is(sgopt.vm.ea.initfill, 0, 12, [t 'vm.ea.initfill'])
0033 t_is(sgopt.vm.parallel.use, 0, 12, [t 'vm.parallel.use'])
0034 t_is(sgopt.vm.parallel.numcores, 0, 12, [t 'vm.parallel.numcores'])
0035 t_is(sgopt.vm.branchperm.niter, 1, 12, [t 'vm.branchperm.niter'])
0036 t_is(sgopt.vm.branchperm.verbose, 0, 12, [t 'vm.branchperm.verbose'])
0037 t_is(sgopt.vm.branchperm.overload_frac_factor, 0.95, 12, [t 'vm.branchperm.overload_frac_factor'])
0038 t_is(sgopt.vm.nodeperm.niter, 1, 12, [t 'vm.nodeperm.niter'])
0039 t_is(sgopt.vm.nodeperm.verbose, 0, 12, [t 'vm.nodeperm.verbose'])
0040 t_is(sgopt.vm.nodeperm.nox, 1, 12, [t 'vm.nodeperm.nox'])
0041 t_is(sgopt.vm.nodeperm.usedv, 0, 12, [t 'vm.nodeperm.usedv'])
0042 t_is(sgopt.vm.nodeperm.scale_s, 1, 12, [t 'vm.nodeperm.scale_s'])
0043 t_is(sgopt.vm.nodeperm.scale_s_factor, 0.95, 12, [t 'vm.nodeperm.scale_s_factor'])
0044 t_is(sgopt.vm.shunts.tmag, 0.1, 12, [t 'vm.shunts.tmag'])
0045 t_is(sgopt.vm.shunts.shift_in, 0.015, 12, [t 'vm.shunts.shift_in'])
0046 t_is(sgopt.vm.shunts.shunt_max, 500, 12, [t 'vm.shunts.shunt_max'])
0047 t_is(sgopt.vm.shunts.verbose, 0, 12, [t 'vm.shunts.verbose'])
0048 t_is(sgopt.vm.shunts.soft_ratea, 0, 12, [t 'vm.shunts.soft_ratea'])
0049 t_ok(strcmp(sgopt.vm.smpl.branch, 'direct'), [t 'vm.smpl.branch'])
0050 t_ok(strcmp(sgopt.vm.smpl.node, 'kde'), [t 'vm.smpl.node'])
0051 t_is(sgopt.vm.smpl.lincost, 100, 12, [t 'vm.smpl.lincost'])
0052 t_is(sgopt.vm.smpl.usegenbus, 1, 12, [t 'vm.smpl.usegenbus'])
0053 t_is(sgopt.vm.smpl.ngbuses, -1, 12, [t 'vm.smpl.ngbuses'])
0054 t_is(sgopt.vm.smpl.usegen2load, 1, 12, [t 'vm.smpl.usegen2load'])
0055 t_is(sgopt.vm.smpl.baseMVA_default, 100, 12, [t 'vm.smpl.baseMVA_default'])
0056 t_is(sgopt.vm.smpl.rate_a_default, 400, 12, [t 'vm.smpl.rate_a_default'])
0057 if have_fcn('ipopt')
0058     t_ok(strcmp(sgopt.mpopt.opf.ac.solver, 'IPOPT'), [t 'AC OPF solver = ''IPOPT''']);
0059     t_is(sgopt.mpopt.ipopt.opts.max_iter, 500, 12, [t 'mpopt.ipopt.opts.max_iter'])
0060     t_is(sgopt.mpopt.ipopt.opts.tol, 1e-6, 12, [t 'mpopts.ipopt.opts.tol'])
0061     t_is(sgopt.mpopt.ipopt.opts.constr_viol_tol, 1e-6, 12, [t 'mpopts.ipopt.opts.constr_viol_tol'])
0062     t_is(sgopt.mpopt.ipopt.opts.acceptable_tol, 1e-6, 12, [t 'mpopts.ipopt.opts.acceptable_tol'])
0063     t_is(sgopt.mpopt.ipopt.opts.dual_inf_tol, 1e-5, 12, [t 'mpopts.ipopt.opts.dual_inf_tol'])
0064     % check that MIPS is default if IPOPT not available
0065     have_fcn('ipopt', 0);
0066     sgopt = sg_options();
0067     t_ok(strcmp(sgopt.mpopt.opf.ac.solver, 'DEFAULT'), [t 'AC OPF solver = ''DEFAULT''']);
0068     have_fcn('ipopt', 1);
0069 else
0070     t_skip(6, 'IPOPT not installed')
0071     t_ok(strcmp(sgopt.mpopt.opf.ac.solver, 'DEFAULT'), [t 'AC OPF solver = ''DEFAULT''']);
0072 end
0073 
0074 t = 'sg_options(ov1) : ';
0075 ov1 = struct(...
0076     'verbose',      2, ...          %% no progress output
0077     'bm', struct( ...
0078         'loading',      'L', ...    %% low
0079         'bta_method',   1 ) ...     %% "W0" method - simpler, faster
0080 );
0081 sgopt = sg_options(ov1);
0082 t_is(sgopt.verbose, 2, 12, [t 'verbose']);
0083 t_is(sgopt.bm.refsys, 2, 12, [t 'bm.refsys']);
0084 t_ok(isequal(sgopt.bm.loading, 'L'), [t 'bm.loading']);
0085 t_is(sgopt.bm.br2b_ratio, 1.5, 12, [t 'bm.br2b_ratio']);
0086 t_is(sgopt.bm.bta_method, 1, 12, [t 'bm.bta_method']);
0087 
0088 t = 'sg_options(ov2) : ';
0089 ov2 = struct(...
0090     'bm', struct( ...
0091         'refsys',       3, ...
0092         'loading',      'H', ...    %% high
0093         'br2b_ratio',   2.5 ) ...
0094 );
0095 sgopt = sg_options(ov2);
0096 t_is(sgopt.verbose, 0, 12, [t 'verbose']);
0097 t_is(sgopt.bm.refsys, 3, 12, [t 'bm.refsys']);
0098 t_ok(isequal(sgopt.bm.loading, 'H'), [t 'bm.loading']);
0099 t_is(sgopt.bm.br2b_ratio, 2.5, 12, [t 'bm.br2b_ratio']);
0100 t_is(sgopt.bm.bta_method, 0, 12, [t 'bm.bta_method']);
0101 
0102 if have_fcn('ipopt')
0103     t = 'sg_options(ov3) + IPOPT : ';
0104     ov3 = struct('mpopt', mpoption('ipopt.opts.max_iter', 300, 'ipopt.opts.tol', 1e-4));
0105     sgopt = sg_options(ov3);
0106     t_is(sgopt.mpopt.ipopt.opts.max_iter, 300, 12, [t 'mpopt.ipopt.opts.max_iter'])
0107     t_is(sgopt.mpopt.ipopt.opts.tol, 1e-4, 12, [t 'mpopts.ipopt.opts.tol'])
0108 else
0109     t_skip(2, 'IPOPT not installed')
0110 end
0111 
0112 % check mpoptprint functionality
0113 t = 'sg_options(ov4) (mpoptprint = 0) : ';
0114 ov4 = struct('mpopt', mpoption('verbose', 1, 'out.all', 1));
0115 sgopt = sg_options(ov4);
0116 t_is(sgopt.mpopt.out.all, 0, 12, [t 'mpopt.out.all'])
0117 t_is(sgopt.mpopt.verbose, 0, 12, [t 'mpopt.verose'])
0118 t = 'sg_options(ov4) (mpoptprint = 1) : ';
0119 ov4 = struct('mpoptprint', 1, 'mpopt', mpoption('verbose', 1, 'out.all', 1));
0120 sgopt = sg_options(ov4);
0121 t_is(sgopt.mpopt.out.all, 1, 12, [t 'mpopt.out.all'])
0122 t_is(sgopt.mpopt.verbose, 1, 12, [t 'mpopt.verose'])
0123 
0124 % name value test
0125 t = 'sg_options(name, val ...) : ';
0126 sgopt0 = sg_options('verbose', 2, 'vm.ea.generations', 10, 'bm.br2b_ratio', 2.5);
0127 t_ok(sgopt0.verbose == 2, [t 'verbose']);
0128 t_ok(sgopt0.vm.ea.generations == 10, [t 'vm.ea.generations']);
0129 t_is(sgopt0.bm.br2b_ratio, 2.5, 12, [t 'bm.br2b_ratio']);
0130 
0131 % update options structure
0132 t = 'sg_options(sgopt0, name, val ...) : ';
0133 sgopt = sg_options(sgopt0, 'vm.smpl.lincost', 150, 'vm.shunts.tmag', 0.5);
0134 t_ok(sgopt.verbose == 2, [t 'verbose']);
0135 t_ok(sgopt.vm.ea.generations == 10, [t 'vm.ea.generations']);
0136 t_is(sgopt.bm.br2b_ratio, 2.5, 12, [t 'bm.br2b_ratio']);
0137 t_ok(sgopt.vm.smpl.lincost == 150, [t 'vm.smpl.lincost']);
0138 t_is(sgopt.vm.shunts.tmag, 0.5, 12, [t 'vm.shunts.tmag']);
0139 
0140 if have_fcn('ipopt')
0141     t = 'sg_options(sgopt0, name, val ...) + IPOPT : ';
0142     sgopt = sg_options(sgopt0, 'mpopt.ipopt.opts.max_iter', 300, 'mpopt.ipopt.opts.tol', 1e-4);
0143     t_ok(sgopt.verbose == 2, [t 'verbose']);
0144     t_ok(sgopt.vm.ea.generations == 10, [t 'vm.ea.generations']);
0145     t_is(sgopt.bm.br2b_ratio, 2.5, 12, [t 'bm.br2b_ratio']);
0146     t_is(sgopt.mpopt.ipopt.opts.max_iter, 300, 12, [t 'mpopt.ipopt.opts.max_iter'])
0147     t_is(sgopt.mpopt.ipopt.opts.tol, 1e-4, 12, [t 'mpopts.ipopt.opts.tol'])
0148 else
0149     t_skip(5, 'IPOPT not installed')
0150 end
0151 
0152 t = 'sg_options(sgopt0, ov) : ';
0153 ov = struct('vm', struct('smpl', struct('lincost', 150), 'shunts', struct('tmag', 0.5)));
0154 sgopt = sg_options(sgopt0, ov);
0155 t_ok(sgopt.verbose == 2, [t 'verbose']);
0156 t_ok(sgopt.vm.ea.generations == 10, [t 'vm.ea.generations']);
0157 t_is(sgopt.bm.br2b_ratio, 2.5, 12, [t 'bm.br2b_ratio']);
0158 t_ok(sgopt.vm.smpl.lincost == 150, [t 'vm.smpl.lincost']);
0159 t_is(sgopt.vm.shunts.tmag, 0.5, 12, [t 'vm.shunts.tmag']);
0160 
0161 if have_fcn('ipopt')
0162     t = 'sg_options(sgopt0, ov) + IPOPT : ';
0163     ov3 = struct('mpopt', mpoption('ipopt.opts.max_iter', 300, 'ipopt.opts.tol', 1e-4));
0164     sgopt = sg_options(sgopt0, ov3);
0165     t_ok(sgopt.verbose == 2, [t 'verbose']);
0166     t_ok(sgopt.vm.ea.generations == 10, [t 'vm.ea.generations']);
0167     t_is(sgopt.bm.br2b_ratio, 2.5, 12, [t 'bm.br2b_ratio']);
0168     t_is(sgopt.mpopt.ipopt.opts.max_iter, 300, 12, [t 'mpopt.ipopt.opts.max_iter'])
0169     t_is(sgopt.mpopt.ipopt.opts.tol, 1e-4, 12, [t 'mpopts.ipopt.opts.tol'])
0170 else
0171     t_skip(5, 'IPOPT not installed')
0172 end
0173 %% errors
0174 t = 'bm.refsys < 1 : ';
0175 ov = struct('bm', struct('refsys', 0));
0176 try
0177     sgopt = sg_options(ov);
0178     t_ok(0, [t 'no error thrown']);
0179 catch
0180     t_ok(1, [t 'error thrown as expected']);
0181 end
0182 
0183 t = 'bm.refsys > 3 : ';
0184 ov = struct('bm', struct('refsys', 4));
0185 try
0186     sgopt = sg_options(ov);
0187     t_ok(0, [t 'no error thrown']);
0188 catch
0189     t_ok(1, [t 'error thrown as expected']);
0190 end
0191 
0192 t = 'bm.loading not ''D'', ''L'', ''M'', or ''H'' : ';
0193 ov = struct('bm', struct('loading', 'Z'));
0194 try
0195     sgopt = sg_options(ov);
0196     t_ok(0, [t 'no error thrown']);
0197 catch
0198     t_ok(1, [t 'error thrown as expected']);
0199 end
0200 
0201 t = 'bm.loading not ''D'', ''L'', ''M'', or ''H'' : ';
0202 ov = struct('bm', struct('loading', 'My Goodness'));
0203 try
0204     sgopt = sg_options(ov);
0205     t_ok(0, [t 'no error thrown']);
0206 catch
0207     t_ok(1, [t 'error thrown as expected']);
0208 end
0209 
0210 t = 'bm.br2b_ratio < 1.25 : ';
0211 ov = struct('bm', struct('br2b_ratio', 1.24));
0212 try
0213     sgopt = sg_options(ov);
0214     t_ok(0, [t 'no error thrown']);
0215 catch
0216     t_ok(1, [t 'error thrown as expected']);
0217 end
0218 
0219 t = 'bm.br2b_ratio > 2.5 : ';
0220 ov = struct('bm', struct('br2b_ratio', 2.51));
0221 try
0222     sgopt = sg_options(ov);
0223     t_ok(0, [t 'no error thrown']);
0224 catch
0225     t_ok(1, [t 'error thrown as expected']);
0226 end
0227 
0228 t = 'bm.br_overload not 0 or 1 : ';
0229 ov = struct('bm', struct('br_overload', 0.5));
0230 try
0231     sgopt = sg_options(ov);
0232     t_ok(0, [t 'no error thrown']);
0233 catch
0234     t_ok(1, [t 'error thrown as expected']);
0235 end
0236 
0237 t = 'bm.bta_method not 0 or 1 : ';
0238 ov = struct('bm', struct('bta_method', 0.5));
0239 try
0240     sgopt = sg_options(ov);
0241     t_ok(0, [t 'no error thrown']);
0242 catch
0243     t_ok(1, [t 'error thrown as expected']);
0244 end
0245 
0246 t = 'bm.cost_model not 1 or 2 : ';
0247 ov = struct('bm', struct('cost_model', 0));
0248 try
0249     sgopt = sg_options(ov);
0250     t_ok(0, [t 'no error thrown']);
0251 catch
0252     t_ok(1, [t 'error thrown as expected']);
0253 end
0254 
0255 t_end

Generated on Fri 09-Oct-2020 11:21:31 by m2html © 2005