Skip to main content

pumpkin_core/engine/variables/
integer_variable.rs

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