Skip to content

Commit

Permalink
Algebralize pure-var lin & quad expr #237
Browse files Browse the repository at this point in the history
I.e., turn them into static constraints
  • Loading branch information
glebbelov committed Oct 7, 2024
1 parent 81cf482 commit 7db5f0c
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions include/mp/flat/constr_2_expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -660,6 +678,27 @@ class Constraints2Expr {
}
}

/// Special handling for algebraic functional constraints (LFC, QFC)
/// @return whether the \a con should be deleted
template <class AlgFuncCon>
bool ConsiderExplicifyingAlgebraic(const AlgFuncCon& con, int i) {
if (MPCD( IsProperVar(con.GetResultVar()) )) {
using TargetCon = AlgebraicConstraint<
std::decay_t<decltype(con.GetArguments().GetBody())>,
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
Expand Down

0 comments on commit 7db5f0c

Please sign in to comment.