-
Notifications
You must be signed in to change notification settings - Fork 2
Panic when handling large domain values #1
Copy link
Copy link
Open
Description
Rust panics with error:
attempt to subtract with overflow
thread 'solvers::linear_integer_binary::a' panicked at C:\Users\specy\.cargo\registry\src\index.crates.io-6f17d22bba15001f\copper-0.1.0\src\props\sum.rs:33:35:
attempt to subtract with overflow
here:
impl<V: View> Prune for Sum<V> {
fn prune(&mut self, ctx: &mut Context) -> Option<()> {
// Derive minimum and maximum values the sum of terms can reach
let min_of_terms: i32 = self.xs.iter().map(|x| x.min(ctx)).sum();
let max_of_terms: i32 = self.xs.iter().map(|x| x.max(ctx)).sum();
let _ = self.s.try_set_min(min_of_terms, ctx)?;
let _ = self.s.try_set_max(max_of_terms, ctx)?;
// Current bounds of the sum of all terms
let min = self.s.min(ctx);
let max = self.s.max(ctx);
for x in &self.xs {
let _ = x.try_set_min(min - (max_of_terms - x.max(ctx)), ctx)?; //<---- here
let _ = x.try_set_max(max - (min_of_terms - x.min(ctx)), ctx)?;
}
Some(())
}
}with code:
#[test]
fn a(){
let mut m = Model::default();
let vars: Vec<_> = m.new_vars(3, i32::MIN / 4, i32::MAX / 4).unwrap().collect();
let c1 = m.sum(&vars);
m.less_than_or_equals(c1, 256);
m.maximize(c1).unwrap();
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels