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        Lbd {
15            lbd_helper: SparseSet::new(vec![]),
16        }
17    }
18}
19
20impl Lbd {
21    /// Compute the LBD of the given nogood under the given assignment.
22    pub fn compute_lbd<Context: ReadDomains>(
23        &mut self,
24        predicates: &[Predicate],
25        context: &Context,
26    ) -> u32 {
27        self.lbd_helper.set_to_empty();
28        self.lbd_helper
29            .accommodate(&(context.get_checkpoint() as u32));
30
31        for predicate in predicates {
32            let checkpoint = context.get_checkpoint_for_predicate(*predicate).unwrap();
33
34            self.lbd_helper.insert(checkpoint as u32);
35        }
36
37        self.lbd_helper.len() as u32
38    }
39}