pcp/search/
propagation.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
15use kernel::*;
16use trilean::SKleene::*;
17use search::space::*;
18use search::search_tree_visitor::*;
19use concept::*;
20
21pub struct Propagation<C> {
22  child: C
23}
24
25impl<C> Propagation<C> {
26  pub fn new(child: C) -> Propagation<C> {
27    Propagation {
28      child: child
29    }
30  }
31}
32
33impl<VStore, CStore, R, C> SearchTreeVisitor<Space<VStore, CStore, R>> for Propagation<C> where
34  VStore: VStoreConcept,
35  CStore: IntCStore<VStore>,
36  C: SearchTreeVisitor<Space<VStore, CStore, R>>,
37  R: FreezeSpace<VStore, CStore> + Snapshot<State=Space<VStore, CStore, R>>
38{
39  fn start(&mut self, root: &Space<VStore, CStore, R>) {
40    self.child.start(root);
41  }
42
43  fn enter(&mut self, mut current: Space<VStore, CStore, R>)
44    -> (<Space<VStore, CStore, R> as Freeze>::FrozenState, Status<Space<VStore, CStore, R>>)
45  {
46    let status = current.consistency();
47    match status {
48      True => (current.freeze(), Status::Satisfiable),
49      False => (current.freeze(), Status::Unsatisfiable),
50      Unknown => self.child.enter(current)
51    }
52  }
53}