pcp/propagators/cmp/
mod.rs

1// Copyright 2015 Pierre Talbot (IRCAM)
2
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6
7//     http://www.apache.org/licenses/LICENSE-2.0
8
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15pub mod x_less_y;
16pub mod x_eq_y;
17pub mod x_neq_y;
18pub mod x_greater_y_plus_z;
19pub mod x_less_y_plus_z;
20pub mod x_eq_y_plus_z;
21pub mod x_eq_y_mul_z;
22
23use term::*;
24use gcollections::*;
25use concept::*;
26pub use propagators::cmp::x_eq_y_plus_z::XEqYPlusZ;
27pub use propagators::cmp::x_less_y_plus_z::XLessYPlusZ;
28pub use propagators::cmp::x_greater_y_plus_z::XGreaterYPlusZ;
29pub use propagators::cmp::x_eq_y_mul_z::XEqYMulZ;
30pub use propagators::cmp::x_less_y::XLessY;
31pub use propagators::cmp::x_eq_y::XEqY;
32pub use propagators::cmp::x_neq_y::XNeqY;
33
34pub type XGreaterY<VStore> = XLessY<VStore>;
35pub type XGreaterEqY<VStore> = XLessY<VStore>;
36pub type XLessEqY<VStore> = XLessY<VStore>;
37pub type XGreaterEqYPlusZ<VStore> = XGreaterYPlusZ<VStore>;
38pub type XLessEqYPlusZ<VStore> = XLessYPlusZ<VStore>;
39
40pub fn x_greater_y<VStore>(x: Var<VStore>, y: Var<VStore>) -> XGreaterY<VStore> {
41  XLessY::new(y, x)
42}
43
44pub fn x_geq_y<VStore, Domain, Bound>(x: Var<VStore>, y: Var<VStore>) -> XGreaterEqY<VStore> where
45  VStore: VStoreConcept<Item=Domain> + 'static,
46  Domain: Collection<Item=Bound> + IntDomain,
47  Bound: IntBound
48{
49  x_greater_y(Box::new(Addition::new(x, Bound::one())), y)
50}
51
52pub fn x_leq_y<VStore, Domain, Bound>(x: Var<VStore>, y: Var<VStore>) -> XLessEqY<VStore> where
53  VStore: VStoreConcept<Item=Domain> + 'static,
54  Domain: Collection<Item=Bound> + IntDomain,
55  Bound: IntBound
56{
57  XLessY::new(x, Box::new(Addition::new(y, Bound::one())))
58}
59
60pub fn x_geq_y_plus_z<VStore, Domain, Bound>(x: Var<VStore>, y: Var<VStore>, z: Var<VStore>)
61  -> XGreaterEqYPlusZ<VStore> where
62 VStore: VStoreConcept<Item=Domain> + 'static,
63 Domain: Collection<Item=Bound> + IntDomain,
64 Bound: IntBound
65{
66  XGreaterYPlusZ::new(Box::new(Addition::new(x, Bound::one())), y, z)
67}
68
69pub fn x_leq_y_plus_z<VStore, Domain, Bound>(x: Var<VStore>, y: Var<VStore>, z: Var<VStore>)
70  -> XLessEqYPlusZ<VStore> where
71 VStore: VStoreConcept<Item=Domain> + 'static,
72 Domain: Collection<Item=Bound> + IntDomain,
73 Bound: IntBound
74{
75  XLessYPlusZ::new(Box::new(Addition::new(x, -Bound::one())), y, z)
76}
77
78// #[cfg(test)]
79// mod test {
80//   use super::*;
81//   use kernel::*;
82//   use trilean::SKleene::*;
83//   use propagation::events::*;
84//   use propagation::events::FDEvent::*;
85//   use interval::interval::*;
86//   use propagators::test::*;
87
88//   #[test]
89//   fn x_greater_y_test() {
90//     let dom0_10 = (0,10).to_interval();
91//     let dom10_20 = (10,20).to_interval();
92//     let dom10_11 = (10,11).to_interval();
93//     let dom5_15 = (5,15).to_interval();
94//     let dom5_11 = (5,11).to_interval();
95//     let dom11_20 = (11,20).to_interval();
96//     let dom9_9 = (9,9).to_interval();
97
98//     x_greater_y_test_one(1, dom0_10, dom0_10, Unknown, Unknown, vec![(0, Bound), (1, Bound)], true);
99//     x_greater_y_test_one(2, dom0_10, dom10_20, False, False, vec![], false);
100//     x_greater_y_test_one(3, dom5_15, dom10_20, Unknown, Unknown, vec![(0, Bound), (1, Bound)], true);
101//     x_greater_y_test_one(4, dom5_11, dom10_20, Unknown, True, vec![(0, Assignment), (1, Assignment)], true);
102//     x_greater_y_test_one(5, dom10_11, dom10_11, Unknown, True, vec![(0, Assignment), (1, Assignment)], true);
103//     x_greater_y_test_one(6, dom5_15, dom0_10, Unknown, Unknown, vec![], true);
104//     x_greater_y_test_one(7, dom11_20, dom0_10, True, True, vec![], true);
105//     x_greater_y_test_one(8, dom9_9, dom0_10, Unknown, True, vec![(1, Bound)], true);
106//   }
107
108//   fn x_greater_y_test_one(test_num: u32, x: Interval<i32>, y: Interval<i32>,
109//     before: SKleene, after: SKleene,
110//     delta_expected: Vec<(usize, FDEvent)>, propagate_success: bool)
111//   {
112//     binary_propagator_test(test_num, x_greater_y, x, y, before, after, delta_expected, propagate_success);
113//   }
114
115//   #[test]
116//   fn x_geq_y_test() {
117//     let dom0_10 = (0,10).to_interval();
118//     let dom10_20 = (10,20).to_interval();
119//     let dom10_11 = (10,11).to_interval();
120//     let dom5_15 = (5,15).to_interval();
121//     let dom11_20 = (11,20).to_interval();
122//     let dom9_9 = (9,9).to_interval();
123
124//     x_geq_y_test_one(1, dom0_10, dom0_10, Unknown, Unknown, vec![], true);
125//     x_geq_y_test_one(2, dom0_10, dom10_20, Unknown, True, vec![(0, Assignment), (1, Assignment)], true);
126//     x_geq_y_test_one(3, dom5_15, dom10_20, Unknown, Unknown, vec![(0, Bound), (1, Bound)], true);
127//     x_geq_y_test_one(4, dom10_11, dom10_11, Unknown, Unknown, vec![], true);
128//     x_geq_y_test_one(5, dom5_15, dom0_10, Unknown, Unknown, vec![], true);
129//     x_geq_y_test_one(6, dom11_20, dom0_10, True, True, vec![], true);
130//     x_geq_y_test_one(7, dom9_9, dom0_10, Unknown, True, vec![(1, Bound)], true);
131//   }
132
133//   fn x_geq_y_test_one(test_num: u32, x: Interval<i32>, y: Interval<i32>,
134//     before: SKleene, after: SKleene,
135//     delta_expected: Vec<(usize, FDEvent)>, propagate_success: bool)
136//   {
137//     binary_propagator_test(test_num, x_geq_y::<_,_,i32>, x, y, before, after, delta_expected, propagate_success);
138//   }
139// }