diff --git a/include/mp/flat/redef/MIP/mul.h b/include/mp/flat/redef/MIP/mul.h index 6cad26131..9467346a5 100644 --- a/include/mp/flat/redef/MIP/mul.h +++ b/include/mp/flat/redef/MIP/mul.h @@ -30,6 +30,13 @@ class QCConverter_MIP : return !GetMC().IfPassQuadCon(); } + /// Skip conversion? + bool IfDelayConversion(const ItemType& , int ) { + return + GetMC().IfPassQuadCon() + || GetMC().IfWantNLOutput(); // Assume QuadExpr accepted + } + /// Conversion void Convert(const ItemType& qc, int ) { LinearizeQPTerms(qc); diff --git a/solvers/mp2nl/mp2nlmodelapi.cc b/solvers/mp2nl/mp2nlmodelapi.cc index 19e681a5b..218383e98 100644 --- a/solvers/mp2nl/mp2nlmodelapi.cc +++ b/solvers/mp2nl/mp2nlmodelapi.cc @@ -221,6 +221,9 @@ MP2NL_Expr MP2NLModelAPI::AddExpression(const SinExpression &expr) MP2NL_Expr MP2NLModelAPI::AddExpression(const CosExpression &expr) { return AddExpression(expr, ExpressionTypeID::ID_Cos); } +MP2NL_Expr MP2NLModelAPI::AddExpression(const DivExpression &expr) +{ return AddExpression(expr, ExpressionTypeID::ID_Div); } + void MP2NLModelAPI::FinishProblemModificationPhase() { } @@ -752,6 +755,8 @@ void MP2NLModelAPI::FeedOpcode(Expr expr, ExprWriter& ew) { HANDLE_OPCODE_CASE_1_ARG(Sin, SIN, FdArgs) HANDLE_OPCODE_CASE_1_ARG(Cos, COS, FdArgs) + HANDLE_OPCODE_CASE_2_ARG(Div, DIV, FdArgs) + default: MP_RAISE("MP2NL: unknown expression type"); } diff --git a/solvers/mp2nl/mp2nlmodelapi.h b/solvers/mp2nl/mp2nlmodelapi.h index 9d78f943a..6a505572b 100644 --- a/solvers/mp2nl/mp2nlmodelapi.h +++ b/solvers/mp2nl/mp2nlmodelapi.h @@ -94,8 +94,9 @@ class MP2NLModelAPI void AddVariables(const VarArrayDef& vad); void SetLinearObjective( int iobj, const LinearObjective& lo ); /// Whether accepting quadratic objectives: - /// 0 - no, 1 - convex, 2 - nonconvex - static int AcceptsQuadObj() { return 2; } + /// 0 - no, 1 - convex, 2 - nonconvex. + /// Return 0 because the QP terms go into expression + static int AcceptsQuadObj() { return 0; } void SetQuadraticObjective(int iobj, const QuadraticObjective& qo); /// Whether accepts NLObjective. static int AcceptsNLObj() { return 1; } @@ -414,6 +415,9 @@ class MP2NLModelAPI ACCEPT_EXPRESSION(CosExpression, Recommended) Expr AddExpression(const CosExpression& ); + ACCEPT_EXPRESSION(DivExpression, Recommended) + Expr AddExpression(const DivExpression& ); + // TODO Div; PowVarVar; @@ -1110,7 +1114,9 @@ class MP2NLModelAPI ID_Log, ID_Pow, ID_Sin, - ID_Cos + ID_Cos, + + ID_Div }; @@ -1287,6 +1293,7 @@ class MP2NLModelAPI CREATE_EXPRESSION_DISPATCHER(Sin) CREATE_EXPRESSION_DISPATCHER(Cos) + CREATE_EXPRESSION_DISPATCHER(Div) /// Constraint/objective/expression info. /// We rely on the pointers staying valid.