Skip to content

Commit

Permalink
Fix idealistic checks and reenable #200
Browse files Browse the repository at this point in the history
  • Loading branch information
glebbelov committed Aug 31, 2023
1 parent 990c11d commit af9396d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 22 deletions.
11 changes: 7 additions & 4 deletions include/mp/flat/constr_algebraic.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,16 @@ class AlgebraicConstraint :
/// For checking solver values,
/// report violation amount
/// (negative if holds with slack.)
/// In idealistic mode, report 1/0
/// In logical mode, report 1/0
/// (what's the violation amount of 0 for >0?)
template <class VarInfo>
double
ComputeViolation(const VarInfo& x) const {
auto bd = Body::ComputeValue(x);
if (!x.idealistic())
ComputeViolation(const VarInfo& x, bool logical=false) const {
double bd = Body::ComputeValue(x);
if (!logical) {
return std::max( // same for strict cmp?
RhsOrRange::lb() - bd, bd - RhsOrRange::ub());
}
return !RhsOrRange::is_valid(bd);
}

Expand Down Expand Up @@ -112,6 +113,8 @@ class AlgConRange {
static constexpr const char* GetTypeName() { return "Range"; }
/// Constructor
AlgConRange(double l, double u) : lb_(l), ub_(u) { }
/// kind placeholder
int kind() const { return -100; }
/// range lb()
double lb() const { return lb_; }
/// range ub()
Expand Down
2 changes: 1 addition & 1 deletion include/mp/flat/constr_eval.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ double ComputeValue(
template <class Con, class VarVec>
double ComputeValue(
const ConditionalConstraint<Con>& con, const VarVec& x) {
auto viol = con.GetConstraint().ComputeViolation(x);
auto viol = con.GetConstraint().ComputeViolation(x, true);
bool ccon_valid = viol<=0.0;
return ccon_valid;
}
Expand Down
12 changes: 5 additions & 7 deletions include/mp/flat/constr_keeper.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class VarInfoImpl {
const VarVec& get_x() const { return x_; }
/// Access raw variables
double raw(int i) const {
assert(i < x_raw_.size()
assert(i < (int)x_raw_.size()
&& "Can only access raw solver values "
"in idealistic mode and they should be available");
return x_raw_[i];
Expand Down Expand Up @@ -240,18 +240,18 @@ struct SolCheck {
/// Construct.
/// @param chkmode: can be subset of 1+2+4+8+16
SolCheck(ArrayRef<double> x,
const pre::ValueMapDbl& duals,
const pre::ValueMapDbl& , //duals,
ArrayRef<double> obj,
ArrayRef<double> x_raw,
ArrayRef<var::Type> vtype,
ArrayRef<double> lb, ArrayRef<double> ub,
double feastol, double inttol,
double feastol, double , //inttol,
const char* sol_rnd, const char* sol_prec,
bool recomp_vals, int chk_mode)
: x_(feastol, recomp_vals,
x, x_raw, vtype, lb, ub, sol_rnd, sol_prec),
y_(duals), obj_(obj),
feastol_(feastol), inttol_(inttol),
obj_(obj),
feastol_(feastol),
fRecomputedVals_(recomp_vals),
check_mode_(chk_mode) { }
/// Any violations?
Expand Down Expand Up @@ -311,10 +311,8 @@ struct SolCheck {

private:
VarInfoStatic x_;
const pre::ValueMapDbl& y_;
ArrayRef<double> obj_;
double feastol_;
double inttol_;
bool fRecomputedVals_;
int check_mode_;

Expand Down
4 changes: 2 additions & 2 deletions include/mp/flat/constr_prepro.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ class ConstraintPreprocessors {
prepro.narrow_result_bounds(0.0, 0.0);
return;
}
if (con.GetArguments().size() == n01.second) {
if ((int)con.GetArguments().size() == n01.second) {
prepro.narrow_result_bounds(1.0, 1.0);
return;
}
Expand All @@ -307,7 +307,7 @@ class ConstraintPreprocessors {
prepro.narrow_result_bounds(1.0, 1.0);
return;
}
if (con.GetArguments().size() == n01.first) {
if ((int)con.GetArguments().size() == n01.first) {
prepro.narrow_result_bounds(0.0, 0.0);
return;
}
Expand Down
17 changes: 9 additions & 8 deletions include/mp/flat/converter.h
Original file line number Diff line number Diff line change
Expand Up @@ -651,19 +651,20 @@ class FlatConverter :
= [this](int i, const VarInfoRecomp& x) {
if (MPCD( HasInitExpression(i) )) {
const auto& iexpr = MPCD( GetInitExpression(i) );
assert(iexpr.GetCK()
->GetResultVar(iexpr.GetIndex()) == i);
if (!iexpr.GetCK()->IsUnused(iexpr.GetIndex()))
return iexpr.GetCK()
->ComputeValue(iexpr.GetIndex(), x);
auto pCK = iexpr.GetCK();
auto resvar = pCK->GetResultVar(iexpr.GetIndex());
assert(resvar == i);
if (!pCK->IsUnused(iexpr.GetIndex()))
return pCK->ComputeValue(iexpr.GetIndex(), x);
}
return x.get_x().get_x()[i]; // no recomputation
};

/// Recompute auxiliary variables
ArrayRef<double> RecomputeAuxVars(ArrayRef<double> x) {
VarInfoRecomp vir {
options_.solfeastol_, false,
options_.solfeastol_,
true, // currently not relevant for recomputation
{x, recomp_fn},
{}, // now raw values
GetModel().var_type_vec(),
Expand Down Expand Up @@ -1146,7 +1147,7 @@ class FlatConverter :

int relax_ = 0;

int solcheckmode_ = 0; //1+2+16? +512?;
int solcheckmode_ = 1+2+16+512;
bool solcheckfail_ = false;
double solfeastol_ = 1e-6;
double solinttol_ = 1e-5;
Expand Down Expand Up @@ -1247,7 +1248,7 @@ class FlatConverter :
" applied by the solver when computing "
" expression values.\n"
"\n"
"Default: 0.",
"Default: 1+2+16+512.",
options_.solcheckmode_, 0, 1024);
GetEnv().AddOption("sol:chk:feastol sol:chk:eps sol:eps chk:eps",
"Solution checking tolerance for objective values, variable "
Expand Down

0 comments on commit af9396d

Please sign in to comment.