pcp/search/
debugger.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 kernel::*;
16use gcollections::ops::*;
17use search::space::*;
18use search::search_tree_visitor::*;
19use std::io::{self};
20use concept::*;
21use model::*;
22
23pub struct Debugger<C> {
24  model: Model,
25  child: C
26}
27
28impl<C> Debugger<C> {
29  pub fn new(model: Model, child: C) -> Debugger<C> {
30    Debugger {
31      model: model,
32      child: child
33    }
34  }
35}
36
37impl<VStore, CStore, Domain, R, C> SearchTreeVisitor<Space<VStore, CStore, R>> for Debugger<C> where
38  VStore: VStoreConcept<Item=Domain> + Clone,
39  CStore: IntCStore<VStore> + DisplayStateful<(Model, VStore)>,
40  C: SearchTreeVisitor<Space<VStore, CStore, R>>,
41  Domain: IsSingleton,
42  R: FreezeSpace<VStore, CStore> + Snapshot<State=Space<VStore, CStore, R>>
43{
44  fn start(&mut self, root: &Space<VStore, CStore, R>) {
45    self.child.start(root);
46  }
47
48  fn enter(&mut self, current: Space<VStore, CStore, R>)
49    -> (<Space<VStore, CStore, R> as Freeze>::FrozenState, Status<Space<VStore, CStore, R>>)
50  {
51    let (frozen, status) = self.child.enter(current);
52    let current = frozen.unfreeze();
53    println!("Variable store:");
54    println!("  Number of variables: {}", current.vstore.size());
55    println!("  Number of variables assigned: {}", current.vstore.iter().filter(|v| v.is_singleton()).count());
56    current.vstore.display(&self.model);
57    println!("Constraint store:");
58    current.cstore.display(&(self.model.clone(), current.vstore.clone()));
59    println!("Status {:?}", status);
60    println!("Press enter to continue...");
61    let mut buffer = String::new();
62    io::stdin().read_line(&mut buffer).unwrap();
63    (current.freeze(), status)
64  }
65}