From 7db5f0c44f72b216b595ad64165072cba04eaa76 Mon Sep 17 00:00:00 2001 From: Gleb Belov Date: Mon, 7 Oct 2024 19:30:05 +1100 Subject: [PATCH] Algebralize pure-var lin & quad expr #237 I.e., turn them into static constraints --- include/mp/flat/constr_2_expr.h | 39 +++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/include/mp/flat/constr_2_expr.h b/include/mp/flat/constr_2_expr.h index b6eb2da01..efcbc3124 100644 --- a/include/mp/flat/constr_2_expr.h +++ b/include/mp/flat/constr_2_expr.h @@ -149,6 +149,24 @@ class Constraints2Expr { return false; // leave it active } + /// Special handling for LinearFunctionalConstraint + bool ConvertWithExpressions( + const LinearFunctionalConstraint& con, int i, + ConstraintAcceptanceLevel , ExpressionAcceptanceLevel eal) { + if (2==stage_cvt2expr_) { + return ConsiderExplicifyingAlgebraic(con, i); + } + } + + /// Special handling for LinearFunctionalConstraint + bool ConvertWithExpressions( + const QuadraticFunctionalConstraint& con, int i, + ConstraintAcceptanceLevel , ExpressionAcceptanceLevel eal) { + if (2==stage_cvt2expr_) { + return ConsiderExplicifyingAlgebraic(con, i); + } + } + /// Convert complementarity constraint for use with expressions. /// Similarly to Conditional, we need the expression part to be an NL expression. /// @return true if this constraint has been eliminated/replaced. @@ -660,6 +678,27 @@ class Constraints2Expr { } } + /// Special handling for algebraic functional constraints (LFC, QFC) + /// @return whether the \a con should be deleted + template + bool ConsiderExplicifyingAlgebraic(const AlgFuncCon& con, int i) { + if (MPCD( IsProperVar(con.GetResultVar()) )) { + using TargetCon = AlgebraicConstraint< + std::decay_t, + AlgConRhs<0> >; // @todo can be ,=, >= + if (!MPCD( template ModelAPIOk< TargetCon >() ) + || HasExpressionArgs(con.GetArguments())) { + DoExplicify(con, i); // as other explicified expressions + return false; + } else { + auto& ck = GET_CONSTRAINT_KEEPER(AlgFuncCon); + const auto& ie = MPD( GetInitExpression(con.GetResultVar()) ); + ck.ConvertConstraint(ie.GetIndex()); + return true; + } + } + } + private: /// (Argument) variable visitor: mark var as proper