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