Home > matpower7.1 > mp-opt-model > lib > mpopt2qpopt.m

mpopt2qpopt

PURPOSE ^

MPOPT2QPOPT Create/modify MI/QPS_MASTER options struct from MPOPT.

SYNOPSIS ^

function qpopt = mpopt2qpopt(mpopt, model, alg)

DESCRIPTION ^

MPOPT2QPOPT   Create/modify MI/QPS_MASTER options struct from MPOPT.

   QPOPT = MPOPT2QPOPT(MPOPT, MODEL)
   QPOPT = MPOPT2QPOPT(MPOPT, MODEL, ALG)

   Uses a MATPOWER options struct, MPOPT, to create or modify an
   MIQPS_MASTER or QPS_MASTER options struct.

   Inputs (default values in parentheses):
       MPOPT : MATPOWER options struct
       MODEL ('MIQP') : (optional) one of the following model types, required
               for selection of solver in case ALG is 'DEFAULT' (solver
               precedence for each model type list in parentheses):
           'LP'   - linear program with all continuous variables
                   (GUROBI, CPLEX, MOSEK, OT (if MATLAB), GLPK, BPMPD, MIPS)
           'QP'   - quadratic program with all continuous variables
                   (GUROBI, CPLEX, MOSEK, OT (if large-scale alg available),
                    BPMPD, MIPS)
           'MILP' - LP with mixed integer/continuous variables
                   (GUROBI, CPLEX, MOSEK, OT, GLPK)
           'MIQP' - (default) QP with mixed integer/continuous variables
                   (GUROBI, CPLEX, MOSEK)
       ALG ('opf.dc') : (optional) 'opf.dc', 'most', or any valid value of
               OPT.alg for QPS_MASTER or MIQPS_MASTER. The first two
               options indicate that it should be taken from
               MPOPT.opf.dc.solver or MPOPT.most.solver, respectively.

   Output:
       QPOPT : an options struct for use by QPS_MASTER or MIQPS_MASTER
               and friends

   See QPS_MASTER, MIQPS_MASTER, MPOPTION.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function qpopt = mpopt2qpopt(mpopt, model, alg)
0002 %MPOPT2QPOPT   Create/modify MI/QPS_MASTER options struct from MPOPT.
0003 %
0004 %   QPOPT = MPOPT2QPOPT(MPOPT, MODEL)
0005 %   QPOPT = MPOPT2QPOPT(MPOPT, MODEL, ALG)
0006 %
0007 %   Uses a MATPOWER options struct, MPOPT, to create or modify an
0008 %   MIQPS_MASTER or QPS_MASTER options struct.
0009 %
0010 %   Inputs (default values in parentheses):
0011 %       MPOPT : MATPOWER options struct
0012 %       MODEL ('MIQP') : (optional) one of the following model types, required
0013 %               for selection of solver in case ALG is 'DEFAULT' (solver
0014 %               precedence for each model type list in parentheses):
0015 %           'LP'   - linear program with all continuous variables
0016 %                   (GUROBI, CPLEX, MOSEK, OT (if MATLAB), GLPK, BPMPD, MIPS)
0017 %           'QP'   - quadratic program with all continuous variables
0018 %                   (GUROBI, CPLEX, MOSEK, OT (if large-scale alg available),
0019 %                    BPMPD, MIPS)
0020 %           'MILP' - LP with mixed integer/continuous variables
0021 %                   (GUROBI, CPLEX, MOSEK, OT, GLPK)
0022 %           'MIQP' - (default) QP with mixed integer/continuous variables
0023 %                   (GUROBI, CPLEX, MOSEK)
0024 %       ALG ('opf.dc') : (optional) 'opf.dc', 'most', or any valid value of
0025 %               OPT.alg for QPS_MASTER or MIQPS_MASTER. The first two
0026 %               options indicate that it should be taken from
0027 %               MPOPT.opf.dc.solver or MPOPT.most.solver, respectively.
0028 %
0029 %   Output:
0030 %       QPOPT : an options struct for use by QPS_MASTER or MIQPS_MASTER
0031 %               and friends
0032 %
0033 %   See QPS_MASTER, MIQPS_MASTER, MPOPTION.
0034 
0035 %   MP-Opt-Model
0036 %   Copyright (c) 2015-2020, Power Systems Engineering Research Center (PSERC)
0037 %   by Ray Zimmerman, PSERC Cornell
0038 %
0039 %   This file is part of MP-Opt-Model.
0040 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0041 %   See https://github.com/MATPOWER/mp-opt-model for more info.
0042 
0043 %% set default args
0044 if nargin < 3
0045     alg = '';
0046     if nargin < 2
0047         model = '';
0048     end
0049 end
0050 if isempty(model)
0051     model = 'MIQP';
0052 else
0053     model = upper(model);
0054 end
0055 skip_prices = 0;
0056 price_stage_warn_tol = [];
0057 
0058 %% get ALG from mpopt, if necessary
0059 switch alg
0060     case {'opf.dc', ''}
0061         alg = upper(mpopt.opf.dc.solver);
0062     case 'most'
0063         alg = upper(mpopt.most.solver);
0064         skip_prices             = mpopt.most.skip_prices;
0065         price_stage_warn_tol    = mpopt.most.price_stage_warn_tol;
0066     otherwise
0067         alg = upper(alg);
0068 end
0069 
0070 %% default solver
0071 switch alg
0072     case {'DEFAULT', 0}
0073         if have_feature('gurobi')
0074             alg = 'GUROBI';     %% use Gurobi by default, if available
0075         elseif have_feature('cplex')
0076             alg = 'CPLEX';      %% if not, then CPLEX, if available
0077         elseif have_feature('mosek')
0078             alg = 'MOSEK';      %% if not, then MOSEK, if available
0079         elseif have_feature('linprog_ds') && strcmp(model, 'LP') && have_feature('matlab') || ...
0080                 have_feature('quadprog_ls') && strcmp(model, 'QP') || ...
0081                 have_feature('intlinprog') && strcmp(model, 'MILP')
0082             alg = 'OT';         %% if not, then newer Optimization Tbx, if
0083                                 %% available and applicable
0084         elseif have_feature('glpk') && model(end-1) == 'L'  %% LP or MILP
0085             alg = 'GLPK';       %% if not, then GLPK, if available & applicable
0086         elseif have_feature('linprog') && strcmp(model, 'LP') && have_feature('matlab')
0087             alg = 'OT';         %% if not, then older Optimization Tbx, if
0088                                 %% available and applicable
0089         elseif model(1) ~= 'M'  %% LP or QP
0090             if have_feature('bpmpd')
0091                 alg = 'BPMPD';  %% if not, then BPMPD_MEX, if available
0092                                 %% and applicable
0093             else
0094                 alg = 'MIPS';   %% otherwise MIPS, if applicable
0095             end
0096         else
0097             error('mpopt2qpopt: Sorry, no solver available for %s models', model);
0098         end
0099 end
0100 
0101 %% create MI/QPS_MASTER options struct
0102 qpopt = struct('alg', alg, 'verbose', mpopt.verbose);
0103 switch alg
0104     case {'MIPS', 200, 250}
0105         %% set up options
0106         qpopt.mips_opt = mpopt.mips;
0107         if qpopt.mips_opt.feastol == 0      %% = MPOPT.opf.violation by default
0108             qpopt.mips_opt.feastol = mpopt.opf.violation;
0109         end
0110     case {'IPOPT', 400}
0111         qpopt.ipopt_opt = ipopt_options([], mpopt);
0112     case {'BPMPD', 100}
0113         bp_opt = bpopt;
0114         bp_opt(20) = 1e-9;  %% TOPT1
0115         qpopt.bp_opt = bp_opt;
0116     case 'CLP'
0117         qpopt.clp_opt = clp_options([], mpopt);
0118     case {'CPLEX', 500}
0119         qpopt.cplex_opt = cplex_options([], mpopt);
0120     case 'GLPK'
0121         qpopt.glpk_opt = glpk_options([], mpopt);
0122     case {'GUROBI', 700}
0123         qpopt.grb_opt = gurobi_options([], mpopt);
0124     case {'MOSEK', 600}
0125         qpopt.mosek_opt = mosek_options([], mpopt);
0126     case 'OSQP'
0127         qpopt.osqp_opt = osqp_options([], mpopt);
0128     case {'OT', 300}
0129         if isfield(mpopt, 'linprog') && ~isempty(mpopt.linprog)
0130             qpopt.linprog_opt = mpopt.linprog;
0131         end
0132         if isfield(mpopt, 'quadprog') && ~isempty(mpopt.quadprog)
0133             qpopt.quadprog_opt = mpopt.quadprog;
0134         end
0135         if isfield(mpopt, 'intlinprog') && ~isempty(mpopt.intlinprog)
0136             qpopt.intlinprog_opt = mpopt.intlinprog;
0137         end
0138 end
0139 if model(1) == 'M'
0140     qpopt.skip_prices           = skip_prices;
0141     qpopt.price_stage_warn_tol  = price_stage_warn_tol;
0142 end

Generated on Fri 09-Oct-2020 11:21:31 by m2html © 2005