Home > matpower7.0 > lib > mosek_options.m

mosek_options

PURPOSE ^

MOSEK_OPTIONS Sets options for MOSEK.

SYNOPSIS ^

function opt = mosek_options(overrides, mpopt)

DESCRIPTION ^

MOSEK_OPTIONS  Sets options for MOSEK.

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

   Sets the values for the param struct normally passed to MOSEKOPT.

   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.MSK_DPAR_INTPNT_TOL_PFEAS
           verbose         - not currently used here
           mosek.lp_alg    - used to set opt.MSK_IPAR_OPTIMIZER
           mosek.max_it    - used to set opt.MSK_IPAR_INTPNT_MAX_ITERATIONS
           mosek.gap_tol   - used to set opt.MSK_DPAR_INTPNT_TOL_REL_GAP
           mosek.max_time  - used to set opt.MSK_DPAR_OPTIMIZER_MAX_TIME
           mosek.num_threads - used to set opt.MSK_IPAR_INTPNT_NUM_THREADS
           mosek.opts      - struct containing values to use as OVERRIDES
           mosek.opt_fname - name of user-supplied function used as FNAME,
               except with calling syntax:
                   MODIFIED_OPT = FNAME(DEFAULT_OPT, MPOPT);
           mosek.opt       - numbered user option function, if and only if
               mosek.opt_fname is empty and mosek.opt is non-zero, the value
               of mosek.opt_fname is generated by appending mosek.opt to
               'mosek_user_options_' (for backward compatibility with old
               MATPOWER option MOSEK_OPT).

   Output is a param struct to pass to MOSEKOPT.

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

   Example:

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

       opt = mosek_user_options_3(opt, mpopt);

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

       function opt = mosek_user_options_3(opt, mpopt)
       opt.MSK_DPAR_INTPNT_TOL_DFEAS   = 1e-9;
       opt.MSK_IPAR_SIM_MAX_ITERATIONS = 5000000;

   See the Parameters reference in "The MOSEK optimization toolbox
   for MATLAB manaul" for details on the available options. You may also
   want to use the symbolic constants defined by MOSEK_SYMBCON.

       http://docs.mosek.com/7.1/toolbox/Parameters.html

   See also MOSEK_SYMBCON, MOSEKOPT, MPOPTION.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function opt = mosek_options(overrides, mpopt)
0002 %MOSEK_OPTIONS  Sets options for MOSEK.
0003 %
0004 %   OPT = MOSEK_OPTIONS
0005 %   OPT = MOSEK_OPTIONS(OVERRIDES)
0006 %   OPT = MOSEK_OPTIONS(OVERRIDES, FNAME)
0007 %   OPT = MOSEK_OPTIONS(OVERRIDES, MPOPT)
0008 %
0009 %   Sets the values for the param struct normally passed to MOSEKOPT.
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.MSK_DPAR_INTPNT_TOL_PFEAS
0020 %           verbose         - not currently used here
0021 %           mosek.lp_alg    - used to set opt.MSK_IPAR_OPTIMIZER
0022 %           mosek.max_it    - used to set opt.MSK_IPAR_INTPNT_MAX_ITERATIONS
0023 %           mosek.gap_tol   - used to set opt.MSK_DPAR_INTPNT_TOL_REL_GAP
0024 %           mosek.max_time  - used to set opt.MSK_DPAR_OPTIMIZER_MAX_TIME
0025 %           mosek.num_threads - used to set opt.MSK_IPAR_INTPNT_NUM_THREADS
0026 %           mosek.opts      - struct containing values to use as OVERRIDES
0027 %           mosek.opt_fname - name of user-supplied function used as FNAME,
0028 %               except with calling syntax:
0029 %                   MODIFIED_OPT = FNAME(DEFAULT_OPT, MPOPT);
0030 %           mosek.opt       - numbered user option function, if and only if
0031 %               mosek.opt_fname is empty and mosek.opt is non-zero, the value
0032 %               of mosek.opt_fname is generated by appending mosek.opt to
0033 %               'mosek_user_options_' (for backward compatibility with old
0034 %               MATPOWER option MOSEK_OPT).
0035 %
0036 %   Output is a param struct to pass to MOSEKOPT.
0037 %
0038 %   There are multiple ways of providing values to override the default
0039 %   options. Their precedence and order of application are as follows:
0040 %
0041 %   With inputs OVERRIDES and FNAME
0042 %       1. FNAME is called
0043 %       2. OVERRIDES are applied
0044 %   With inputs OVERRIDES and MPOPT
0045 %       1. FNAME (from mosek.opt_fname or mosek.opt) is called
0046 %       2. mosek.opts (if not empty) are applied
0047 %       3. OVERRIDES are applied
0048 %
0049 %   Example:
0050 %
0051 %   If mosek.opt = 3, then after setting the default MOSEK options,
0052 %   MOSEK_OPTIONS will execute the following user-defined function
0053 %   to allow option overrides:
0054 %
0055 %       opt = mosek_user_options_3(opt, mpopt);
0056 %
0057 %   The contents of mosek_user_options_3.m, could be something like:
0058 %
0059 %       function opt = mosek_user_options_3(opt, mpopt)
0060 %       opt.MSK_DPAR_INTPNT_TOL_DFEAS   = 1e-9;
0061 %       opt.MSK_IPAR_SIM_MAX_ITERATIONS = 5000000;
0062 %
0063 %   See the Parameters reference in "The MOSEK optimization toolbox
0064 %   for MATLAB manaul" for details on the available options. You may also
0065 %   want to use the symbolic constants defined by MOSEK_SYMBCON.
0066 %
0067 %       http://docs.mosek.com/7.1/toolbox/Parameters.html
0068 %
0069 %   See also MOSEK_SYMBCON, MOSEKOPT, MPOPTION.
0070 
0071 %   MATPOWER
0072 %   Copyright (c) 2010-2016, Power Systems Engineering Research Center (PSERC)
0073 %   by Ray Zimmerman, PSERC Cornell
0074 %
0075 %   This file is part of MATPOWER.
0076 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0077 %   See https://matpower.org for more info.
0078 
0079 %%-----  initialization and arg handling  -----
0080 %% defaults
0081 verbose = 2;
0082 gaptol  = 0;
0083 fname   = '';
0084 
0085 %% get symbolic constant names
0086 sc = mosek_symbcon;
0087 
0088 %% second argument
0089 if nargin > 1 && ~isempty(mpopt)
0090     if ischar(mpopt)        %% 2nd arg is FNAME (string)
0091         fname = mpopt;
0092         have_mpopt = 0;
0093     else                    %% 2nd arg is MPOPT (MATPOWER options struct)
0094         have_mpopt = 1;
0095         verbose = mpopt.verbose;
0096         if isfield(mpopt.mosek, 'opt_fname') && ~isempty(mpopt.mosek.opt_fname)
0097             fname = mpopt.mosek.opt_fname;
0098         elseif mpopt.mosek.opt
0099             fname = sprintf('mosek_user_options_%d', mpopt.mosek.opt);
0100         end
0101     end
0102 else
0103     have_mpopt = 0;
0104 end
0105 
0106 %%-----  set default options for MOSEK  -----
0107 %% solution algorithm
0108 if have_mpopt
0109     vnum = have_fcn('mosek', 'vnum');
0110     valid_alg = {                                   %% v6.x v7.x v8.x
0111             sc.MSK_OPTIMIZER_FREE,                  %%  0    0    2
0112             sc.MSK_OPTIMIZER_INTPNT,                %%  1    1    4
0113             sc.MSK_OPTIMIZER_PRIMAL_SIMPLEX,        %%  4    3    6
0114             sc.MSK_OPTIMIZER_DUAL_SIMPLEX,          %%  5    4    1
0115             sc.MSK_OPTIMIZER_FREE_SIMPLEX           %%  7    6    3
0116     };
0117     if vnum < 8
0118         valid_alg{end+1} = ...
0119             sc.MSK_OPTIMIZER_PRIMAL_DUAL_SIMPLEX;   %%  6    5    -
0120         valid_alg{end+1} = ...
0121             sc.MSK_OPTIMIZER_CONCURRENT;            %% 10   10    -
0122     end
0123     if vnum >= 7 && vnum < 8
0124         valid_alg{end+1} = ...
0125             sc.MSK_OPTIMIZER_NETWORK_PRIMAL_SIMPLEX;%%  -    7    -
0126     end
0127 
0128     alg = mpopt.mosek.lp_alg;
0129     switch alg
0130         case valid_alg
0131             opt.MSK_IPAR_OPTIMIZER = alg;
0132             opt.MSK_IPAR_MIO_ROOT_OPTIMIZER = alg;
0133             opt.MSK_IPAR_MIO_NODE_OPTIMIZER = alg;
0134         otherwise
0135             if alg == 0     %% MATPOWER still interprets this to be 'default'
0136                             %% even for MOSEK 8, since the conic optimizer is
0137                             %% not directly supported by mi/qps_matpower()
0138                 opt.MSK_IPAR_OPTIMIZER = sc.MSK_OPTIMIZER_FREE;
0139             else
0140                 error('mosek_options: %d is not a valid value for MSK_IPAR_OPTIMIZER', alg);
0141             end
0142     end
0143 
0144     %% (make default opf.violation correspond to default MSK_DPAR_INTPNT_TOL_PFEAS)
0145     opt.MSK_DPAR_INTPNT_TOL_PFEAS = mpopt.opf.violation/500;
0146     if mpopt.mosek.max_it
0147         opt.MSK_IPAR_INTPNT_MAX_ITERATIONS = mpopt.mosek.max_it;
0148     end
0149     if mpopt.mosek.gap_tol
0150         opt.MSK_DPAR_INTPNT_TOL_REL_GAP = mpopt.mosek.gap_tol;
0151     end
0152     if mpopt.mosek.max_time
0153         opt.MSK_DPAR_OPTIMIZER_MAX_TIME = mpopt.mosek.max_time;
0154     end
0155     if mpopt.mosek.num_threads
0156         if have_fcn('mosek', 'vnum') < 7
0157             opt.MSK_IPAR_INTPNT_NUM_THREADS = mpopt.mosek.num_threads;
0158         else
0159             opt.MSK_IPAR_NUM_THREADS = mpopt.mosek.num_threads;
0160         end
0161     end
0162 else
0163     opt.MSK_IPAR_OPTIMIZER = sc.MSK_OPTIMIZER_FREE;
0164 end
0165 % opt.MSK_DPAR_INTPNT_TOL_PFEAS = 1e-8;       %% primal feasibility tol
0166 % opt.MSK_DPAR_INTPNT_TOL_DFEAS = 1e-8;       %% dual feasibility tol
0167 % opt.MSK_DPAR_INTPNT_TOL_MU_RED = 1e-16;     %% relative complementarity gap tol
0168 % opt.MSK_DPAR_INTPNT_TOL_REL_GAP = 1e-8;     %% relative gap termination tol
0169 % opt.MSK_IPAR_INTPNT_MAX_ITERATIONS = 400;   %% max iterations for int point
0170 % opt.MSK_IPAR_SIM_MAX_ITERATIONS = 10000000; %% max iterations for simplex
0171 % opt.MSK_DPAR_OPTIMIZER_MAX_TIME = -1;       %% max time allowed (< 0 --> Inf)
0172 % opt.MSK_IPAR_INTPNT_NUM_THREADS = 1;        %% number of threads
0173 % opt.MSK_IPAR_PRESOLVE_USE = sc.MSK_PRESOLVE_MODE_OFF;
0174 
0175 % if verbose == 0
0176 %     opt.MSK_IPAR_LOG = 0;
0177 % end
0178 
0179 %%-----  call user function to modify defaults  -----
0180 if ~isempty(fname)
0181     if have_mpopt
0182         opt = feval(fname, opt, mpopt);
0183     else
0184         opt = feval(fname, opt);
0185     end
0186 end
0187 
0188 %%-----  apply overrides  -----
0189 if have_mpopt && isfield(mpopt.mosek, 'opts') && ~isempty(mpopt.mosek.opts)
0190     opt = nested_struct_copy(opt, mpopt.mosek.opts);
0191 end
0192 if nargin > 0 && ~isempty(overrides)
0193     opt = nested_struct_copy(opt, overrides);
0194 end

Generated on Mon 24-Jun-2019 15:58:45 by m2html © 2005