Skip to content

Commit

Permalink
sol:chk:refcons to also check reformulated constraints #200
Browse files Browse the repository at this point in the history
Currently only checks solver-side constraints by default
  • Loading branch information
glebbelov committed Aug 28, 2023
1 parent 4a33064 commit 736d69b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
12 changes: 9 additions & 3 deletions include/mp/flat/constr_keeper.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,11 @@ struct SolCheck {
ArrayRef<double> obj,
ArrayRef<var::Type> vtype,
ArrayRef<double> lb, ArrayRef<double> 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(); }
Expand All @@ -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_; }
Expand Down Expand Up @@ -182,6 +186,7 @@ struct SolCheck {
ArrayRef<double> obj_;
double feastol_;
double inttol_;
bool reportBridgedCons_ = false;

std::string report_;

Expand Down Expand Up @@ -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)
Expand Down
15 changes: 10 additions & 5 deletions include/mp/flat/converter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 {}");
}
Expand Down Expand Up @@ -1041,6 +1043,7 @@ class FlatConverter :
int solcheckmode_ = 1;
double solfeastol_ = 1e-6;
double solinttol_ = 1e-5;
bool reprefcons_ = false;
};
Options options_;

Expand Down Expand Up @@ -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);
}


Expand Down

0 comments on commit 736d69b

Please sign in to comment.