Skip to content

Commit

Permalink
Expressions: for IfThen, algebralize only the then- and else-part #237
Browse files Browse the repository at this point in the history
  • Loading branch information
glebbelov committed Nov 1, 2024
1 parent 2532278 commit 1aaf5d1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
11 changes: 10 additions & 1 deletion include/mp/flat/constr_2_expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -387,14 +387,23 @@ class Constraints2Expr {
return false;
}

/// Handle logical expression in an algebraic con
/// Handle logical expressions in an algebraic con
/// @return whether to remove the original \a con.
template <class Con>
bool HandleLogicalArgs(const Con& con, int ) {
VisitArguments(con, MarkVarIfLogical_); // Mark as proper vars
return false; // don't remove immediately
}

/// Handle logical expressions in an IfThen
/// @return whether to remove the original \a con.
template <>
bool HandleLogicalArgs(const IfThenConstraint& con, int ) {
MarkVarIfLogical_(con.GetArguments()[1]); // then part
MarkVarIfLogical_(con.GetArguments()[2]); // else part
return false;
}

/// Special linear cases.
/// Not doing any more because these simplifications
/// interfere with result variable marking.
Expand Down
4 changes: 2 additions & 2 deletions include/mp/flat/constr_keeper.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ class ConstraintKeeper final
return false;
}

/// Mark whether we could result vars of functional constraints
/// as vars, vs using these constraints as expressions
/// Mark whether we could use result vars of functional constraints
/// as expressions
void MarkExprResultVars(BasicFlatConverter& cvt) override {
assert(&cvt == &GetConverter()); // Using the same Converter
DoMarkForResultVars();
Expand Down
4 changes: 3 additions & 1 deletion test/end2end/cases/categorized/fast/logical/modellist.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@
"name" : "ifthen_var cmp:eps=0 chk:fail",
"tags" : ["logical"],
"options": {
"ANYSOLVER_options": "cvt:cmp:eps=0 chk:fail"
"ANYSOLVER_options": "cvt:cmp:eps=0 chk:fail",
"mp2nl_options": "solver_options='cvt:cmp:eps=0 chk:fail'"

},
"values": {
"solve_result_num": 150
Expand Down

0 comments on commit 1aaf5d1

Please sign in to comment.