MPOPT2QPOPT Create/modify MI/QPS_MATPOWER 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_MATPOWER or QPS_MATPOWER 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_MATPOWER or MIQPS_MATPOWER. 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_MATPOWER or MIQPS_MATPOWER and friends
0001 function qpopt = mpopt2qpopt(mpopt, model, alg) 0002 %MPOPT2QPOPT Create/modify MI/QPS_MATPOWER 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_MATPOWER or QPS_MATPOWER 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_MATPOWER or MIQPS_MATPOWER. 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_MATPOWER or MIQPS_MATPOWER 0031 % and friends 0032 0033 % MATPOWER 0034 % Copyright (c) 2015-2016, Power Systems Engineering Research Center (PSERC) 0035 % by Ray Zimmerman, PSERC Cornell 0036 % 0037 % This file is part of MATPOWER. 0038 % Covered by the 3-clause BSD License (see LICENSE file for details). 0039 % See https://matpower.org for more info. 0040 0041 %% set default args 0042 if nargin < 3 0043 alg = ''; 0044 if nargin < 2 0045 model = ''; 0046 end 0047 end 0048 if isempty(model) 0049 model = 'MIQP'; 0050 else 0051 model = upper(model); 0052 end 0053 skip_prices = 0; 0054 price_stage_warn_tol = []; 0055 0056 %% get ALG from mpopt, if necessary 0057 switch alg 0058 case {'opf.dc', ''} 0059 alg = upper(mpopt.opf.dc.solver); 0060 case 'most' 0061 alg = upper(mpopt.most.solver); 0062 skip_prices = mpopt.most.skip_prices; 0063 price_stage_warn_tol = mpopt.most.price_stage_warn_tol; 0064 otherwise 0065 alg = upper(alg); 0066 end 0067 0068 %% default solver 0069 switch alg 0070 case {'DEFAULT', 0} 0071 if have_fcn('gurobi') 0072 alg = 'GUROBI'; %% use Gurobi by default, if available 0073 elseif have_fcn('cplex') 0074 alg = 'CPLEX'; %% if not, then CPLEX, if available 0075 elseif have_fcn('mosek') 0076 alg = 'MOSEK'; %% if not, then MOSEK, if available 0077 elseif have_fcn('linprog_ds') && strcmp(model, 'LP') && have_fcn('matlab') || ... 0078 have_fcn('quadprog_ls') && strcmp(model, 'QP') || ... 0079 have_fcn('intlinprog') && strcmp(model, 'MILP') 0080 alg = 'OT'; %% if not, then newer Optimization Tbx, if 0081 %% available and applicable 0082 elseif have_fcn('glpk') && model(end-1) == 'L' %% LP or MILP 0083 alg = 'GLPK'; %% if not, then GLPK, if available & applicable 0084 elseif have_fcn('linprog') && strcmp(model, 'LP') && have_fcn('matlab') 0085 alg = 'OT'; %% if not, then older Optimization Tbx, if 0086 %% available and applicable 0087 elseif model(1) ~= 'M' %% LP or QP 0088 if have_fcn('bpmpd') 0089 alg = 'BPMPD'; %% if not, then BPMPD_MEX, if available 0090 %% and applicable 0091 else 0092 alg = 'MIPS'; %% otherwise MIPS, if applicable 0093 end 0094 else 0095 error('mpopt2qpopt: Sorry, no solver available for %s models', model); 0096 end 0097 end 0098 0099 %% create MI/QPS_MATPOWER options struct 0100 qpopt = struct('alg', alg, 'verbose', mpopt.verbose); 0101 switch alg 0102 case {'MIPS', 200, 250} 0103 %% set up options 0104 qpopt.mips_opt = mpopt.mips; 0105 if qpopt.mips_opt.feastol == 0 %% = MPOPT.opf.violation by default 0106 qpopt.mips_opt.feastol = mpopt.opf.violation; 0107 end 0108 case {'IPOPT', 400} 0109 qpopt.ipopt_opt = ipopt_options([], mpopt); 0110 case {'BPMPD', 100} 0111 bp_opt = bpopt; 0112 bp_opt(20) = 1e-9; %% TOPT1 0113 qpopt.bp_opt = bp_opt; 0114 case 'CLP' 0115 qpopt.clp_opt = clp_options([], mpopt); 0116 case {'CPLEX', 500} 0117 qpopt.cplex_opt = cplex_options([], mpopt); 0118 case 'GLPK' 0119 qpopt.glpk_opt = glpk_options([], mpopt); 0120 case {'GUROBI', 700} 0121 qpopt.grb_opt = gurobi_options([], mpopt); 0122 case {'MOSEK', 600} 0123 qpopt.mosek_opt = mosek_options([], mpopt); 0124 case {'OT', 300} 0125 if isfield(mpopt, 'linprog') && ~isempty(mpopt.linprog) 0126 qpopt.linprog_opt = mpopt.linprog; 0127 end 0128 if isfield(mpopt, 'quadprog') && ~isempty(mpopt.quadprog) 0129 qpopt.quadprog_opt = mpopt.quadprog; 0130 end 0131 if isfield(mpopt, 'intlinprog') && ~isempty(mpopt.intlinprog) 0132 qpopt.intlinprog_opt = mpopt.intlinprog; 0133 end 0134 end 0135 if model(1) == 'M' 0136 qpopt.skip_prices = skip_prices; 0137 qpopt.price_stage_warn_tol = price_stage_warn_tol; 0138 end