pumpkin_core/engine/variables/
constant.rs1use pumpkin_checking::CheckerVariable;
2use pumpkin_checking::IntExt;
3
4use crate::engine::Assignments;
5use crate::predicates::Predicate;
6use crate::predicates::PredicateConstructor;
7use crate::variables::IntegerVariable;
8use crate::variables::TransformableVariable;
9
10impl IntegerVariable for i32 {
11 type AffineView = i32;
12
13 fn lower_bound(&self, _assignment: &Assignments) -> i32 {
14 *self
15 }
16
17 fn lower_bound_at_trail_position(
18 &self,
19 _assignment: &Assignments,
20 _trail_position: usize,
21 ) -> i32 {
22 *self
23 }
24
25 fn upper_bound(&self, _assignment: &Assignments) -> i32 {
26 *self
27 }
28
29 fn upper_bound_at_trail_position(
30 &self,
31 _assignment: &Assignments,
32 _trail_position: usize,
33 ) -> i32 {
34 *self
35 }
36
37 fn contains(&self, _assignment: &Assignments, value: i32) -> bool {
38 value == *self
39 }
40
41 fn contains_at_trail_position(
42 &self,
43 _assignment: &Assignments,
44 value: i32,
45 _trail_position: usize,
46 ) -> bool {
47 value == *self
48 }
49
50 fn iterate_domain(&self, _assignment: &Assignments) -> impl Iterator<Item = i32> {
51 std::iter::once(*self)
52 }
53
54 fn watch_all(
55 &self,
56 _watchers: &mut crate::engine::notifications::Watchers<'_>,
57 _events: enumset::EnumSet<crate::propagation::DomainEvent>,
58 ) {
59 }
60
61 fn unwatch_all(&self, _watchers: &mut crate::engine::notifications::Watchers<'_>) {}
62
63 fn watch_all_backtrack(
64 &self,
65 _watchers: &mut crate::engine::notifications::Watchers<'_>,
66 _events: enumset::EnumSet<crate::propagation::DomainEvent>,
67 ) {
68 }
69
70 fn unpack_event(
71 &self,
72 _event: crate::propagation::OpaqueDomainEvent,
73 ) -> crate::propagation::DomainEvent {
74 unreachable!()
75 }
76
77 fn get_holes_at_current_checkpoint(
78 &self,
79 _assignments: &Assignments,
80 ) -> impl Iterator<Item = i32> {
81 std::iter::empty()
82 }
83
84 fn get_holes(&self, _assignments: &Assignments) -> impl Iterator<Item = i32> {
85 std::iter::empty()
86 }
87}
88
89impl TransformableVariable<i32> for i32 {
90 fn scaled(&self, scale: i32) -> i32 {
91 *self * scale
92 }
93
94 fn offset(&self, offset: i32) -> i32 {
95 *self + offset
96 }
97}
98
99impl PredicateConstructor for i32 {
100 type Value = i32;
101
102 fn equality_predicate(&self, bound: Self::Value) -> Predicate {
103 if bound == *self {
104 Predicate::trivially_true()
105 } else {
106 Predicate::trivially_false()
107 }
108 }
109
110 fn lower_bound_predicate(&self, bound: Self::Value) -> Predicate {
111 if bound <= *self {
112 Predicate::trivially_true()
113 } else {
114 Predicate::trivially_false()
115 }
116 }
117
118 fn upper_bound_predicate(&self, bound: Self::Value) -> Predicate {
119 if bound >= *self {
120 Predicate::trivially_true()
121 } else {
122 Predicate::trivially_false()
123 }
124 }
125
126 fn disequality_predicate(&self, bound: Self::Value) -> Predicate {
127 if bound != *self {
128 Predicate::trivially_true()
129 } else {
130 Predicate::trivially_false()
131 }
132 }
133}
134
135impl CheckerVariable<Predicate> for i32 {
136 fn does_atomic_constrain_self(&self, _atomic: &Predicate) -> bool {
137 false
138 }
139
140 fn atomic_less_than(&self, value: i32) -> Predicate {
141 if value >= *self {
142 Predicate::trivially_true()
143 } else {
144 Predicate::trivially_false()
145 }
146 }
147
148 fn atomic_greater_than(&self, value: i32) -> Predicate {
149 if value <= *self {
150 Predicate::trivially_true()
151 } else {
152 Predicate::trivially_false()
153 }
154 }
155
156 fn atomic_equal(&self, value: i32) -> Predicate {
157 if value == *self {
158 Predicate::trivially_true()
159 } else {
160 Predicate::trivially_false()
161 }
162 }
163
164 fn atomic_not_equal(&self, value: i32) -> Predicate {
165 if value != *self {
166 Predicate::trivially_true()
167 } else {
168 Predicate::trivially_false()
169 }
170 }
171
172 fn induced_lower_bound(
173 &self,
174 _variable_state: &pumpkin_checking::VariableState<Predicate>,
175 ) -> IntExt {
176 IntExt::Int(*self)
177 }
178
179 fn induced_upper_bound(
180 &self,
181 _variable_state: &pumpkin_checking::VariableState<Predicate>,
182 ) -> IntExt {
183 IntExt::Int(*self)
184 }
185
186 fn induced_fixed_value(
187 &self,
188 _variable_state: &pumpkin_checking::VariableState<Predicate>,
189 ) -> Option<i32> {
190 Some(*self)
191 }
192
193 fn induced_domain_contains(
194 &self,
195 _variable_state: &pumpkin_checking::VariableState<Predicate>,
196 value: i32,
197 ) -> bool {
198 value == *self
199 }
200
201 fn induced_holes<'this, 'state>(
202 &'this self,
203 _variable_state: &'state pumpkin_checking::VariableState<Predicate>,
204 ) -> impl Iterator<Item = i32> + 'state
205 where
206 'this: 'state,
207 {
208 std::iter::empty()
209 }
210
211 fn iter_induced_domain<'this, 'state>(
212 &'this self,
213 _variable_state: &'state pumpkin_checking::VariableState<Predicate>,
214 ) -> Option<impl Iterator<Item = i32> + 'state>
215 where
216 'this: 'state,
217 {
218 Some(std::iter::once(*self))
219 }
220}