Home > matpower5.1 > extras > sdp_pf > yalmip_options.m

yalmip_options

PURPOSE ^

YALMIP_OPTIONS Sets options for YALMIP.

SYNOPSIS ^

function opt = yalmip_options(overrides, mpopt)

DESCRIPTION ^

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.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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-2015 by Power System Engineering Research Center (PSERC)
0063 %   by Ray Zimmerman, PSERC Cornell
0064 %   and Daniel Molzahn, PSERC U of Wisc, Madison
0065 %
0066 %   $Id: yalmip_options.m 2644 2015-03-11 19:34:22Z ray $
0067 %
0068 %   This file is part of MATPOWER.
0069 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0070 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0071 
0072 %%-----  initialization and arg handling  -----
0073 %% defaults
0074 verbose = 1;
0075 fname   = '';
0076 
0077 %% second argument
0078 if nargin > 1 && ~isempty(mpopt)
0079     if ischar(mpopt)        %% 2nd arg is FNAME (string)
0080         fname = mpopt;
0081         have_mpopt = 0;
0082     else                    %% 2nd arg is MPOPT (MATPOWER options struct)
0083         have_mpopt = 1;
0084         verbose = mpopt.verbose;
0085         if isfield(mpopt.yalmip, 'opt_fname') && ~isempty(mpopt.yalmip.opt_fname)
0086             fname = mpopt.yalmip.opt_fname;
0087         end
0088     end
0089 else
0090     have_mpopt = 0;
0091 end
0092 
0093 %% -----  set default options for YALMIP  -----
0094 opt = sdpsettings;
0095 opt.verbose = verbose >= 1;
0096 
0097 % Store defaults for SeDuMi and SDPT3. Use a default sdpsettings object for
0098 % any other solver.
0099 if have_fcn('sedumi')
0100     opt = sdpsettings(opt, ...
0101         'solver','sedumi', ...
0102         'sedumi.eps',1e-8, ...
0103         'sedumi.alg',2, ...
0104         'sedumi.sdp',1, ...
0105         'sedumi.free',1, ...
0106         'sedumi.stepdif',2);
0107 elseif have_fcn('sdpt3')
0108     opt = sdpsettings(opt, ...
0109         'solver','sdpt3', ...
0110         'sdpt3.gaptol',0, ...
0111         'sdpt3.maxit',100);
0112 end
0113 
0114 %%-----  call user function to modify defaults  -----
0115 if ~isempty(fname)
0116     if have_mpopt
0117         opt = feval(fname, opt, mpopt);
0118     else
0119         opt = feval(fname, opt);
0120     end
0121 end
0122 
0123 %%-----  apply overrides  -----
0124 if have_mpopt && isfield(mpopt.yalmip, 'opts') && ~isempty(mpopt.yalmip.opts)
0125     opt = nested_struct_copy(opt, mpopt.yalmip.opts);
0126 end
0127 if nargin > 0 && ~isempty(overrides)
0128     opt = nested_struct_copy(opt, overrides);
0129 end

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