Home > matpower7.1 > mp-opt-model > lib > glpk_options.m

glpk_options

PURPOSE ^

GLPK_OPTIONS Sets options for GLPK.

SYNOPSIS ^

function opt = glpk_options(overrides, mpopt)

DESCRIPTION ^

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

       https://www.gnu.org/software/octave/doc/interpreter/Linear-Programming.html

   or by typing 'help glpk'.

   See also GLPK, MPOPTION.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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 %       https://www.gnu.org/software/octave/doc/interpreter/Linear-Programming.html
0055 %
0056 %   or by typing 'help glpk'.
0057 %
0058 %   See also GLPK, MPOPTION.
0059 
0060 %   MP-Opt-Model
0061 %   Copyright (c) 2010-2020, Power Systems Engineering Research Center (PSERC)
0062 %   by Ray Zimmerman, PSERC Cornell
0063 %
0064 %   This file is part of MP-Opt-Model.
0065 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0066 %   See https://github.com/MATPOWER/mp-opt-model for more info.
0067 
0068 %%-----  initialization and arg handling  -----
0069 %% defaults
0070 verbose = 2;
0071 fname   = '';
0072 
0073 %% second argument
0074 if nargin > 1 && ~isempty(mpopt)
0075     if ischar(mpopt)        %% 2nd arg is FNAME (string)
0076         fname = mpopt;
0077         have_mpopt = 0;
0078     else                    %% 2nd arg is MPOPT (MATPOWER options struct)
0079         have_mpopt = 1;
0080         verbose = mpopt.verbose;
0081         if isfield(mpopt.glpk, 'opt_fname') && ~isempty(mpopt.glpk.opt_fname)
0082             fname = mpopt.glpk.opt_fname;
0083         end
0084     end
0085 else
0086     have_mpopt = 0;
0087 end
0088 
0089 %%-----  set default options for GLPK  -----
0090 %% printing
0091 opt.msglev = verbose;
0092 
0093 %%-----  call user function to modify defaults  -----
0094 if ~isempty(fname)
0095     if have_mpopt
0096         opt = feval(fname, opt, mpopt);
0097     else
0098         opt = feval(fname, opt);
0099     end
0100 end
0101 
0102 %%-----  apply overrides  -----
0103 if have_mpopt && isfield(mpopt.glpk, 'opts') && ~isempty(mpopt.glpk.opts)
0104     opt = nested_struct_copy(opt, mpopt.glpk.opts);
0105 end
0106 if nargin > 0 && ~isempty(overrides)
0107     opt = nested_struct_copy(opt, overrides);
0108 end

Generated on Fri 09-Oct-2020 11:21:31 by m2html © 2005