pumpkin_core/engine/variables/
integer_variable.rs

1use std::fmt::Debug;
2
3use enumset::EnumSet;
4
5use super::TransformableVariable;
6use crate::engine::notifications::DomainEvent;
7use crate::engine::notifications::OpaqueDomainEvent;
8use crate::engine::notifications::Watchers;
9use crate::engine::predicates::predicate_constructor::PredicateConstructor;
10use crate::engine::Assignments;
11
12/// A trait specifying the required behaviour of an integer variable such as retrieving a
13/// lower-bound ([`IntegerVariable::lower_bound`]).
14pub trait IntegerVariable:
15    Clone + PredicateConstructor<Value = i32> + TransformableVariable<Self::AffineView> + Debug
16{
17    type AffineView: IntegerVariable;
18
19    /// Get the lower bound of the variable.
20    fn lower_bound(&self, assignment: &Assignments) -> i32;
21
22    /// Get the lower bound of the variable at the given trail position.
23    fn lower_bound_at_trail_position(&self, assignment: &Assignments, trail_position: usize)
24        -> i32;
25
26    /// Get the upper bound of the variable.
27    fn upper_bound(&self, assignment: &Assignments) -> i32;
28
29    /// Get the upper bound of the variable at the given trail position.
30    fn upper_bound_at_trail_position(&self, assignment: &Assignments, trail_position: usize)
31        -> i32;
32
33    /// Determine whether the value is in the domain of this variable.
34    fn contains(&self, assignment: &Assignments, value: i32) -> bool;
35
36    /// Determine whether the value is in the domain of this variable at the given trail position.
37    fn contains_at_trail_position(
38        &self,
39        assignment: &Assignments,
40        value: i32,
41        trail_position: usize,
42    ) -> bool;
43
44    /// Iterate over the values of the domain.
45    fn iterate_domain(&self, assignment: &Assignments) -> impl Iterator<Item = i32>;
46
47    /// Register a watch for this variable on the given domain events.
48    fn watch_all(&self, watchers: &mut Watchers<'_>, events: EnumSet<DomainEvent>);
49
50    fn watch_all_backtrack(&self, watchers: &mut Watchers<'_>, events: EnumSet<DomainEvent>);
51
52    /// Decode a domain event for this variable.
53    fn unpack_event(&self, event: OpaqueDomainEvent) -> DomainEvent;
54
55    /// Returns all of the holes in the domain which were created at the current decision level
56    fn get_holes_on_current_decision_level(
57        &self,
58        assignments: &Assignments,
59    ) -> impl Iterator<Item = i32>;
60
61    /// Returns all of the holes in the domain
62    fn get_holes(&self, assignments: &Assignments) -> impl Iterator<Item = i32>;
63}