PROBLEM_TYPE Return a string identifying the type of mathematical program PROB_TYPE = OM.PROBLEM_TYPE() PROB_TYPE = OM.PROBLEM_TYPE(RECHECK) Returns a string identifying the type of mathematical program represented by the current model, based on the variables, costs, and constraints that have been added to the model. Used to automatically select an appropriate solver. Linear and nonlinear equations are models with no costs, no inequality constraints, and an equal number of continuous variables and equality constraints. Outputs: PROB_TYPE : problem type, one of the following strings: 'LEQ' - linear equations 'NLEQ' - nonlinear equations 'LP' - linear program 'QP' - quadratic program 'NLP' - nonlinear program 'MILP' - mixed-integer linear program 'MIQP' - mixed-integer quadratic program 'MINLP' - mixed-integer nonlinear program The output value is cached for future calls, but calling with a true value for the optional RECHECK argument will force it to recheck in case the problem type has changed due to modifying the variables, constraints or costs in the model. See also OPT_MODEL
0001 function prob = problem_type(om, recheck) 0002 %PROBLEM_TYPE Return a string identifying the type of mathematical program 0003 % PROB_TYPE = OM.PROBLEM_TYPE() 0004 % PROB_TYPE = OM.PROBLEM_TYPE(RECHECK) 0005 % 0006 % Returns a string identifying the type of mathematical program 0007 % represented by the current model, based on the variables, costs, 0008 % and constraints that have been added to the model. Used to 0009 % automatically select an appropriate solver. 0010 % 0011 % Linear and nonlinear equations are models with no costs, no inequality 0012 % constraints, and an equal number of continuous variables and equality 0013 % constraints. 0014 % 0015 % Outputs: 0016 % PROB_TYPE : problem type, one of the following strings: 0017 % 'LEQ' - linear equations 0018 % 'NLEQ' - nonlinear equations 0019 % 'LP' - linear program 0020 % 'QP' - quadratic program 0021 % 'NLP' - nonlinear program 0022 % 'MILP' - mixed-integer linear program 0023 % 'MIQP' - mixed-integer quadratic program 0024 % 'MINLP' - mixed-integer nonlinear program 0025 % 0026 % The output value is cached for future calls, but calling with a true 0027 % value for the optional RECHECK argument will force it to recheck in 0028 % case the problem type has changed due to modifying the variables, 0029 % constraints or costs in the model. 0030 % 0031 % See also OPT_MODEL 0032 0033 % MP-Opt-Model 0034 % Copyright (c) 2020, Power Systems Engineering Research Center (PSERC) 0035 % by Ray Zimmerman, PSERC Cornell 0036 % 0037 % This file is part of MP-Opt-Model. 0038 % Covered by the 3-clause BSD License (see LICENSE file for details). 0039 % See https://github.com/MATPOWER/mp-opt-model for more info. 0040 0041 if isempty(om.prob_type) || nargin > 1 && recheck 0042 nleN = om.getN('nle'); %% nonlinear equalities 0043 nliN = om.getN('nli'); %% nonlinear inequalities 0044 nlcN = om.getN('nlc'); %% general nonlinear costs 0045 qdcN = om.getN('qdc'); %% quadratic costs 0046 linN = om.getN('lin'); %% linear constraints 0047 varN = om.getN('var'); %% variables 0048 if nlcN || qdcN %% problem has costs 0049 if nliN || nleN || nlcN %% nonlinear 0050 prob = 'NLP'; %% nonlinear program 0051 else %% linear constraints, no general nonlinear costs 0052 %% get quadratic cost coefficients 0053 H = om.params_quad_cost(); 0054 if isempty(H) || ~any(any(H)) 0055 prob = 'LP'; %% linear program 0056 else 0057 prob = 'QP'; %% quadratic program 0058 end 0059 end 0060 else %% problem has no costs 0061 if nliN 0062 error('@opt_model/problem_type: invalid problem - nonlinear inequality constraints with no costs'); 0063 end 0064 if nleN + linN == varN %% square system 0065 if linN > 0 0066 %% get lower & upper bounds 0067 [A, l, u] = om.params_lin_constraint(); 0068 if any(l ~= u) 0069 error('@opt_model/problem_type: invalid problem - linear inequality constraints with no costs'); 0070 end 0071 end 0072 if nleN 0073 prob = 'NLEQ'; %% square nonlinear set of equations 0074 else 0075 prob = 'LEQ'; %% square linear set of equations 0076 end 0077 else 0078 error('@opt_model/problem_type: invalid problem - non-square system with no costs'); 0079 end 0080 end 0081 if om.is_mixed_integer() && ~strcmp(prob, 'NLEQ') 0082 prob = ['MI' prob]; 0083 end 0084 om.prob_type = prob; %% cache it 0085 else 0086 prob = om.prob_type; %% return cached type 0087 end