pcp/search/
statistics.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 search::monitor::*;
17use search::search_tree_visitor::Status;
18
19pub struct Statistics {
20  pub num_solution: usize,
21  pub num_failed_node: usize,
22  pub num_prune: usize,
23  pub num_nodes: usize
24}
25
26impl Statistics {
27  pub fn new() -> Self {
28    Statistics {
29      num_solution: 0,
30      num_failed_node: 0,
31      num_prune: 0,
32      num_nodes: 0
33    }
34  }
35}
36
37impl<Space:Freeze> SearchMonitor<Space> for Statistics {
38  fn on_node(&mut self, space: &Space, status: &Status<Space>) {
39    println!("\n\nLLLL\n\n");
40    self.num_nodes += 1;
41    self.dispatch_node(space, status)
42  }
43
44  fn on_solution(&mut self, _space: &Space) {
45    self.num_solution += 1;
46  }
47  fn on_failure(&mut self, _space: &Space) {
48    self.num_failed_node += 1;
49  }
50  fn on_prune(&mut self, _space: &Space) {
51    self.num_prune += 1;
52  }
53}