Home > matpower6.0 > clp_options.m

clp_options

PURPOSE ^

CLP_OPTIONS Sets options for CLP.

SYNOPSIS ^

function opt = clp_options(overrides, mpopt)

DESCRIPTION ^

CLP_OPTIONS  Sets options for CLP.

   OPT = CLP_OPTIONS
   OPT = CLP_OPTIONS(OVERRIDES)
   OPT = CLP_OPTIONS(OVERRIDES, FNAME)
   OPT = CLP_OPTIONS(OVERRIDES, MPOPT)

   Sets the values for the options struct normally passed to CLP.

   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
           clp.opts       - struct containing values to use as OVERRIDES
           clp.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 CLP.

   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 clp.opt_fname) is called
       2. clp.opts (if not empty) are applied
       3. OVERRIDES are applied

   Example:

   If clp.opt_fname = 'clp_user_options_3', then after setting the
   default CLP options, CLP_OPTIONS will execute the following
   user-defined function to allow option overrides:

       opt = clp_user_options_3(opt, mpopt);

   The contents of clp_user_options_3.m, could be something like:

       function opt = clp_user_options_3(opt, mpopt)
       opt.algorithm   = 1;
       opt.numThreads  = 2;

   See the documentation for the CLP Options by typing 'help clp'.

   See also CLP, MPOPTION.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function opt = clp_options(overrides, mpopt)
0002 %CLP_OPTIONS  Sets options for CLP.
0003 %
0004 %   OPT = CLP_OPTIONS
0005 %   OPT = CLP_OPTIONS(OVERRIDES)
0006 %   OPT = CLP_OPTIONS(OVERRIDES, FNAME)
0007 %   OPT = CLP_OPTIONS(OVERRIDES, MPOPT)
0008 %
0009 %   Sets the values for the options struct normally passed to CLP.
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 %           clp.opts       - struct containing values to use as OVERRIDES
0021 %           clp.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 CLP.
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 clp.opt_fname) is called
0035 %       2. clp.opts (if not empty) are applied
0036 %       3. OVERRIDES are applied
0037 %
0038 %   Example:
0039 %
0040 %   If clp.opt_fname = 'clp_user_options_3', then after setting the
0041 %   default CLP options, CLP_OPTIONS will execute the following
0042 %   user-defined function to allow option overrides:
0043 %
0044 %       opt = clp_user_options_3(opt, mpopt);
0045 %
0046 %   The contents of clp_user_options_3.m, could be something like:
0047 %
0048 %       function opt = clp_user_options_3(opt, mpopt)
0049 %       opt.algorithm   = 1;
0050 %       opt.numThreads  = 2;
0051 %
0052 %   See the documentation for the CLP Options by typing 'help clp'.
0053 %
0054 %   See also CLP, MPOPTION.
0055 
0056 %   MATPOWER
0057 %   Copyright (c) 2010-2016, Power Systems Engineering Research Center (PSERC)
0058 %   by Ray Zimmerman, PSERC Cornell
0059 %
0060 %   This file is part of MATPOWER.
0061 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0062 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0063 
0064 %%-----  initialization and arg handling  -----
0065 %% defaults
0066 verbose = 2;
0067 fname   = '';
0068 
0069 %% second argument
0070 if nargin > 1 && ~isempty(mpopt)
0071     if ischar(mpopt)        %% 2nd arg is FNAME (string)
0072         fname = mpopt;
0073         have_mpopt = 0;
0074     else                    %% 2nd arg is MPOPT (MATPOWER options struct)
0075         have_mpopt = 1;
0076         verbose = mpopt.verbose;
0077         if isfield(mpopt.clp, 'opt_fname') && ~isempty(mpopt.clp.opt_fname)
0078             fname = mpopt.clp.opt_fname;
0079         end
0080     end
0081 else
0082     have_mpopt = 0;
0083 end
0084 
0085 %%-----  set default options for CLP  -----
0086 %% printing
0087 if have_fcn('opti_clp')
0088     opt.display = verbose;
0089 else
0090     opt.verbose = verbose;
0091 end
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.clp, 'opts') && ~isempty(mpopt.clp.opts)
0104     opt = nested_struct_copy(opt, mpopt.clp.opts);
0105 end
0106 if nargin > 0 && ~isempty(overrides)
0107     opt = nested_struct_copy(opt, overrides);
0108 end

Generated on Fri 16-Dec-2016 12:45:37 by m2html © 2005