Skip to content

Commit 27b8c83

Browse files
authored
fix: Sign error in greater_than constraint (#334)
`greater_than(terms, rhs)` is implemented as `greater_than_or_equals(terms, rhs - 1)`, but should be `greater_than_or_equals(terms, rhs + 1)`. This is likely a copy-paste error from the implementation of `less_than`.
1 parent babbdd9 commit 27b8c83

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

pumpkin-crates/core/src/constraints/arithmetic/inequality.rs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub fn greater_than<Var: IntegerVariable + 'static>(
4040
rhs: i32,
4141
constraint_tag: ConstraintTag,
4242
) -> impl NegatableConstraint {
43-
greater_than_or_equals(terms, rhs - 1, constraint_tag)
43+
greater_than_or_equals(terms, rhs + 1, constraint_tag)
4444
}
4545

4646
/// Create the [`NegatableConstraint`] `\sum terms_i >= rhs`.
@@ -140,3 +140,38 @@ impl<Var: IntegerVariable + 'static> NegatableConstraint for Inequality<Var> {
140140
}
141141
}
142142
}
143+
144+
#[cfg(test)]
145+
mod tests {
146+
use super::*;
147+
148+
#[test]
149+
fn less_than_conflict() {
150+
let mut solver = Solver::default();
151+
152+
let constraint_tag = solver.new_constraint_tag();
153+
let x = solver.new_named_bounded_integer(0, 0, "x");
154+
155+
let result = less_than([x], 0, constraint_tag).post(&mut solver);
156+
assert_eq!(
157+
result,
158+
Err(ConstraintOperationError::InfeasiblePropagator),
159+
"Expected {result:?} to be an `InfeasiblePropagator` error"
160+
);
161+
}
162+
163+
#[test]
164+
fn greater_than_conflict() {
165+
let mut solver = Solver::default();
166+
167+
let constraint_tag = solver.new_constraint_tag();
168+
let x = solver.new_named_bounded_integer(0, 0, "x");
169+
170+
let result = greater_than([x], 0, constraint_tag).post(&mut solver);
171+
assert_eq!(
172+
result,
173+
Err(ConstraintOperationError::InfeasiblePropagator),
174+
"Expected {result:?} to be an `InfeasiblePropagator` error"
175+
);
176+
}
177+
}

0 commit comments

Comments
 (0)