Home > matpower5.0 > 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 %   $Id: yalmip_options.m 2272 2014-01-17 14:15:47Z ray $
0063 %   by Ray Zimmerman, PSERC Cornell
0064 %   and Daniel Molzahn, PSERC U of Wisc, Madison
0065 %   Copyright (c) 2013-2014 by Power System Engineering Research Center (PSERC)
0066 %
0067 %   This file is part of MATPOWER.
0068 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0069 %
0070 %   MATPOWER is free software: you can redistribute it and/or modify
0071 %   it under the terms of the GNU General Public License as published
0072 %   by the Free Software Foundation, either version 3 of the License,
0073 %   or (at your option) any later version.
0074 %
0075 %   MATPOWER is distributed in the hope that it will be useful,
0076 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0077 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0078 %   GNU General Public License for more details.
0079 %
0080 %   You should have received a copy of the GNU General Public License
0081 %   along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.
0082 %
0083 %   Additional permission under GNU GPL version 3 section 7
0084 %
0085 %   If you modify MATPOWER, or any covered work, to interface with
0086 %   other modules (such as MATLAB code and MEX-files) available in a
0087 %   MATLAB(R) or comparable environment containing parts covered
0088 %   under other licensing terms, the licensors of MATPOWER grant
0089 %   you additional permission to convey the resulting work.
0090 
0091 %%-----  initialization and arg handling  -----
0092 %% defaults
0093 verbose = 1;
0094 fname   = '';
0095 
0096 %% second argument
0097 if nargin > 1 && ~isempty(mpopt)
0098     if ischar(mpopt)        %% 2nd arg is FNAME (string)
0099         fname = mpopt;
0100         have_mpopt = 0;
0101     else                    %% 2nd arg is MPOPT (MATPOWER options struct)
0102         have_mpopt = 1;
0103         verbose = mpopt.verbose;
0104         if isfield(mpopt.yalmip, 'opt_fname') && ~isempty(mpopt.yalmip.opt_fname)
0105             fname = mpopt.yalmip.opt_fname;
0106         end
0107     end
0108 else
0109     have_mpopt = 0;
0110 end
0111 
0112 %% -----  set default options for YALMIP  -----
0113 opt = sdpsettings;
0114 opt.verbose = verbose >= 1;
0115 
0116 % Store defaults for SeDuMi and SDPT3. Use a default sdpsettings object for
0117 % any other solver.
0118 if have_fcn('sedumi')
0119     opt = sdpsettings(opt, ...
0120         'solver','sedumi', ...
0121         'sedumi.eps',1e-8, ...
0122         'sedumi.alg',2, ...
0123         'sedumi.sdp',1, ...
0124         'sedumi.free',1, ...
0125         'sedumi.stepdif',2);
0126 elseif have_fcn('sdpt3')
0127     opt = sdpsettings(opt, ...
0128         'solver','sdpt3', ...
0129         'sdpt3.gaptol',0, ...
0130         'sdpt3.maxit',100);
0131 end
0132 
0133 %%-----  call user function to modify defaults  -----
0134 if ~isempty(fname)
0135     if have_mpopt
0136         opt = feval(fname, opt, mpopt);
0137     else
0138         opt = feval(fname, opt);
0139     end
0140 end
0141 
0142 %%-----  apply overrides  -----
0143 if have_mpopt && isfield(mpopt.yalmip, 'opts') && ~isempty(mpopt.yalmip.opts)
0144     opt = nested_struct_copy(opt, mpopt.yalmip.opts);
0145 end
0146 if nargin > 0 && ~isempty(overrides)
0147     opt = nested_struct_copy(opt, overrides);
0148 end

Generated on Mon 26-Jan-2015 15:21:31 by m2html © 2005