Home > matpower5.0 > have_fcn.m

have_fcn

PURPOSE ^

HAVE_FCN Test for optional functionality.

SYNOPSIS ^

function TorF = have_fcn(tag)

DESCRIPTION ^

HAVE_FCN  Test for optional functionality.
   TORF = HAVE_FCN(TAG) returns 1 if the optional functionality is
   available, 0 otherwise.

   Possible values for input TAG and their meanings:
       bpmpd       - BP, BPMPD interior point solver
       cplex       - CPLEX, IBM ILOG CPLEX Optimizer
       fmincon     - FMINCON, solver from Optimization Toolbox 2.x +
       fmincon_ipm - FMINCON with Interior Point solver, from Opt Tbx 4.x +
       glpk        - GLPK, GNU Linear Programming Kit
       gurobi      - GUROBI, Gurobi solver (http://www.gurobi.com/), 5.x +
       ipopt       - IPOPT, NLP solver (https://projects.coin-or.org/Ipopt/)
       linprog     - LINPROG, LP solver from Optimization Toolbox 2.x +
       linprog_ds  - LINPROG with dual-simplex solver
                       from Optimization Toolbox 7.1 (R2014b) +
       knitro      - KNITRO, NLP solver (http://www.ziena.com/)
         knitromatlab - KNITRO, version 9.0.0+
         ktrlink      - KNITRO, version < 9.0.0 (requires Opt Tbx)
       minopf      - MINOPF, MINOPF, MINOS-based OPF solver
       mosek       - MOSEK, LP/QP solver (http://www.mosek.com/)
       optimoptions - OPTIMOPTIONS, option setting funciton for Optim Tbx 6.3+
       quadprog    - QUADPROG, QP solver from Optimization Toolbox 2.x +
       quadprog_ls - QUADPROG with large-scale interior point convex solver
                       from Optimization Toolbox 6.x +
       pdipmopf    - PDIPMOPF, primal-dual interior point method OPF solver
       scpdipmopf  - SCPDIPMOPF, step-controlled PDIPM OPF solver
       smartmarket - RUNMARKET and friends, for running an auction
       tralmopf    - TRALMOPF, trust region based augmented Langrangian
                     OPF solver
       octave      - code is running under Octave, not MATLAB
       sdp_pf      - SDP_PF applications of semi-definite programming
                     relaxation of power flow equations
       yalmip      - YALMIP SDP modeling platform
       sedumi      - SeDuMi SDP solver
       sdpt3       - SDPT3 SDP solver

   Examples:
       if have_fcn('minopf')
           results = runopf(mpc, mpoption('opf.ac.solver', 'MINOPF'));
       end

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function TorF = have_fcn(tag)
0002 %HAVE_FCN  Test for optional functionality.
0003 %   TORF = HAVE_FCN(TAG) returns 1 if the optional functionality is
0004 %   available, 0 otherwise.
0005 %
0006 %   Possible values for input TAG and their meanings:
0007 %       bpmpd       - BP, BPMPD interior point solver
0008 %       cplex       - CPLEX, IBM ILOG CPLEX Optimizer
0009 %       fmincon     - FMINCON, solver from Optimization Toolbox 2.x +
0010 %       fmincon_ipm - FMINCON with Interior Point solver, from Opt Tbx 4.x +
0011 %       glpk        - GLPK, GNU Linear Programming Kit
0012 %       gurobi      - GUROBI, Gurobi solver (http://www.gurobi.com/), 5.x +
0013 %       ipopt       - IPOPT, NLP solver (https://projects.coin-or.org/Ipopt/)
0014 %       linprog     - LINPROG, LP solver from Optimization Toolbox 2.x +
0015 %       linprog_ds  - LINPROG with dual-simplex solver
0016 %                       from Optimization Toolbox 7.1 (R2014b) +
0017 %       knitro      - KNITRO, NLP solver (http://www.ziena.com/)
0018 %         knitromatlab - KNITRO, version 9.0.0+
0019 %         ktrlink      - KNITRO, version < 9.0.0 (requires Opt Tbx)
0020 %       minopf      - MINOPF, MINOPF, MINOS-based OPF solver
0021 %       mosek       - MOSEK, LP/QP solver (http://www.mosek.com/)
0022 %       optimoptions - OPTIMOPTIONS, option setting funciton for Optim Tbx 6.3+
0023 %       quadprog    - QUADPROG, QP solver from Optimization Toolbox 2.x +
0024 %       quadprog_ls - QUADPROG with large-scale interior point convex solver
0025 %                       from Optimization Toolbox 6.x +
0026 %       pdipmopf    - PDIPMOPF, primal-dual interior point method OPF solver
0027 %       scpdipmopf  - SCPDIPMOPF, step-controlled PDIPM OPF solver
0028 %       smartmarket - RUNMARKET and friends, for running an auction
0029 %       tralmopf    - TRALMOPF, trust region based augmented Langrangian
0030 %                     OPF solver
0031 %       octave      - code is running under Octave, not MATLAB
0032 %       sdp_pf      - SDP_PF applications of semi-definite programming
0033 %                     relaxation of power flow equations
0034 %       yalmip      - YALMIP SDP modeling platform
0035 %       sedumi      - SeDuMi SDP solver
0036 %       sdpt3       - SDPT3 SDP solver
0037 %
0038 %   Examples:
0039 %       if have_fcn('minopf')
0040 %           results = runopf(mpc, mpoption('opf.ac.solver', 'MINOPF'));
0041 %       end
0042 
0043 %   Private tags for internal use only:
0044 %       catchme         - support for 'catch me' syntax in try/catch constructs
0045 %       ipopt_auxdata   - support for ipopt_auxdata(), required by 3.11 and later
0046 %       regexp_split    - support for 'split' argument to regexp()
0047 
0048 %   MATPOWER
0049 %   $Id: have_fcn.m 2496 2014-12-17 19:56:00Z ray $
0050 %   by Ray Zimmerman, PSERC Cornell
0051 %   Copyright (c) 2004-2014 by Power System Engineering Research Center (PSERC)
0052 %
0053 %   This file is part of MATPOWER.
0054 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0055 %
0056 %   MATPOWER is free software: you can redistribute it and/or modify
0057 %   it under the terms of the GNU General Public License as published
0058 %   by the Free Software Foundation, either version 3 of the License,
0059 %   or (at your option) any later version.
0060 %
0061 %   MATPOWER is distributed in the hope that it will be useful,
0062 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0063 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0064 %   GNU General Public License for more details.
0065 %
0066 %   You should have received a copy of the GNU General Public License
0067 %   along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.
0068 %
0069 %   Additional permission under GNU GPL version 3 section 7
0070 %
0071 %   If you modify MATPOWER, or any covered work, to interface with
0072 %   other modules (such as MATLAB code and MEX-files) available in a
0073 %   MATLAB(R) or comparable environment containing parts covered
0074 %   under other licensing terms, the licensors of MATPOWER grant
0075 %   you additional permission to convey the resulting work.
0076 
0077 persistent fcns;
0078 
0079 if isfield(fcns, tag) && ~isempty(fcns.(tag))
0080     TorF = fcns.(tag);
0081 else
0082     switch tag
0083     %%-----  public tags  -----
0084         case 'bpmpd'
0085             TorF = exist('bp', 'file') == 3;
0086         case 'cplex'
0087             TorF = 0;
0088             if exist('cplexqp', 'file')
0089                 %% it's installed, but we need to check for MEX for this arch
0090                 p = which('cplexqp');   %% get the path
0091                 len = length(p) - length('cplexqp.p');
0092                 w = what(p(1:len));             %% look for mex files on the path
0093                 for k = 1:length(w.mex)
0094                     if regexp(w.mex{k}, 'cplexlink[^\.]*');
0095                         TorF = 1;
0096                         break;
0097                     end
0098                 end
0099             end
0100         case {'fmincon', 'fmincon_ipm', 'linprog', 'linprog_ds', ...
0101                     'optimoptions', 'quadprog', 'quadprog_ls'}
0102             if license('test', 'optimization_toolbox')
0103                 switch tag
0104                     case 'fmincon'
0105                         TorF = exist('fmincon', 'file') == 2 || ...
0106                             exist('fmincon', 'file') == 6;
0107                     case 'linprog'
0108                         TorF = exist('linprog', 'file') == 2;
0109                     case 'quadprog'
0110                         TorF = exist('quadprog', 'file') == 2;
0111                     otherwise
0112                         v = ver('optim');
0113                         otver = vstr2num(v.Version);
0114                         switch tag
0115                             case 'fmincon_ipm'
0116                                 if otver >= 4
0117                                     TorF = 1;
0118                                 else
0119                                     TorF = 0;
0120                                 end
0121                             case 'linprog_ds'
0122                                 if otver >= 7.001
0123                                     TorF = 1;
0124                                 else
0125                                     TorF = 0;
0126                                 end
0127                             case 'optimoptions'
0128                                 if otver >= 6.003
0129                                     TorF = 1;
0130                                 else
0131                                     TorF = 0;
0132                                 end
0133                             case 'quadprog_ls'
0134                                 if otver >= 6
0135                                     TorF = 1;
0136                                 else
0137                                     TorF = 0;
0138                                 end
0139                         end
0140                 end
0141             else
0142                 TorF = 0;
0143             end
0144         case 'glpk'
0145             TorF = exist('glpk','file') == 2 && ...
0146                 (exist('__glpk__','file') == 3 || exist('glpkcc','file') == 3);
0147         case 'gurobi'
0148             TorF = exist('gurobi', 'file') == 3;
0149         case 'ipopt'
0150             TorF = exist('ipopt', 'file') == 3;
0151         case 'knitro'       %% any Knitro
0152             TorF = have_fcn('knitromatlab') || have_fcn('ktrlink');
0153         case 'knitromatlab'     %% Knitro 9.0 or greater
0154             TorF = exist('knitromatlab', 'file') == 2;
0155             if TorF
0156                 try
0157                     str = evalc('[x fval] = knitromatlab(@(x)1,1);');
0158                 end
0159                 TorF = exist('fval', 'var') && fval == 1;
0160             end
0161         case 'ktrlink'      %% pre 9.0 Knitro interface, requires Opt Tbx
0162             TorF = exist('ktrlink', 'file') == 2;
0163             if TorF
0164                 try
0165                     str = evalc('[x fval] = ktrlink(@(x)1,1);');
0166                 end
0167                 TorF = exist('fval', 'var') && fval == 1;
0168             end
0169         case 'minopf'
0170             TorF = exist('minopf', 'file') == 3;
0171         case 'mosek'
0172             TorF = exist('mosekopt', 'file') == 3;
0173         case 'smartmarket'
0174             TorF = exist('runmarket', 'file') == 2;
0175         case 'octave'
0176             TorF = exist('OCTAVE_VERSION', 'builtin') == 5;
0177         case {'pdipmopf', 'scpdipmopf', 'tralmopf'}
0178             if have_fcn('octave')
0179                 TorF = 0;
0180             else
0181                 v = ver('Matlab');
0182                 %% requires >= MATLAB 6.5 (R13) (released 20-Jun-2002)
0183                 %% older versions do not have mxCreateDoubleScalar() function
0184                 %% (they have mxCreateScalarDouble() instead)
0185                 if vstr2num(v.Version) >= 6.005
0186                     switch tag
0187                         case 'pdipmopf'
0188                             TorF = exist('pdipmopf', 'file') == 3;
0189                         case 'scpdipmopf'
0190                             TorF = exist('scpdipmopf', 'file') == 3;
0191                         case 'tralmopf'
0192                             %% requires >= MATLAB 7.3 (R2006b) (released 03-Aug-2006)
0193                             %% older versions do not include the needed form of chol()
0194                             if vstr2num(v.Version) >= 7.003
0195                                 TorF = exist('tralmopf', 'file') == 3;
0196                             else
0197                                 TorF = 0;
0198                             end
0199                     end
0200                 else
0201                     TorF = 0;
0202                 end
0203             end
0204         case 'sdp_pf'
0205             TorF = have_fcn('yalmip') && exist('mpoption_info_sdp_pf', 'file') == 2;
0206         case 'yalmip'
0207             TorF = ~have_fcn('octave') && exist('yalmip','file') == 2;
0208             %% YALMIP does not yet work with Octave, rdz 1/6/14
0209         case 'sedumi'
0210             TorF = exist('sedumi','file') == 2;
0211         case 'sdpt3'
0212             TorF = exist('sdpt3','file') == 2;
0213 
0214     %%-----  private tags  -----
0215         case 'catchme'  %% not supported by Matlab <= 7.4 (R2007a), Octave <= 3.6
0216             if have_fcn('octave')
0217                 v = ver('Octave');
0218                 if vstr2num(v.Version) <= 3.006
0219                     TorF = 0;
0220                 else
0221                     TorF = 1;
0222                 end
0223             else
0224                 v = ver('Matlab');
0225                 if vstr2num(v.Version) <= 7.004
0226                     TorF = 0;
0227                 else
0228                     TorF = 1;
0229                 end
0230             end
0231         case 'ipopt_auxdata'
0232             if have_fcn('ipopt')
0233                 str = evalc('qps_ipopt([],1,1,1,1,1,1,1,struct(''verbose'', 2))');
0234                 pat = 'Ipopt version ([^\s,]+)';
0235                 [s,e,tE,m,t] = regexp(str, pat);
0236                 if isempty(t)
0237                     TorF = 0;       %% assume version is less than 3.11
0238                 else
0239                     vn = t{1}{1};
0240                     if vstr2num(vn) >= 3.011
0241                         TorF = 1;
0242                     else
0243                         TorF = 0;
0244                     end
0245                 end
0246             else
0247                 TorF = 0;
0248             end
0249         case 'regexp_split'
0250             TorF = 1;
0251             if have_fcn('octave')   %% only missing for Octave < 3.8
0252                 v = ver('Octave');
0253                 if vstr2num(v.Version) < 3.008
0254                     TorF = 0;
0255                 end
0256             end
0257 
0258     %%-----  unknown tag  -----
0259         otherwise
0260             error('have_fcn: unknown functionality %s', tag);
0261     end
0262     fcns.(tag) = TorF;
0263 end
0264 
0265 
0266 function num = vstr2num(vstr)
0267 % Converts version string to numerical value suitable for < or > comparisons
0268 % E.g. '3.11.4' -->  3.011004
0269 pat = '\.?(\d+)';
0270 [s,e,tE,m,t] = regexp(vstr, pat);
0271 b = 1;
0272 num = 0;
0273 for k = 1:length(t)
0274     num = num + b * str2num(t{k}{1});
0275     b = b / 1000;
0276 end

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