From 736d69be75bef8cc1cd106251fb7ec82850da3c4 Mon Sep 17 00:00:00 2001 From: Gleb Belov Date: Mon, 28 Aug 2023 22:32:05 +1000 Subject: [PATCH] sol:chk:refcons to also check reformulated constraints #200 Currently only checks solver-side constraints by default --- include/mp/flat/constr_keeper.h | 12 +++++++++--- include/mp/flat/converter.h | 15 ++++++++++----- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/include/mp/flat/constr_keeper.h b/include/mp/flat/constr_keeper.h index 8e36a40a8..3083f0363 100644 --- a/include/mp/flat/constr_keeper.h +++ b/include/mp/flat/constr_keeper.h @@ -125,9 +125,11 @@ struct SolCheck { ArrayRef obj, ArrayRef vtype, ArrayRef lb, ArrayRef ub, - double feastol, double inttol) + double feastol, double inttol, + bool reportBridged) : x_(feastol, x, vtype, lb, ub), y_(duals), obj_(obj), - feastol_(feastol), inttol_(inttol) { } + feastol_(feastol), inttol_(inttol), + reportBridgedCons_(reportBridged) { } /// Any violations? bool HasAnyViols() const { return HasAnyConViols() || HasAnyObjViols(); } @@ -153,6 +155,8 @@ struct SolCheck { double x(int i) const { return x_[i]; } /// Feasibility tolerance double GetFeasTol() const { return feastol_; } + /// Report reformulated constraints? + bool RepRefCons() const { return reportBridgedCons_; } /// Var bnd violations ViolSummArray<2>& VarViolBnds() { return viol_var_bnds_; } @@ -182,6 +186,7 @@ struct SolCheck { ArrayRef obj_; double feastol_; double inttol_; + bool reportBridgedCons_ = false; std::string report_; @@ -737,7 +742,8 @@ class ConstraintKeeper : public BasicConstraintKeeper { const auto& x = chk.x_ext(); ViolSummArray<3>* conviolarray {nullptr}; for (int i=(int)cons_.size(); i--; ) { - if (!cons_[i].IsUnused()) { + if (!cons_[i].IsUnused() + && (chk.RepRefCons() || !cons_[i].IsBridged())) { auto viol = cons_[i].con_.ComputeViolation(x); if (viol > chk.GetFeasTol()) { if (!conviolarray) diff --git a/include/mp/flat/converter.h b/include/mp/flat/converter.h index bd9001fa2..b88e14c0a 100644 --- a/include/mp/flat/converter.h +++ b/include/mp/flat/converter.h @@ -617,7 +617,9 @@ class FlatConverter : GetModel().var_type_vec(), GetModel().var_lb_vec(), GetModel().var_ub_vec(), - options_.solfeastol_, options_.solinttol_); + options_.solfeastol_, + options_.solinttol_, + options_.reprefcons_); CheckVars(chk); CheckCons(chk); CheckObjs(chk); @@ -726,7 +728,7 @@ class FlatConverter : + std::string(cva.first) + "' violate bounds,\n max by {}"); Gen1Viol(cva.second.at(2), wrt, - " - {} final constraint(s) of type '" + " - {} solver constraint(s) of type '" + std::string(cva.first) + "' violate bounds,\n max by {}"); } @@ -1041,6 +1043,7 @@ class FlatConverter : int solcheckmode_ = 1; double solfeastol_ = 1e-6; double solinttol_ = 1e-5; + bool reprefcons_ = false; }; Options options_; @@ -1127,13 +1130,15 @@ class FlatConverter : options_.solcheckmode_, values_solchk_); GetEnv().AddOption("sol:chk:feastol sol:chk:eps sol:eps chk:eps", "Solution checking tolerance for objective values, variable " - "and constraint bounds. Default 1e-6. " - "Violated logical constraints are always reported.", + "and constraint bounds. Default 1e-6.", options_.solfeastol_, 0.0, 1e100); GetEnv().AddOption("sol:chk:inttol sol:chk:inteps sol:inteps chk:inteps", "Solution checking tolerance for variables' integrality. " - "Default 1e-6. ", + "Default 1e-5.", options_.solinttol_, 0.0, 1e100); + GetEnv().AddOption("sol:chk:refcons chk:refcons", + "Report violations of reformulated constraints.", + options_.reprefcons_, false, true); }