Home > matpower5.0 > gurobi_options.m

gurobi_options

PURPOSE ^

GUROBI_OPTIONS Sets options for GUROBI (version 5.x and greater).

SYNOPSIS ^

function opt = gurobi_options(overrides, mpopt)

DESCRIPTION ^

GUROBI_OPTIONS  Sets options for GUROBI (version 5.x and greater).

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

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

   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:
           opf.violation    - used to set opt.FeasibilityTol
           verbose          - used to set opt.DisplayInterval,
                                 opt.OutputFlag, opt.LogToConsole
           gurobi.method    - used to set opt.Method
           gurobi.timelimit - used to set opt.TimeLimit (seconds)
           gurobi.threads   - used to set opt.Threads
           gurobi.opts      - struct containing values to use as OVERRIDES
           gurobi.opt_fname - name of user-supplied function used as FNAME,
               except with calling syntax:
                   MODIFIED_OPT = FNAME(DEFAULT_OPT, MPOPT);
           gurobi.opt       - numbered user option function, if and only if
               gurobi.opt_fname is empty and gurobi.opt is non-zero, the value
               of gurobi.opt_fname is generated by appending gurobi.opt to
               'gurobi_user_options_' (for backward compatibility with old
               MATPOWER option GRB_OPT).

   Output is a parameter struct to pass to GUROBI.

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

   Example:

   If gurobi.opt = 3, then after setting the default GUROBI options,
   GUROBI_OPTIONS will execute the following user-defined function
   to allow option overrides:

       opt = gurobi_user_options_3(opt, mpopt);

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

       function opt = gurobi_user_options_3(opt, mpopt)
       opt.OptimalityTol   = 1e-9;
       opt.BarConvTol      = 1e-9;
       opt.IterationLimit  = 3000;
       opt.BarIterLimit    = 200;
       opt.Crossover       = 0;
       opt.Presolve        = 0;

   For details on the available options, see the "Parameters" section
   of the "Gurobi Optimizer Reference Manual" at:

       http://www.gurobi.com/documentation/5.6/reference-manual/parameters

   See also GUROBI, MPOPTION.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function opt = gurobi_options(overrides, mpopt)
0002 %GUROBI_OPTIONS  Sets options for GUROBI (version 5.x and greater).
0003 %
0004 %   OPT = GUROBI_OPTIONS
0005 %   OPT = GUROBI_OPTIONS(OVERRIDES)
0006 %   OPT = GUROBI_OPTIONS(OVERRIDES, FNAME)
0007 %   OPT = GUROBI_OPTIONS(OVERRIDES, MPOPT)
0008 %
0009 %   Sets the values for the options struct normally passed to GUROBI.
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 %           opf.violation    - used to set opt.FeasibilityTol
0020 %           verbose          - used to set opt.DisplayInterval,
0021 %                                 opt.OutputFlag, opt.LogToConsole
0022 %           gurobi.method    - used to set opt.Method
0023 %           gurobi.timelimit - used to set opt.TimeLimit (seconds)
0024 %           gurobi.threads   - used to set opt.Threads
0025 %           gurobi.opts      - struct containing values to use as OVERRIDES
0026 %           gurobi.opt_fname - name of user-supplied function used as FNAME,
0027 %               except with calling syntax:
0028 %                   MODIFIED_OPT = FNAME(DEFAULT_OPT, MPOPT);
0029 %           gurobi.opt       - numbered user option function, if and only if
0030 %               gurobi.opt_fname is empty and gurobi.opt is non-zero, the value
0031 %               of gurobi.opt_fname is generated by appending gurobi.opt to
0032 %               'gurobi_user_options_' (for backward compatibility with old
0033 %               MATPOWER option GRB_OPT).
0034 %
0035 %   Output is a parameter struct to pass to GUROBI.
0036 %
0037 %   There are multiple ways of providing values to override the default
0038 %   options. Their precedence and order of application are as follows:
0039 %
0040 %   With inputs OVERRIDES and FNAME
0041 %       1. FNAME is called
0042 %       2. OVERRIDES are applied
0043 %   With inputs OVERRIDES and MPOPT
0044 %       1. FNAME (from gurobi.opt_fname or gurobi.opt) is called
0045 %       2. gurobi.opts (if not empty) are applied
0046 %       3. OVERRIDES are applied
0047 %
0048 %   Example:
0049 %
0050 %   If gurobi.opt = 3, then after setting the default GUROBI options,
0051 %   GUROBI_OPTIONS will execute the following user-defined function
0052 %   to allow option overrides:
0053 %
0054 %       opt = gurobi_user_options_3(opt, mpopt);
0055 %
0056 %   The contents of gurobi_user_options_3.m, could be something like:
0057 %
0058 %       function opt = gurobi_user_options_3(opt, mpopt)
0059 %       opt.OptimalityTol   = 1e-9;
0060 %       opt.BarConvTol      = 1e-9;
0061 %       opt.IterationLimit  = 3000;
0062 %       opt.BarIterLimit    = 200;
0063 %       opt.Crossover       = 0;
0064 %       opt.Presolve        = 0;
0065 %
0066 %   For details on the available options, see the "Parameters" section
0067 %   of the "Gurobi Optimizer Reference Manual" at:
0068 %
0069 %       http://www.gurobi.com/documentation/5.6/reference-manual/parameters
0070 %
0071 %   See also GUROBI, MPOPTION.
0072 
0073 %   MATPOWER
0074 %   $Id: gurobi_options.m 2242 2014-01-03 17:49:15Z ray $
0075 %   by Ray Zimmerman, PSERC Cornell
0076 %   Copyright (c) 2010-2013 by Power System Engineering Research Center (PSERC)
0077 %
0078 %   This file is part of MATPOWER.
0079 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0080 %
0081 %   MATPOWER is free software: you can redistribute it and/or modify
0082 %   it under the terms of the GNU General Public License as published
0083 %   by the Free Software Foundation, either version 3 of the License,
0084 %   or (at your option) any later version.
0085 %
0086 %   MATPOWER is distributed in the hope that it will be useful,
0087 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0088 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0089 %   GNU General Public License for more details.
0090 %
0091 %   You should have received a copy of the GNU General Public License
0092 %   along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.
0093 %
0094 %   Additional permission under GNU GPL version 3 section 7
0095 %
0096 %   If you modify MATPOWER, or any covered work, to interface with
0097 %   other modules (such as MATLAB code and MEX-files) available in a
0098 %   MATLAB(R) or comparable environment containing parts covered
0099 %   under other licensing terms, the licensors of MATPOWER grant
0100 %   you additional permission to convey the resulting work.
0101 
0102 %%-----  initialization and arg handling  -----
0103 %% defaults
0104 verbose = 1;
0105 fname   = '';
0106 
0107 %% second argument
0108 if nargin > 1 && ~isempty(mpopt)
0109     if ischar(mpopt)        %% 2nd arg is FNAME (string)
0110         fname = mpopt;
0111         have_mpopt = 0;
0112     else                    %% 2nd arg is MPOPT (MATPOWER options struct)
0113         have_mpopt = 1;
0114         verbose = mpopt.verbose;
0115         if isfield(mpopt.gurobi, 'opt_fname') && ~isempty(mpopt.gurobi.opt_fname)
0116             fname = mpopt.gurobi.opt_fname;
0117         elseif mpopt.gurobi.opt
0118             fname = sprintf('gurobi_user_options_%d', mpopt.gurobi.opt);
0119         end
0120     end
0121 else
0122     have_mpopt = 0;
0123 end
0124 
0125 %%-----  set default options for Gurobi  -----
0126 % opt.OptimalityTol = 1e-6;
0127 % opt.Presolve = -1;              %% -1 - auto, 0 - no, 1 - conserv, 2 - aggressive=
0128 % opt.LogFile = 'qps_gurobi.log';
0129 if have_mpopt
0130     %% (make default opf.violation correspond to default FeasibilityTol)
0131     opt.FeasibilityTol  = mpopt.opf.violation/5;
0132     opt.Method          = mpopt.gurobi.method;
0133     opt.TimeLimit       = mpopt.gurobi.timelimit;
0134     opt.Threads         = mpopt.gurobi.threads;
0135 else
0136     opt.Method          = -1;           %% automatic
0137 end
0138 if verbose > 1
0139     opt.LogToConsole = 1;
0140     opt.OutputFlag = 1;
0141     if verbose > 2
0142         opt.DisplayInterval = 1;
0143     else
0144         opt.DisplayInterval = 100;
0145     end
0146 else
0147     opt.LogToConsole = 0;
0148     opt.OutputFlag = 0;
0149 end
0150 
0151 %%-----  call user function to modify defaults  -----
0152 if ~isempty(fname)
0153     if have_mpopt
0154         opt = feval(fname, opt, mpopt);
0155     else
0156         opt = feval(fname, opt);
0157     end
0158 end
0159 
0160 %%-----  apply overrides  -----
0161 if have_mpopt && isfield(mpopt.gurobi, 'opts') && ~isempty(mpopt.gurobi.opts)
0162     opt = nested_struct_copy(opt, mpopt.gurobi.opts);
0163 end
0164 if nargin > 0 && ~isempty(overrides)
0165     opt = nested_struct_copy(opt, overrides);
0166 end

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