pcp/
concept.rs

1// Copyright 2016 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
15use gcollections::*;
16use gcollections::ops::*;
17use kernel::*;
18use model::*;
19use term::ops::*;
20use propagation::events::*;
21use propagation::concept::*;
22use interval::ops::Range;
23use num::{Signed, Integer};
24use std::ops::*;
25use std::fmt::Debug;
26
27pub use variable::concept::*;
28
29pub trait IntBound:
30  Integer + Clone + Debug
31  + Signed // Due to the lack of Subtraction in term/
32{}
33
34impl<R> IntBound for R where
35  R: Integer + Clone + Debug
36  + Signed
37{}
38
39pub trait IntDomain:
40  Bounded + Cardinality + Empty + IsEmpty + Singleton + IsSingleton + Range + Contains +
41  ShrinkLeft + ShrinkRight + StrictShrinkLeft + StrictShrinkRight +
42  Difference<<Self as Collection>::Item, Output=Self> +
43  Intersection<Output=Self> + Difference<Output=Self> + Overlap + Subset + Disjoint +
44  Add<<Self as Collection>::Item, Output=Self> + Sub<<Self as Collection>::Item, Output=Self> +
45  Add<Output=Self> + Sub<Output=Self> + Mul<Output=Self> +
46  Clone + Debug
47where
48  <Self as Collection>::Item: IntBound
49{}
50
51impl<R> IntDomain for R where
52  R: Bounded + Cardinality + Empty + IsEmpty + Singleton + IsSingleton + Range + Contains,
53  R: ShrinkLeft + ShrinkRight + StrictShrinkLeft + StrictShrinkRight,
54  R: Difference<<R as Collection>::Item, Output=R>,
55  R: Intersection<Output=R> + Difference<Output=R> + Overlap + Subset + Disjoint,
56  R: Add<<R as Collection>::Item, Output=R> + Sub<<R as Collection>::Item, Output=R>,
57  R: Add<Output=R> + Sub<Output=R> + Mul<Output=R>,
58  R: Clone + Debug,
59  <R as Collection>::Item: IntBound
60{}
61
62pub trait IntVariable_<VStore>:
63  ViewDependencies<FDEvent> +
64  StoreMonotonicUpdate<VStore> +
65  StoreRead<VStore> +
66  Debug + DisplayStateful<Model>
67 where VStore: Collection
68{}
69
70impl<R, VStore> IntVariable_<VStore> for R where
71  R: ViewDependencies<FDEvent>,
72  R: StoreMonotonicUpdate<VStore>,
73  R: StoreRead<VStore>,
74  R: Debug + DisplayStateful<Model>,
75  VStore: Collection
76{}
77
78pub type Var<VStore> = Box<dyn IntVariable<VStore>>;
79
80pub trait IntVariable<VStore>: IntVariable_<VStore>
81  where VStore: Collection
82{
83  fn bclone(&self) -> Box<dyn IntVariable<VStore>>;
84}
85
86impl<VStore, R> IntVariable<VStore> for R where
87  R: IntVariable_<VStore>,
88  R: Clone + 'static,
89  VStore: Collection
90{
91  fn bclone(&self) -> Box<dyn IntVariable<VStore>> {
92    Box::new(self.clone())
93  }
94}
95
96pub trait IntCStore<VStore>:
97  Alloc + Empty + Clone + Freeze + DisplayStateful<Model> + DisplayStateful<(Model, VStore)> +
98  Collection<Item=Box<dyn PropagatorConcept<VStore, FDEvent>>> +
99  Consistency<VStore>
100{}
101
102impl<R, VStore> IntCStore<VStore> for R where
103  R: Alloc + Empty + Clone + Freeze + DisplayStateful<Model> + DisplayStateful<(Model, VStore)>,
104  R: Collection<Item=Box<dyn PropagatorConcept<VStore, FDEvent>>>,
105  R: Consistency<VStore>
106{}
107
108pub type Formula<VStore> = Box<dyn PropagatorConcept<VStore, FDEvent>>;