From 5252a55b6789661a1a688d353b66d5bf3de23e9c Mon Sep 17 00:00:00 2001 From: Gleb Belov Date: Mon, 28 Aug 2023 13:40:44 +1000 Subject: [PATCH] Violated constraints: short names #200 --- include/mp/flat/constr_keeper.h | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/include/mp/flat/constr_keeper.h b/include/mp/flat/constr_keeper.h index cf685389c..069a7e3c8 100644 --- a/include/mp/flat/constr_keeper.h +++ b/include/mp/flat/constr_keeper.h @@ -214,6 +214,11 @@ class BasicConstraintKeeper { virtual const char* GetAcceptanceOptionNames() const { return solver_opt_nm_; } + /// Constraint type short name. + /// Ideally should be in the constraint itself, + /// but currently we derive it from acceptance options. + virtual const char* GetShortTypeName() const; + /// See what options are available for this constraint: /// whether it is accepted natively by ModelAPI and/or can be /// converted by the Converter. @@ -294,9 +299,25 @@ class BasicConstraintKeeper { pre::ValueNode value_node_; const char* const constr_name_; const char* const solver_opt_nm_; + mutable std::string type_name_short_; int acceptance_level_ {-1}; }; +const char* +BasicConstraintKeeper::GetShortTypeName() const { + if (type_name_short_.empty()) { + std::string acc_opt = GetAcceptanceOptionNames(); + auto word_end = std::min(acc_opt.find(' '), + acc_opt.size()); + auto colon_pos = acc_opt.find(':'); + if (colon_pos>word_end) + colon_pos = 0; + type_name_short_ = acc_opt.substr( + colon_pos, word_end-colon_pos); + } + return type_name_short_.c_str(); +} + /// Full id of a constraint: CK + index /// This helper class is parameterized by the Keeper @@ -654,7 +675,7 @@ class ConstraintKeeper : public BasicConstraintKeeper { if (viol > chk.GetFeasTol()) { if (!conviolarray) conviolarray = - &conviolmap[cons_.front().con_.GetTypeName()]; + &conviolmap[GetShortTypeName()]; /// index==2 <==> solver-side constraint. /// TODO also original NL constraints (index 0) int index = cons_[i].IsBridged() ? 1 : 2;