MPOPT2NLEQOPT Create/modify NLEQS_MASTER options struct from MPOPT. NLEQOPT = MPOPT2NLEQOPT(MPOPT, MODEL) NLEQOPT = MPOPT2NLEQOPT(MPOPT, MODEL, ALG) Uses a MATPOWER options struct, MPOPT, to create or modify an NLEQS_MASTER options struct. Inputs (default values in parentheses): MPOPT : MATPOWER options struct MODEL ('NLEQ') : (optional) one of the following model types, required for selection of solver in case ALG is 'DEFAULT' (solver precedence for each model type list in parentheses): 'NLEQ' - nonlinear equation with all continuous variables (NEWTON, FSOLVE) ALG ('opf.ac') : (optional) 'pf.alg' or any valid value of OPT.alg for NLEQS_MASTER. The first option indicates that it should be taken from MPOPT.pf.alg. Output: NLEQOPT : an options struct for use by NLEQS_MASTER and friends See NLEQS_MASTER, MPOPTION.
0001 function nleqopt = mpopt2nleqopt(mpopt, model, alg) 0002 %MPOPT2NLEQOPT Create/modify NLEQS_MASTER options struct from MPOPT. 0003 % 0004 % NLEQOPT = MPOPT2NLEQOPT(MPOPT, MODEL) 0005 % NLEQOPT = MPOPT2NLEQOPT(MPOPT, MODEL, ALG) 0006 % 0007 % Uses a MATPOWER options struct, MPOPT, to create or modify an 0008 % NLEQS_MASTER options struct. 0009 % 0010 % Inputs (default values in parentheses): 0011 % MPOPT : MATPOWER options struct 0012 % MODEL ('NLEQ') : (optional) one of the following model types, required 0013 % for selection of solver in case ALG is 'DEFAULT' (solver 0014 % precedence for each model type list in parentheses): 0015 % 'NLEQ' - nonlinear equation with all continuous variables 0016 % (NEWTON, FSOLVE) 0017 % ALG ('opf.ac') : (optional) 'pf.alg' or any valid value of 0018 % OPT.alg for NLEQS_MASTER. The first option indicates that 0019 % it should be taken from MPOPT.pf.alg. 0020 % 0021 % Output: 0022 % NLEQOPT : an options struct for use by NLEQS_MASTER and friends 0023 % 0024 % See NLEQS_MASTER, MPOPTION. 0025 0026 % MP-Opt-Model 0027 % Copyright (c) 2015-2020, Power Systems Engineering Research Center (PSERC) 0028 % by Ray Zimmerman, PSERC Cornell 0029 % 0030 % This file is part of MP-Opt-Model. 0031 % Covered by the 3-clause BSD License (see LICENSE file for details). 0032 % See https://github.com/MATPOWER/mp-opt-model for more info. 0033 0034 %% set default args 0035 if nargin < 3 0036 alg = ''; 0037 if nargin < 2 0038 model = ''; 0039 end 0040 end 0041 if isempty(model) 0042 model = 'NLEQ'; 0043 else 0044 model = upper(model); 0045 end 0046 0047 %% get ALG, MAX_IT from mpopt, if necessary 0048 switch alg 0049 case {'pf.ac', ''} 0050 alg = upper(mpopt.pf.alg); 0051 otherwise 0052 alg = upper(alg); 0053 end 0054 0055 %% create NLEQS_MASTER options struct 0056 nleqopt = struct( 'verbose', mpopt.verbose, ... 0057 'alg', alg, ... 0058 'tol', mpopt.pf.tol ); 0059 switch alg 0060 case {'DEFAULT', 'NEWTON'} 0061 %% set up options 0062 nleqopt.newton_opt.lin_solver = mpopt.pf.nr.lin_solver; 0063 nleqopt.max_it = mpopt.pf.nr.max_it; 0064 case 'FD' 0065 nleqopt.max_it = mpopt.pf.fd.max_it; 0066 case 'GS' 0067 nleqopt.max_it = mpopt.pf.gs.max_it; 0068 case 'ZG' 0069 nleqopt.max_it = mpopt.pf.zg.max_it; 0070 nleqopt.alg = 'CORE'; 0071 case 'FSOLVE' 0072 %% basic optimset options needed for fmincon 0073 % nleqopt.fsolve_opt.Algorithm = ''; 0074 % nleqopt.fsolve_opt.Algorithm = 'trust-region-dogleg'; 0075 % nleqopt.fsolve_opt.Algorithm = 'trust-region'; %% for optimoptions 0076 % nleqopt.fsolve_opt.Algorithm = 'trust-region-reflective'; %% for optimset 0077 % nleqopt.fsolve_opt.Algorithm = 'levenberg-marquardt'; 0078 nleqopt.max_it = 0; %% use fsolve default 0079 end