GLPK_OPTIONS Sets options for GLPK. OPT = GLPK_OPTIONS OPT = GLPK_OPTIONS(OVERRIDES) OPT = GLPK_OPTIONS(OVERRIDES, FNAME) OPT = GLPK_OPTIONS(OVERRIDES, MPOPT) Sets the values for the options struct normally passed to GLPK. 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.msglev glpk.opts - struct containing values to use as OVERRIDES glpk.opt_fname - name of user-supplied function used as FNAME, except with calling syntax: MODIFIED_OPT = FNAME(DEFAULT_OPT, MPOPT); Output is an options struct to pass to GLPK. 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 glpk.opt_fname) is called 2. glpk.opts (if not empty) are applied 3. OVERRIDES are applied Example: If glpk.opt_fname = 'glpk_user_options_3', then after setting the default GLPK options, GLPK_OPTIONS will execute the following user-defined function to allow option overrides: opt = glpk_user_options_3(opt, mpopt); The contents of glpk_user_options_3.m, could be something like: function opt = glpk_user_options_3(opt, mpopt) opt.lpsolver = 1; opt.dual = 2; See the documentation for the PARAM argument at http://www.gnu.org/software/octave/doc/interpreter/Linear-Programming.html or by typing 'help glpk'. See also GLPK, MPOPTION.
0001 function opt = glpk_options(overrides, mpopt) 0002 %GLPK_OPTIONS Sets options for GLPK. 0003 % 0004 % OPT = GLPK_OPTIONS 0005 % OPT = GLPK_OPTIONS(OVERRIDES) 0006 % OPT = GLPK_OPTIONS(OVERRIDES, FNAME) 0007 % OPT = GLPK_OPTIONS(OVERRIDES, MPOPT) 0008 % 0009 % Sets the values for the options struct normally passed to GLPK. 0010 % 0011 % Inputs are all optional, second argument must be either a string 0012 % (FNAME) or a struct (MPOPT): 0013 % 0014 % OVERRIDES - struct containing values to override the defaults 0015 % FNAME - name of user-supplied function called after default 0016 % options are set to modify them. Calling syntax is: 0017 % MODIFIED_OPT = FNAME(DEFAULT_OPT); 0018 % MPOPT - MATPOWER options struct, uses the following fields: 0019 % verbose - used to set opt.msglev 0020 % glpk.opts - struct containing values to use as OVERRIDES 0021 % glpk.opt_fname - name of user-supplied function used as FNAME, 0022 % except with calling syntax: 0023 % MODIFIED_OPT = FNAME(DEFAULT_OPT, MPOPT); 0024 % 0025 % Output is an options struct to pass to GLPK. 0026 % 0027 % There are multiple ways of providing values to override the default 0028 % options. Their precedence and order of application are as follows: 0029 % 0030 % With inputs OVERRIDES and FNAME 0031 % 1. FNAME is called 0032 % 2. OVERRIDES are applied 0033 % With inputs OVERRIDES and MPOPT 0034 % 1. FNAME (from glpk.opt_fname) is called 0035 % 2. glpk.opts (if not empty) are applied 0036 % 3. OVERRIDES are applied 0037 % 0038 % Example: 0039 % 0040 % If glpk.opt_fname = 'glpk_user_options_3', then after setting the 0041 % default GLPK options, GLPK_OPTIONS will execute the following 0042 % user-defined function to allow option overrides: 0043 % 0044 % opt = glpk_user_options_3(opt, mpopt); 0045 % 0046 % The contents of glpk_user_options_3.m, could be something like: 0047 % 0048 % function opt = glpk_user_options_3(opt, mpopt) 0049 % opt.lpsolver = 1; 0050 % opt.dual = 2; 0051 % 0052 % See the documentation for the PARAM argument at 0053 % 0054 % http://www.gnu.org/software/octave/doc/interpreter/Linear-Programming.html 0055 % 0056 % or by typing 'help glpk'. 0057 % 0058 % 0059 % See also GLPK, MPOPTION. 0060 0061 % MATPOWER 0062 % Copyright (c) 2010-2016, Power Systems Engineering Research Center (PSERC) 0063 % by Ray Zimmerman, PSERC Cornell 0064 % 0065 % This file is part of MATPOWER. 0066 % Covered by the 3-clause BSD License (see LICENSE file for details). 0067 % See http://www.pserc.cornell.edu/matpower/ for more info. 0068 0069 %%----- initialization and arg handling ----- 0070 %% defaults 0071 verbose = 2; 0072 fname = ''; 0073 0074 %% second argument 0075 if nargin > 1 && ~isempty(mpopt) 0076 if ischar(mpopt) %% 2nd arg is FNAME (string) 0077 fname = mpopt; 0078 have_mpopt = 0; 0079 else %% 2nd arg is MPOPT (MATPOWER options struct) 0080 have_mpopt = 1; 0081 verbose = mpopt.verbose; 0082 if isfield(mpopt.glpk, 'opt_fname') && ~isempty(mpopt.glpk.opt_fname) 0083 fname = mpopt.glpk.opt_fname; 0084 end 0085 end 0086 else 0087 have_mpopt = 0; 0088 end 0089 0090 %%----- set default options for GLPK ----- 0091 %% printing 0092 opt.msglev = verbose; 0093 0094 %%----- call user function to modify defaults ----- 0095 if ~isempty(fname) 0096 if have_mpopt 0097 opt = feval(fname, opt, mpopt); 0098 else 0099 opt = feval(fname, opt); 0100 end 0101 end 0102 0103 %%----- apply overrides ----- 0104 if have_mpopt && isfield(mpopt.glpk, 'opts') && ~isempty(mpopt.glpk.opts) 0105 opt = nested_struct_copy(opt, mpopt.glpk.opts); 0106 end 0107 if nargin > 0 && ~isempty(overrides) 0108 opt = nested_struct_copy(opt, overrides); 0109 end