1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//! Compute glue levels of clauses.
//!
//! The glue level of a propagating clause is the number of distinct decision levels of the clause's
//! variables. This is also called the literal block distance (LBD). For each clause the smallest
//! glue level observed is used as an indicator of how useful that clause is.

use partial_ref::{partial, PartialRef};

use varisat_formula::Lit;

use crate::context::{parts::*, Context};

/// Compute the glue level of a clause.
pub fn compute_glue(mut ctx: partial!(Context, mut TmpFlagsP, ImplGraphP), lits: &[Lit]) -> usize {
    let (tmp_flags, ctx) = ctx.split_part_mut(TmpFlagsP);
    let impl_graph = ctx.part(ImplGraphP);
    let flags = &mut tmp_flags.flags;

    let mut glue = 0;

    for &lit in lits {
        let level = impl_graph.level(lit.var());
        let flag = &mut flags[level];
        if !*flag {
            *flag = true;
            glue += 1
        }
    }

    for &lit in lits {
        let level = impl_graph.level(lit.var());
        flags[level] = false;
    }

    glue
}