YALMIP_OPTIONS Sets options for YALMIP. OPT = YALMIP_OPTIONS OPT = YALMIP_OPTIONS(OVERRIDES) OPT = YALMIP_OPTIONS(OVERRIDES, FNAME) OPT = YALMIP_OPTIONS(OVERRIDES, MPOPT) Sets the values for the YALMIP options struct (sdpsettings) normally passed to SOLVESDP. Inputs are all optional, second argument must be either a string (FNAME) or a struct (MPOPT): OVERRIDES - struct containing values to override the defaults FNAME - name of user-supplied function called after default options are set to modify them. Calling syntax is: MODIFIED_OPT = FNAME(DEFAULT_OPT); MPOPT - MATPOWER options struct, uses the following fields: verbose - used to set opt.verbose yalmip.opts - struct containing values to use as OVERRIDES yalmip.opt_fname - name of user-supplied function used as FNAME, except with calling syntax: MODIFIED_OPT = FNAME(DEFAULT_OPT, MPOPT); Output is an sdpsettings struct to pass to SOLVESDP. There are multiple ways of providing values to override the default options. Their precedence and order of application are as follows: With inputs OVERRIDES and FNAME 1. FNAME is called 2. OVERRIDES are applied With inputs OVERRIDES and MPOPT 1. FNAME (from yalmip.opt_fname) is called 2. yalmip.opts (if not empty) are applied 3. OVERRIDES are applied Example: If yalmip.opt_fname = 'yalmip_user_options_3', then after setting the default YALMIP options, YALMIP_OPTIONS will execute the following user-defined function to allow option overrides: opt = yalmip_user_options_3(opt, mpopt); The contents of yalmip_user_options_3.m, could be something like: function opt = yalmip_user_options_3(opt, mpopt) opt.solver = 'sedumi'; opt.sedumi.eps = 0; opt.sedumi.alg = 2; opt.sedumi.free = 1; opt.sedumi.stepdiff = 2; See the YALMIP documentation (help sdpsettings) and the solver (e.g., SeDuMi, SDPT3, etc.) documentation for details. See also SDPSETTINGS, MPOPTION.
0001 function opt = yalmip_options(overrides, mpopt) 0002 %YALMIP_OPTIONS Sets options for YALMIP. 0003 % 0004 % OPT = YALMIP_OPTIONS 0005 % OPT = YALMIP_OPTIONS(OVERRIDES) 0006 % OPT = YALMIP_OPTIONS(OVERRIDES, FNAME) 0007 % OPT = YALMIP_OPTIONS(OVERRIDES, MPOPT) 0008 % 0009 % Sets the values for the YALMIP options struct (sdpsettings) normally 0010 % passed to SOLVESDP. 0011 % 0012 % Inputs are all optional, second argument must be either a string 0013 % (FNAME) or a struct (MPOPT): 0014 % 0015 % OVERRIDES - struct containing values to override the defaults 0016 % FNAME - name of user-supplied function called after default 0017 % options are set to modify them. Calling syntax is: 0018 % MODIFIED_OPT = FNAME(DEFAULT_OPT); 0019 % MPOPT - MATPOWER options struct, uses the following fields: 0020 % verbose - used to set opt.verbose 0021 % yalmip.opts - struct containing values to use as OVERRIDES 0022 % yalmip.opt_fname - name of user-supplied function used as FNAME, 0023 % except with calling syntax: 0024 % MODIFIED_OPT = FNAME(DEFAULT_OPT, MPOPT); 0025 % 0026 % Output is an sdpsettings struct to pass to SOLVESDP. 0027 % 0028 % There are multiple ways of providing values to override the default 0029 % options. Their precedence and order of application are as follows: 0030 % 0031 % With inputs OVERRIDES and FNAME 0032 % 1. FNAME is called 0033 % 2. OVERRIDES are applied 0034 % With inputs OVERRIDES and MPOPT 0035 % 1. FNAME (from yalmip.opt_fname) is called 0036 % 2. yalmip.opts (if not empty) are applied 0037 % 3. OVERRIDES are applied 0038 % 0039 % Example: 0040 % 0041 % If yalmip.opt_fname = 'yalmip_user_options_3', then after setting the 0042 % default YALMIP options, YALMIP_OPTIONS will execute the following 0043 % user-defined function to allow option overrides: 0044 % 0045 % opt = yalmip_user_options_3(opt, mpopt); 0046 % 0047 % The contents of yalmip_user_options_3.m, could be something like: 0048 % 0049 % function opt = yalmip_user_options_3(opt, mpopt) 0050 % opt.solver = 'sedumi'; 0051 % opt.sedumi.eps = 0; 0052 % opt.sedumi.alg = 2; 0053 % opt.sedumi.free = 1; 0054 % opt.sedumi.stepdiff = 2; 0055 % 0056 % See the YALMIP documentation (help sdpsettings) and the solver (e.g., 0057 % SeDuMi, SDPT3, etc.) documentation for details. 0058 % 0059 % See also SDPSETTINGS, MPOPTION. 0060 0061 % MATPOWER 0062 % Copyright (c) 2013-2019, Power Systems Engineering Research Center (PSERC) 0063 % by Ray Zimmerman, PSERC Cornell 0064 % and Daniel Molzahn, PSERC U of Wisc, Madison 0065 % 0066 % This file is part of MATPOWER/mx-sdp_pf. 0067 % Covered by the 3-clause BSD License (see LICENSE file for details). 0068 % See https://github.com/MATPOWER/mx-sdp_pf/ for more info. 0069 0070 %%----- initialization and arg handling ----- 0071 %% defaults 0072 verbose = 1; 0073 fname = ''; 0074 0075 %% second argument 0076 if nargin > 1 && ~isempty(mpopt) 0077 if ischar(mpopt) %% 2nd arg is FNAME (string) 0078 fname = mpopt; 0079 have_mpopt = 0; 0080 else %% 2nd arg is MPOPT (MATPOWER options struct) 0081 have_mpopt = 1; 0082 verbose = mpopt.verbose; 0083 if isfield(mpopt.yalmip, 'opt_fname') && ~isempty(mpopt.yalmip.opt_fname) 0084 fname = mpopt.yalmip.opt_fname; 0085 end 0086 end 0087 else 0088 have_mpopt = 0; 0089 end 0090 0091 %% ----- set default options for YALMIP ----- 0092 if have_feature('matlab', 'vnum') >= 8.006 && have_feature('cplex') && ... 0093 have_feature('cplex', 'vnum') <= 12.006003 0094 s = warning('QUERY', 'MATLAB:lang:badlyScopedReturnValue'); 0095 warning('OFF', 'MATLAB:lang:badlyScopedReturnValue'); 0096 opt = sdpsettings; 0097 warning(s.state, 'MATLAB:lang:badlyScopedReturnValue'); 0098 else 0099 opt = sdpsettings; 0100 end 0101 0102 opt.verbose = verbose >= 1; 0103 0104 % Store defaults for SeDuMi and SDPT3. Use a default sdpsettings object for 0105 % any other solver. 0106 if have_feature('sedumi') 0107 opt = sdpsettings(opt, ... 0108 'solver','sedumi', ... 0109 'sedumi.eps',1e-8, ... 0110 'sedumi.alg',2, ... 0111 'sedumi.sdp',1, ... 0112 'sedumi.free',1, ... 0113 'sedumi.stepdif',2); 0114 elseif have_feature('sdpt3') 0115 opt = sdpsettings(opt, ... 0116 'solver','sdpt3', ... 0117 'sdpt3.gaptol',0, ... 0118 'sdpt3.maxit',100); 0119 end 0120 0121 %%----- call user function to modify defaults ----- 0122 if ~isempty(fname) 0123 if have_mpopt 0124 opt = feval(fname, opt, mpopt); 0125 else 0126 opt = feval(fname, opt); 0127 end 0128 end 0129 0130 %%----- apply overrides ----- 0131 if have_mpopt && isfield(mpopt.yalmip, 'opts') && ~isempty(mpopt.yalmip.opts) 0132 opt = nested_struct_copy(opt, mpopt.yalmip.opts); 0133 end 0134 if nargin > 0 && ~isempty(overrides) 0135 opt = nested_struct_copy(opt, overrides); 0136 end