MPOPT2NLPOPT Create/modify NLPS_MASTER options struct from MPOPT. NLPOPT = MPOPT2NLPOPT(MPOPT, MODEL) NLPOPT = MPOPT2NLPOPT(MPOPT, MODEL, ALG) Uses a MATPOWER options struct, MPOPT, to create or modify an NLPS_MASTER options struct. Inputs (default values in parentheses): MPOPT : MATPOWER options struct MODEL ('NLP') : (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): 'NLP' - nonlinear program with all continuous variables (MIPS, FMINCON, IPOPT, Artelys Knitro) 'MINLP' - NLP with mixed integer/continuous variables (Artelys Knitro) -- not yet implemented ALG ('opf.ac') : (optional) 'opf.ac' or any valid value of OPT.alg for NLPS_MASTER. The first option indicates that it should be taken from MPOPT.opf.ac.solver. Output: NLPOPT : an options struct for use by NLPS_MASTER and friends See NLPS_MASTER, MPOPTION.
0001 function nlpopt = mpopt2nlpopt(mpopt, model, alg) 0002 %MPOPT2NLPOPT Create/modify NLPS_MASTER options struct from MPOPT. 0003 % 0004 % NLPOPT = MPOPT2NLPOPT(MPOPT, MODEL) 0005 % NLPOPT = MPOPT2NLPOPT(MPOPT, MODEL, ALG) 0006 % 0007 % Uses a MATPOWER options struct, MPOPT, to create or modify an 0008 % NLPS_MASTER options struct. 0009 % 0010 % Inputs (default values in parentheses): 0011 % MPOPT : MATPOWER options struct 0012 % MODEL ('NLP') : (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 % 'NLP' - nonlinear program with all continuous variables 0016 % (MIPS, FMINCON, IPOPT, Artelys Knitro) 0017 % 'MINLP' - NLP with mixed integer/continuous variables 0018 % (Artelys Knitro) -- not yet implemented 0019 % ALG ('opf.ac') : (optional) 'opf.ac' or any valid value of 0020 % OPT.alg for NLPS_MASTER. The first option indicates that 0021 % it should be taken from MPOPT.opf.ac.solver. 0022 % 0023 % Output: 0024 % NLPOPT : an options struct for use by NLPS_MASTER and friends 0025 % 0026 % See NLPS_MASTER, MPOPTION. 0027 0028 % MP-Opt-Model 0029 % Copyright (c) 2015-2020, Power Systems Engineering Research Center (PSERC) 0030 % by Ray Zimmerman, PSERC Cornell 0031 % 0032 % This file is part of MP-Opt-Model. 0033 % Covered by the 3-clause BSD License (see LICENSE file for details). 0034 % See https://github.com/MATPOWER/mp-opt-model for more info. 0035 0036 %% set default args 0037 if nargin < 3 0038 alg = ''; 0039 if nargin < 2 0040 model = ''; 0041 end 0042 end 0043 if isempty(model) 0044 model = 'NLP'; 0045 else 0046 model = upper(model); 0047 end 0048 0049 %% get ALG from mpopt, if necessary 0050 switch alg 0051 case {'opf.ac', ''} 0052 alg = upper(mpopt.opf.ac.solver); 0053 otherwise 0054 alg = upper(alg); 0055 end 0056 0057 %% default solver 0058 if strcmp(alg, 'DEFAULT') 0059 alg = 'MIPS'; 0060 if model(1) == 'M' %% mixed integer 0061 if have_feature('knitromatlab') 0062 alg = 'KNITRO'; 0063 else 0064 error('mpopt2nlpopt: Sorry, no solver available for %s models', model); 0065 end 0066 end 0067 end 0068 0069 %% create NLPS_MASTER options struct 0070 nlpopt = struct('alg', alg, 'verbose', mpopt.verbose); 0071 switch alg 0072 case 'MIPS' 0073 %% set up options 0074 nlpopt.mips_opt = mpopt.mips; 0075 if nlpopt.mips_opt.feastol == 0 %% = MPOPT.opf.violation by default 0076 nlpopt.mips_opt.feastol = mpopt.opf.violation; 0077 end 0078 if ~isfield(nlpopt.mips_opt, 'cost_mult') || isempty(nlpopt.mips_opt.cost_mult) 0079 nlpopt.mips_opt.cost_mult = 1e-4; 0080 end 0081 case 'FMINCON' 0082 %% basic optimset options needed for fmincon 0083 nlpopt.fmincon_opt = mpopt.fmincon; 0084 nlpopt.fmincon_opt.opts.TolCon = mpopt.opf.violation; 0085 case 'IPOPT' 0086 nlpopt.ipopt_opt = ipopt_options([], mpopt); 0087 case 'KNITRO' 0088 nlpopt.knitro_opt = mpopt.knitro; 0089 nlpopt.knitro_opt.opts.feastol = mpopt.opf.violation; 0090 % nlpopt.knitro_opt.opts.TolCon = mpopt.opf.violation; 0091 end