Skip to content

Commit

Permalink
Add int_pow propagator
Browse files Browse the repository at this point in the history
  • Loading branch information
Dekker1 committed May 31, 2024
1 parent 27dd5a7 commit e23a091
Show file tree
Hide file tree
Showing 5 changed files with 385 additions and 1 deletion.
9 changes: 9 additions & 0 deletions crates/huub/src/model/constraint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use crate::{
array_var_int_element::ArrayVarIntElementBounds,
int_lin_le::{IntLinearLessEqBounds, IntLinearLessEqImpBounds},
int_lin_ne::{IntLinearNotEqImpValue, IntLinearNotEqValue},
int_pow::IntPowBounds,
int_times::IntTimesBounds,
},
solver::{
Expand All @@ -47,6 +48,7 @@ pub enum Constraint {
IntLinNotEq(Vec<IntView>, IntVal),
IntLinNotEqImp(Vec<IntView>, IntVal, BoolExpr),
IntLinNotEqReif(Vec<IntView>, IntVal, BoolExpr),
IntPow(IntView, IntView, IntView),
IntTimes(IntView, IntView, IntView),
PropLogic(BoolExpr),
SetInReif(IntView, IntSetVal, BoolExpr),
Expand Down Expand Up @@ -334,6 +336,13 @@ impl Constraint {
}
Ok(())
}
Constraint::IntPow(base, exponent, res) => {
let base = base.to_arg(ReifContext::Mixed, slv, map);
let exponent = exponent.to_arg(ReifContext::Mixed, slv, map);
let result = res.to_arg(ReifContext::Mixed, slv, map);
slv.add_propagator(IntPowBounds::prepare(base, exponent, result));
Ok(())
}
Constraint::IntTimes(x, y, z) => {
let x = x.to_arg(ReifContext::Mixed, slv, map);
let y = y.to_arg(ReifContext::Mixed, slv, map);
Expand Down
15 changes: 15 additions & 0 deletions crates/huub/src/model/flatzinc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,21 @@ impl Model {
});
}
}
"int_pow" => {
if let [base, exponent, res] = c.args.as_slice() {
let base = arg_int(fzn, &mut prb, &mut map, base)?;
let exponent = arg_int(fzn, &mut prb, &mut map, exponent)?;
let res = arg_int(fzn, &mut prb, &mut map, res)?;

prb += Constraint::IntPow(base, exponent, res);
} else {
return Err(FlatZincError::InvalidNumArgs {
name: "int_pow",
found: c.args.len(),
expected: 3,
});
}
}
"int_times" => {
if let [x, y, z] = c.args.as_slice() {
let a = arg_int(fzn, &mut prb, &mut map, x)?;
Expand Down
1 change: 1 addition & 0 deletions crates/huub/src/propagator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub(crate) mod conflict;
pub(crate) mod int_event;
pub(crate) mod int_lin_le;
pub(crate) mod int_lin_ne;
pub(crate) mod int_pow;
pub(crate) mod int_times;
pub(crate) mod reason;

Expand Down
Loading

0 comments on commit e23a091

Please sign in to comment.