prune_lang/interp/
config.rs1use super::*;
2
3#[derive(Debug)]
4pub struct RunnerConfig {
5 pub depth_step: usize,
6 pub depth_limit: usize,
7 pub answer_limit: usize,
8 pub print_iter: bool,
9 pub print_stat: bool,
10 pub answer_pause: bool,
11}
12
13impl Default for RunnerConfig {
14 fn default() -> Self {
15 Self::new()
16 }
17}
18
19impl RunnerConfig {
20 pub fn new() -> RunnerConfig {
21 RunnerConfig {
22 depth_step: 5,
23 depth_limit: 100,
24 answer_limit: usize::MAX,
25 print_iter: true,
26 print_stat: true,
27 answer_pause: false,
28 }
29 }
30
31 pub fn reset_default(&mut self) {
32 self.depth_step = 5;
33 self.depth_limit = 100;
34 self.answer_limit = usize::MAX;
35 self.print_iter = true;
36 self.print_stat = true;
37 self.answer_pause = true;
38 }
39
40 pub fn set_param(&mut self, param: &QueryParam) {
41 match param {
42 QueryParam::DepthStep(x) => {
43 self.depth_step = *x;
44 }
45 QueryParam::DepthLimit(x) => {
46 self.depth_limit = *x;
47 }
48 QueryParam::AnswerLimit(x) => {
49 self.answer_limit = *x;
50 }
51 QueryParam::AnswerPause(x) => {
52 self.answer_pause = *x;
53 }
54 }
55 }
56}
57
58#[derive(Debug)]
59pub struct RunnerStats {
60 pub step_cnt: usize,
61 pub step_cnt_la: usize,
62 pub total_step: usize,
63 pub acc_total_step: usize,
64}
65
66impl Default for RunnerStats {
67 fn default() -> Self {
68 Self::new()
69 }
70}
71
72impl RunnerStats {
73 pub fn new() -> RunnerStats {
74 RunnerStats {
75 step_cnt: 0,
76 step_cnt_la: 0,
77 total_step: 0,
78 acc_total_step: 0,
79 }
80 }
81
82 pub fn reset(&mut self) {
83 self.step_cnt = 0;
84 self.step_cnt_la = 0;
85 self.total_step = 0;
86 }
87
88 pub fn step(&mut self) {
89 self.step_cnt += 1;
90 self.total_step += 1;
91 self.acc_total_step += 1;
92 }
93
94 pub fn step_la(&mut self) {
95 self.step_cnt_la += 1;
96 self.total_step += 1;
97 self.acc_total_step += 1;
98 }
99
100 pub fn print_stat(&self) -> String {
101 format!(
102 "[STAT]: step = {}, step_la = {}(ratio {}), total = {}, acc_total = {} ",
103 self.step_cnt,
104 self.step_cnt_la,
105 (self.step_cnt_la as f32) / (self.step_cnt as f32 + 0.001),
106 self.total_step,
107 self.acc_total_step,
108 )
109 }
110}