Home > matpower5.1 > 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

       http://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 %       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-2015 by Power System Engineering Research Center (PSERC)
0063 %   by Ray Zimmerman, PSERC Cornell
0064 %
0065 %   $Id: glpk_options.m 2644 2015-03-11 19:34:22Z ray $
0066 %
0067 %   This file is part of MATPOWER.
0068 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0069 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0070 
0071 %%-----  initialization and arg handling  -----
0072 %% defaults
0073 verbose = 2;
0074 fname   = '';
0075 
0076 %% second argument
0077 if nargin > 1 && ~isempty(mpopt)
0078     if ischar(mpopt)        %% 2nd arg is FNAME (string)
0079         fname = mpopt;
0080         have_mpopt = 0;
0081     else                    %% 2nd arg is MPOPT (MATPOWER options struct)
0082         have_mpopt = 1;
0083         verbose = mpopt.verbose;
0084         if isfield(mpopt.glpk, 'opt_fname') && ~isempty(mpopt.glpk.opt_fname)
0085             fname = mpopt.glpk.opt_fname;
0086         end
0087     end
0088 else
0089     have_mpopt = 0;
0090 end
0091 
0092 %%-----  set default options for GLPK  -----
0093 %% printing
0094 opt.msglev = verbose;
0095 
0096 %%-----  call user function to modify defaults  -----
0097 if ~isempty(fname)
0098     if have_mpopt
0099         opt = feval(fname, opt, mpopt);
0100     else
0101         opt = feval(fname, opt);
0102     end
0103 end
0104 
0105 %%-----  apply overrides  -----
0106 if have_mpopt && isfield(mpopt.glpk, 'opts') && ~isempty(mpopt.glpk.opts)
0107     opt = nested_struct_copy(opt, mpopt.glpk.opts);
0108 end
0109 if nargin > 0 && ~isempty(overrides)
0110     opt = nested_struct_copy(opt, overrides);
0111 end

Generated on Fri 20-Mar-2015 18:23:34 by m2html © 2005