pumpkin_solver/branching/variable_selection/
dynamic_variable_selector.rs

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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use std::fmt::Debug;

use super::VariableSelector;
#[cfg(doc)]
use crate::branching::branchers::dynamic_brancher::DynamicBrancher;
use crate::branching::SelectionContext;
use crate::engine::variables::DomainId;
use crate::engine::variables::Literal;

/// Similar to [`DynamicBrancher`], this is a pass-along structure which should be used when a
/// [`Sized`] object is required.
pub struct DynamicVariableSelector<Var> {
    selector: Box<dyn VariableSelector<Var>>,
}

impl<Var> Debug for DynamicVariableSelector<Var> {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("DynamicVariableSelector").finish()
    }
}

impl<Var> DynamicVariableSelector<Var> {
    pub fn new(selector: Box<dyn VariableSelector<Var>>) -> Self {
        Self { selector }
    }
}

impl<Var> VariableSelector<Var> for DynamicVariableSelector<Var> {
    fn select_variable(&mut self, context: &SelectionContext) -> Option<Var> {
        self.selector.select_variable(context)
    }

    fn on_appearance_in_conflict_integer(&mut self, variable: DomainId) {
        self.selector.on_appearance_in_conflict_integer(variable)
    }

    fn on_conflict(&mut self) {
        self.selector.on_conflict()
    }

    fn on_unassign_integer(&mut self, variable: DomainId, value: i32) {
        self.selector.on_unassign_integer(variable, value)
    }

    fn on_appearance_in_conflict_literal(&mut self, literal: Literal) {
        self.selector.on_appearance_in_conflict_literal(literal)
    }

    fn on_unassign_literal(&mut self, literal: Literal) {
        self.selector.on_unassign_literal(literal)
    }

    fn is_restart_pointless(&mut self) -> bool {
        self.selector.is_restart_pointless()
    }
}