From 76d8b3e608662421fe1a5f069259b7209ffdd58e Mon Sep 17 00:00:00 2001 From: Gleb Belov Date: Wed, 21 Aug 2024 12:15:16 +1000 Subject: [PATCH] Fix expr/flatcon acceptance #237 Restore SCIP::Cos() as 'not recommended' - seems slow Fix Checker_AMPLS_ModeltTraits() signature --- include/mp/ampls-ccallbacks.h | 2 +- include/mp/flat/constr_keeper.h | 36 +++++++++++++++++++++------------ include/mp/flat/item_keeper.h | 2 -- solvers/scipmp/scipmpmodelapi.h | 4 ++-- 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/include/mp/ampls-ccallbacks.h b/include/mp/ampls-ccallbacks.h index c60d26ceb..85aa41e1b 100644 --- a/include/mp/ampls-ccallbacks.h +++ b/include/mp/ampls-ccallbacks.h @@ -17,7 +17,7 @@ typedef struct AMPLS_ModelTraits_T { } AMPLS_ModelTraits; -typedef void (*Checker_AMPLS_ModeltTraits)(AMPLS_ModelTraits*); +typedef void (*Checker_AMPLS_ModeltTraits)(const AMPLS_ModelTraits*); /// Set of callbacks provided to a driver for licensing issues diff --git a/include/mp/flat/constr_keeper.h b/include/mp/flat/constr_keeper.h index 82866ddb9..cf063bce9 100644 --- a/include/mp/flat/constr_keeper.h +++ b/include/mp/flat/constr_keeper.h @@ -154,17 +154,21 @@ class ConstraintKeeper final /// Acceptance level of this constraint type in the ModelAPI ConstraintAcceptanceLevel GetModelAPIAcceptance( - const BasicFlatModelAPI& ba) const override { + const BasicFlatModelAPI& = *(BasicFlatModelAPI*)nullptr) + const override { return - static_cast( ba ). + // static_cast( ba ). + Backend:: AcceptanceLevel((Constraint*)nullptr); } /// Acceptance level of the corresponding expression type in the ModelAPI ExpressionAcceptanceLevel GetModelAPIAcceptanceEXPR( - const BasicFlatModelAPI& ba) const override { + const BasicFlatModelAPI& = *(BasicFlatModelAPI*)nullptr) + const override { return - static_cast( ba ). + // static_cast( ba ). + Backend:: AcceptanceLevel((FlatExprType*)nullptr); } @@ -202,14 +206,15 @@ class ConstraintKeeper final const std::vector* pvnam) override { if (ExpressionAcceptanceLevel::NotAccepted == GetChosenAcceptanceLevelEXPR() - || !GetConverter().IfWantNLOutput()) - try { - AddAllUnbridged(be, pvnam); - } catch (const std::exception& exc) { - MP_RAISE(std::string("Adding constraint of type '") + - Constraint::GetTypeName() + "' to " + - Backend::GetTypeName() + std::string(": ") + - exc.what()); + || !GetConverter().IfWantNLOutput()) { + try { + AddAllUnbridged(be, pvnam); + } catch (const std::exception& exc) { + MP_RAISE(std::string("Adding constraint of type '") + + Constraint::GetTypeName() + "' to " + + Backend::GetTypeName() + std::string(": ") + + exc.what()); + } } } @@ -301,7 +306,12 @@ class ConstraintKeeper final int i=i_last; const auto acceptanceLevel = GetChosenAcceptanceLevel(); - if (ConstraintAcceptanceLevel::NotAccepted == acceptanceLevel) { + if (ConstraintAcceptanceLevel::NotAccepted == acceptanceLevel + || (ConstraintAcceptanceLevel::NotAccepted == GetModelAPIAcceptance() + && (!GetConverter().IfWantNLOutput() + || ExpressionAcceptanceLevel::NotAccepted + == GetChosenAcceptanceLevelEXPR()) + && 2 != AccLevelCommon())) { // Not when acc:_all=2 if (!IfConverterConverts(GetConverter())) { i = (int)cons_.size(); } else { diff --git a/include/mp/flat/item_keeper.h b/include/mp/flat/item_keeper.h index cbf9ae243..03e3fb940 100644 --- a/include/mp/flat/item_keeper.h +++ b/include/mp/flat/item_keeper.h @@ -73,8 +73,6 @@ class BasicConstraintKeeper { al = acc_level_item_; std::array alv = {0, 1, 2, 1, 2}; acceptance_level_ = alv.at(al); - if (al>2 && !IfWantNLOutput()) // expression accepted but NL format not chosen - acceptance_level_ = 0; } return ConstraintAcceptanceLevel(acceptance_level_); } diff --git a/solvers/scipmp/scipmpmodelapi.h b/solvers/scipmp/scipmpmodelapi.h index 17ee74e1b..98b2feaca 100644 --- a/solvers/scipmp/scipmpmodelapi.h +++ b/solvers/scipmp/scipmpmodelapi.h @@ -263,9 +263,9 @@ class ScipModelAPI : ACCEPT_CONSTRAINT(SinConstraint, Recommended, CG_General) void AddConstraint(const SinConstraint& cc); - ACCEPT_EXPRESSION(CosExpression, Recommended) + ACCEPT_EXPRESSION(CosExpression, AcceptedButNotRecommended) //pretty slow in SCIP 8/9 SCIP_EXPR* AddExpression(const CosExpression& ); - ACCEPT_CONSTRAINT(CosConstraint, Recommended, CG_General) //pretty slow in SCIP 8 + ACCEPT_CONSTRAINT(CosConstraint, AcceptedButNotRecommended, CG_General) void AddConstraint(const CosConstraint& cc); // TODO Div; PowVarExponent;