Skip to content

Commit

Permalink
Functional constraint violation: context #200
Browse files Browse the repository at this point in the history
  • Loading branch information
glebbelov committed Aug 29, 2023
1 parent df04167 commit d554e0c
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion include/mp/flat/constr_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,17 @@ double ComputeViolation(
const CustomFunctionalConstraint<Args, Params, NumOrLogic, Id>& c,
const VarVec& x) {
auto resvar = c.GetResultVar();
return std::fabs(x[resvar] - ComputeValue(c, x));
auto viol = x[resvar] - ComputeValue(c, x);
switch (c.GetContext().GetValue()) {
case Context::CTX_MIX:
return std::fabs(viol);
case Context::CTX_POS:
return viol;
case Context::CTX_NEG:
return -viol;
default:
return INFINITY;
}
}


Expand Down

0 comments on commit d554e0c

Please sign in to comment.