From 1aaf5d15c3ce1ba26bdcd9e6a6efe0c3c87a047a Mon Sep 17 00:00:00 2001 From: Gleb Belov Date: Fri, 1 Nov 2024 23:26:17 +1100 Subject: [PATCH] Expressions: for IfThen, algebralize only the then- and else-part #237 --- include/mp/flat/constr_2_expr.h | 11 ++++++++++- include/mp/flat/constr_keeper.h | 4 ++-- .../cases/categorized/fast/logical/modellist.json | 4 +++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/include/mp/flat/constr_2_expr.h b/include/mp/flat/constr_2_expr.h index 6aebc1478..87c2a441b 100644 --- a/include/mp/flat/constr_2_expr.h +++ b/include/mp/flat/constr_2_expr.h @@ -387,7 +387,7 @@ 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 bool HandleLogicalArgs(const Con& con, int ) { @@ -395,6 +395,15 @@ class Constraints2Expr { 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. diff --git a/include/mp/flat/constr_keeper.h b/include/mp/flat/constr_keeper.h index 19c4a96f3..1d7e5c112 100644 --- a/include/mp/flat/constr_keeper.h +++ b/include/mp/flat/constr_keeper.h @@ -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(); diff --git a/test/end2end/cases/categorized/fast/logical/modellist.json b/test/end2end/cases/categorized/fast/logical/modellist.json index 1599aa402..50ebc2ecf 100644 --- a/test/end2end/cases/categorized/fast/logical/modellist.json +++ b/test/end2end/cases/categorized/fast/logical/modellist.json @@ -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