Skip to content

Commit

Permalink
using normal propagators for value propagations when all variables ar…
Browse files Browse the repository at this point in the history
…e fixed
  • Loading branch information
AllenZzw committed Nov 14, 2024
1 parent b8917e5 commit cc19de9
Show file tree
Hide file tree
Showing 16 changed files with 205 additions and 50 deletions.
3 changes: 3 additions & 0 deletions crates/huub/src/helpers/opt_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ impl<const B: usize, T> OptField<B, T> {
pub(crate) fn get(&self) -> Option<&T> {
self.value.first()
}
pub(crate) fn is_some(&self) -> bool {
!self.value.is_empty()
}
}
impl<T> OptField<1, T> {
pub(crate) fn new(value: T) -> Self {
Expand Down
1 change: 1 addition & 0 deletions crates/huub/src/propagator/all_different_int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ impl Poster for AllDifferentIntValuePoster {
for &v in prop.vars.iter() {
actions.enqueue_on_int_change(v, IntPropCond::Fixed);
}
actions.enqueue_when_n_fixed(prop.vars.len(), &[], &prop.vars);
Ok((
Box::new(prop),
QueuePreferences {
Expand Down
6 changes: 6 additions & 0 deletions crates/huub/src/propagator/array_int_minimum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ impl Poster for ArrayIntMinimumBoundsPoster {
actions.enqueue_on_int_change(v, IntPropCond::Bounds);
}
actions.enqueue_on_int_change(prop.min, IntPropCond::LowerBound);

actions.enqueue_when_n_fixed(
prop.vars.len() + 1,
&[],
&[prop.vars.as_slice(), &[prop.min]].concat(),
);
Ok((
Box::new(prop),
QueuePreferences {
Expand Down
6 changes: 6 additions & 0 deletions crates/huub/src/propagator/array_var_int_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,12 @@ impl Poster for ArrayVarIntElementBoundsPoster {
};
actions.enqueue_on_int_change(prop.result, IntPropCond::Bounds);
actions.enqueue_on_int_change(prop.index, IntPropCond::Domain);

actions.enqueue_when_n_fixed(
prop.vars.len() + 1,
&[],
&[prop.vars.as_slice(), &[prop.result, prop.index]].concat(),
);
Ok((
Box::new(prop),
QueuePreferences {
Expand Down
2 changes: 2 additions & 0 deletions crates/huub/src/propagator/disjunctive_strict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,8 @@ impl Poster for DisjunctiveEdgeFindingPoster {
actions.enqueue_on_int_change(v, IntPropCond::Bounds);
}

actions.enqueue_when_n_fixed(prop.start_times.len(), &[], &prop.start_times);

Ok((
Box::new(prop),
QueuePreferences {
Expand Down
2 changes: 2 additions & 0 deletions crates/huub/src/propagator/int_abs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ impl Poster for IntAbsBoundsPoster {
// Subscribe only to the upper bound of the absolute value variable
actions.enqueue_on_int_change(self.abs, IntPropCond::UpperBound);

actions.enqueue_when_n_fixed(2, &[], &[self.origin, self.abs]);

Ok((
Box::new(IntAbsBounds {
origin: self.origin,
Expand Down
2 changes: 2 additions & 0 deletions crates/huub/src/propagator/int_div.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ impl Poster for IntDivBoundsPoster {
actions.enqueue_on_int_change(self.denominator, IntPropCond::Bounds);
actions.enqueue_on_int_change(self.result, IntPropCond::Bounds);

actions.enqueue_when_n_fixed(3, &[], &[self.numerator, self.denominator, self.result]);

// Ensure the consistency of the signs of the three variables using the following clauses.
if actions.get_int_lower_bound(self.numerator) < 0
|| actions.get_int_lower_bound(self.denominator) < 0
Expand Down
13 changes: 13 additions & 0 deletions crates/huub/src/propagator/int_lin_le.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,19 @@ impl<const R: usize> Poster for IntLinearLessEqBoundsPoster<R> {
if let Some(r) = prop.reification.get() {
actions.enqueue_on_bool_change(BoolView(BoolViewInner::Lit(*r)));
}

let bool_vec: Vec<BoolView> = prop
.reification
.get()
.map(|&l| BoolView(BoolViewInner::Lit(l)))
.into_iter()
.collect();
actions.enqueue_when_n_fixed(
prop.vars.len() + if prop.reification.is_some() { 1 } else { 0 },
&bool_vec,
&prop.vars,
);

Ok((
Box::new(prop),
QueuePreferences {
Expand Down
19 changes: 12 additions & 7 deletions crates/huub/src/propagator/int_lin_ne.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
Propagator,
},
solver::{
engine::{activation_list::IntPropCond, queue::PriorityLevel, trail::TrailedInt},
engine::{queue::PriorityLevel, trail::TrailedInt},
poster::{BoxedPropagator, Poster, QueuePreferences},
value::IntVal,
view::{BoolViewInner, IntView, IntViewInner},
Expand Down Expand Up @@ -163,12 +163,17 @@ impl<const R: usize> Poster for IntLinearNotEqValuePoster<R> {
reification: self.reification,
num_fixed: actions.new_trailed_int(0),
};
for &v in prop.vars.iter() {
actions.enqueue_on_int_change(v, IntPropCond::Fixed);
}
if let Some(r) = prop.reification.get() {
actions.enqueue_on_bool_change(BoolView(BoolViewInner::Lit(*r)));
}
let bool_vec: Vec<BoolView> = prop
.reification
.get()
.map(|&l| BoolView(BoolViewInner::Lit(l)))
.into_iter()
.collect();
actions.enqueue_when_n_fixed(
prop.vars.len() + if prop.reification.is_some() { 1 } else { 0 } - 1,
&bool_vec,
&prop.vars,
);
Ok((
Box::new(prop),
QueuePreferences {
Expand Down
2 changes: 2 additions & 0 deletions crates/huub/src/propagator/int_pow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ impl Poster for IntPowBoundsPoster {
actions.enqueue_on_int_change(self.exponent, IntPropCond::Bounds);
actions.enqueue_on_int_change(self.result, IntPropCond::Bounds);

actions.enqueue_when_n_fixed(3, &[], &[self.base, self.exponent, self.result]);

// Ensure that if the base is negative, then the exponent cannot be zero
let (exp_lb, exp_ub) = actions.get_int_bounds(self.exponent);
let (base_lb, base_ub) = actions.get_int_bounds(self.base);
Expand Down
1 change: 1 addition & 0 deletions crates/huub/src/propagator/int_times.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ impl Poster for IntTimesBoundsPoster {
actions.enqueue_on_int_change(self.x, IntPropCond::Bounds);
actions.enqueue_on_int_change(self.y, IntPropCond::Bounds);
actions.enqueue_on_int_change(self.z, IntPropCond::Bounds);
actions.enqueue_when_n_fixed(3, &[], &[self.x, self.y, self.z]);
Ok((
Box::new(IntTimesBounds {
x: self.x,
Expand Down
3 changes: 3 additions & 0 deletions crates/huub/src/solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ impl<Oracle: PropagatingSolver<Engine>> Solver<Oracle> {
debug_assert_eq!(prop_ref, p);
let p = self.engine_mut().state.enqueued.push(false);
debug_assert_eq!(prop_ref, p);
let p = self.engine_mut().state.enqueued_inactive.push(false);
debug_assert_eq!(prop_ref, p);
let p = self.engine_mut().state.activity_scores.push(1.0);
debug_assert_eq!(prop_ref, p);
let p = self.engine_mut().state.functional.push(functional);
Expand All @@ -217,6 +219,7 @@ impl<Oracle: PropagatingSolver<Engine>> Solver<Oracle> {
.propagator_queue
.insert(state.propagator_priority[prop_ref], prop_ref);
state.enqueued[prop_ref] = true;
state.enqueued_inactive[prop_ref] = true;
}
Ok(())
}
Expand Down
Loading

0 comments on commit cc19de9

Please sign in to comment.