pumpkin_core/engine/variables/
integer_variable.rs

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