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