1use trilean::SKleene;
18use kernel::*;
19use model::*;
20use logic::{Boolean, NotFormula};
21use propagation::*;
22use propagation::events::*;
23use term::ops::*;
24use gcollections::kind::*;
25use gcollections::ops::*;
26use num::traits::Num;
27use std::fmt::{Debug, Formatter, Result};
28use concept::*;
29
30pub struct BooleanNeg<VStore> {
31 b: Boolean<VStore>
32}
33
34impl<VStore> BooleanNeg<VStore>
35{
36 pub fn new(b: Boolean<VStore>) -> Self {
37 BooleanNeg {
38 b: b
39 }
40 }
41}
42
43impl<VStore> Debug for BooleanNeg<VStore>
44{
45 fn fmt(&self, fmt: &mut Formatter) -> Result {
46 fmt.debug_struct("BooleanNeg")
47 .field("b", &self.b)
48 .finish()
49 }
50}
51
52impl<VStore> Clone for BooleanNeg<VStore> where
53 VStore: Collection
54{
55 fn clone(&self) -> Self {
56 BooleanNeg {
57 b: self.b.clone()
58 }
59 }
60}
61
62impl<VStore> DisplayStateful<Model> for BooleanNeg<VStore>
63{
64 fn display(&self, model: &Model) {
65 print!("not ");
66 self.b.display(model);
67 }
68}
69
70impl<VStore, Domain, Bound> NotFormula<VStore> for BooleanNeg<VStore> where
71 VStore: VStoreConcept<Item=Domain> + 'static,
72 Domain: IntDomain<Item=Bound> + 'static,
73 Bound: IntBound + 'static,
74{
75 fn not(&self) -> Formula<VStore> {
76 Box::new(self.b.clone())
77 }
78}
79
80impl<VStore, Dom, Bound> Subsumption<VStore> for BooleanNeg<VStore> where
81 VStore: Collection<Item=Dom>,
82 Dom: Bounded<Item=Bound> + IsSingleton,
83 Bound: Num
84{
85 fn is_subsumed(&self, vstore: &VStore) -> SKleene {
86 !self.b.is_subsumed(vstore)
87 }
88}
89
90impl<VStore, Dom, Bound> Propagator<VStore> for BooleanNeg<VStore> where
91 VStore: VStoreConcept<Item=Dom>,
92 Dom: Collection<Item=Bound> + Singleton,
93 Bound: Num
94{
95 fn propagate(&mut self, vstore: &mut VStore) -> bool {
96 self.b.update(vstore, Dom::singleton(Bound::zero()))
97 }
98}
99
100impl<VStore> PropagatorDependencies<FDEvent> for BooleanNeg<VStore>
101{
102 fn dependencies(&self) -> Vec<(usize, FDEvent)> {
103 PropagatorDependencies::dependencies(&self.b)
104 }
105}