Home > matpower4.1 > gurobi_options.m

gurobi_options

PURPOSE ^

GUROBI_OPTIONS Sets options for GUROBI.

SYNOPSIS ^

function opt = gurobi_options(overrides, mpopt)

DESCRIPTION ^

GUROBI_OPTIONS  Sets options for GUROBI.

   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_MEX.

   Inputs are all optional, second argument must be either a string
   (FNAME) or a vector (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 vector, uses the following entries:
           OPF_VIOLATION (16)  - used to set opt.FeasibilityTol
           VERBOSE (31)        - used to set opt.DisplayInterval, opt.Display
           GRB_METHOD (121)    - used to set opt.Method
           GRB_TIMELIMIT (122) - used to set opt.TimeLimit (seconds)
           GRB_THREADS (123)   - used to set opt.Threads
           GRB_OPT (124)       - user option file, if MPOPT(124) is non-zero
               it is appended to 'gurobi_user_options_' to form the name of a
               user-supplied function used as FNAME described above, except
               with calling syntax:
                   MODIFIED_OPT = FNAME(DEFAULT_OPT, MPOPT);

   Output is an options struct to pass to GUROBI_MEX.

   Example:

   If MPOPT(124) = 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.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/doc/45/refman/

   See also GUROBI_MEX, 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.
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_MEX.
0010 %
0011 %   Inputs are all optional, second argument must be either a string
0012 %   (FNAME) or a vector (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 vector, uses the following entries:
0019 %           OPF_VIOLATION (16)  - used to set opt.FeasibilityTol
0020 %           VERBOSE (31)        - used to set opt.DisplayInterval, opt.Display
0021 %           GRB_METHOD (121)    - used to set opt.Method
0022 %           GRB_TIMELIMIT (122) - used to set opt.TimeLimit (seconds)
0023 %           GRB_THREADS (123)   - used to set opt.Threads
0024 %           GRB_OPT (124)       - user option file, if MPOPT(124) is non-zero
0025 %               it is appended to 'gurobi_user_options_' to form the name of a
0026 %               user-supplied function used as FNAME described above, except
0027 %               with calling syntax:
0028 %                   MODIFIED_OPT = FNAME(DEFAULT_OPT, MPOPT);
0029 %
0030 %   Output is an options struct to pass to GUROBI_MEX.
0031 %
0032 %   Example:
0033 %
0034 %   If MPOPT(124) = 3, then after setting the default GUROBI options,
0035 %   GUROBI_OPTIONS will execute the following user-defined function
0036 %   to allow option overrides:
0037 %
0038 %       opt = gurobi_user_options_3(opt, mpopt);
0039 %
0040 %   The contents of gurobi_user_options_3.m, could be something like:
0041 %
0042 %       function opt = gurobi_user_options_3(opt, mpopt)
0043 %       opt.OptimalityTol   = 1e-9;
0044 %       opt.IterationLimit  = 3000;
0045 %       opt.BarIterLimit    = 200;
0046 %       opt.Crossover       = 0;
0047 %       opt.Presolve        = 0;
0048 %
0049 %   For details on the available options, see the "Parameters" section
0050 %   of the "Gurobi Optimizer Reference Manual" at:
0051 %
0052 %       http://www.gurobi.com/doc/45/refman/
0053 %
0054 %   See also GUROBI_MEX, MPOPTION.
0055 
0056 %   MATPOWER
0057 %   $Id: gurobi_options.m,v 1.1 2011/07/05 20:34:58 cvs Exp $
0058 %   by Ray Zimmerman, PSERC Cornell
0059 %   Copyright (c) 2010-2011 by Power System Engineering Research Center (PSERC)
0060 %
0061 %   This file is part of MATPOWER.
0062 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0063 %
0064 %   MATPOWER is free software: you can redistribute it and/or modify
0065 %   it under the terms of the GNU General Public License as published
0066 %   by the Free Software Foundation, either version 3 of the License,
0067 %   or (at your option) any later version.
0068 %
0069 %   MATPOWER is distributed in the hope that it will be useful,
0070 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0071 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0072 %   GNU General Public License for more details.
0073 %
0074 %   You should have received a copy of the GNU General Public License
0075 %   along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.
0076 %
0077 %   Additional permission under GNU GPL version 3 section 7
0078 %
0079 %   If you modify MATPOWER, or any covered work, to interface with
0080 %   other modules (such as MATLAB code and MEX-files) available in a
0081 %   MATLAB(R) or comparable environment containing parts covered
0082 %   under other licensing terms, the licensors of MATPOWER grant
0083 %   you additional permission to convey the resulting work.
0084 
0085 %%-----  initialization and arg handling  -----
0086 %% defaults
0087 verbose = 1;
0088 fname   = '';
0089 
0090 %% second argument
0091 if nargin > 1 && ~isempty(mpopt)
0092     if ischar(mpopt)        %% 2nd arg is FNAME (string)
0093         fname = mpopt;
0094         have_mpopt = 0;
0095     else                    %% 2nd arg is MPOPT (MATPOWER options vector)
0096         have_mpopt = 1;
0097         verbose = mpopt(31);    %% VERBOSE
0098         if mpopt(124)           %% GRB_OPT
0099             fname = sprintf('gurobi_user_options_%d', mpopt(124));
0100         end
0101     end
0102 else
0103     have_mpopt = 0;
0104 end
0105 
0106 %%-----  set default options for CPLEX  -----
0107 % opt.OptimalityTol = 1e-6;
0108 % opt.Presolve = -1;              %% -1 - auto, 0 - no, 1 - conserv, 2 - aggressive=
0109 % opt.LogFile = 'qps_gurobi.log';
0110 if have_mpopt
0111     %% (make default OPF_VIOLATION correspond to default FeasibilityTol)
0112     opt.FeasibilityTol  = mpopt(16)/5;  %% OPF_VIOLATION
0113     opt.Method          = mpopt(121);   %% GRB_METHOD
0114     opt.TimeLimit       = mpopt(122);   %% GRB_TIMELIMIT
0115     opt.Threads         = mpopt(123);   %% GRB_THREADS
0116 else
0117     opt.Method          = 1;            %% dual simplex
0118 end
0119 opt.Display = min(verbose, 3);
0120 if verbose
0121     opt.DisplayInterval = 1;
0122 else
0123     opt.DisplayInterval = Inf;
0124 end
0125 
0126 %%-----  call user function to modify defaults  -----
0127 if ~isempty(fname)
0128     if have_mpopt
0129         opt = feval(fname, opt, mpopt);
0130     else
0131         opt = feval(fname, opt);
0132     end
0133 end
0134 
0135 %%-----  apply overrides  -----
0136 if nargin > 0 && ~isempty(overrides)
0137     names = fieldnames(overrides);
0138     for k = 1:length(names)
0139         opt.(names{k}) = overrides.(names{k});
0140     end
0141 end

Generated on Mon 26-Jan-2015 15:00:13 by m2html © 2005