Skip to main content

pumpkin_core/engine/
literal_block_distance.rs

1use crate::containers::SparseSet;
2use crate::predicates::Predicate;
3use crate::propagation::ReadDomains;
4
5/// Used to compute the LBD of nogoods.
6/// The type carries state that prevents the re-allocation of helper data structures.
7#[derive(Clone, Debug)]
8pub struct Lbd {
9    lbd_helper: SparseSet<u32>,
10}
11
12impl Default for Lbd {
13    fn default() -> Self {
14        fn sparse_set_mapping(elem: &u32) -> usize {
15            *elem as usize
16        }
17
18        Lbd {
19            lbd_helper: SparseSet::new(vec![], sparse_set_mapping),
20        }
21    }
22}
23
24impl Lbd {
25    /// Compute the LBD of the given nogood under the given assignment.
26    pub fn compute_lbd<Context: ReadDomains>(
27        &mut self,
28        predicates: &[Predicate],
29        context: &Context,
30    ) -> u32 {
31        self.lbd_helper.set_to_empty();
32        self.lbd_helper
33            .accommodate(&(context.get_checkpoint() as u32));
34
35        for predicate in predicates {
36            let checkpoint = context.get_checkpoint_for_predicate(*predicate).unwrap();
37
38            self.lbd_helper.insert(checkpoint as u32);
39        }
40
41        self.lbd_helper.len() as u32
42    }
43}