AI 24/25 Project Software
Documentation for the AI 24/25 course programming project software
Loading...
Searching...
No Matches
search_statistics.h
1#ifndef SEARCH_STATISTICS_H
2#define SEARCH_STATISTICS_H
3
4/*
5 This class keeps track of search statistics.
6
7 It keeps counters for expanded, generated and evaluated states (and
8 some other statistics) and provides uniform output for all search
9 methods.
10*/
11
12namespace utils {
13class LogProxy;
14}
15
16class SearchStatistics {
17 utils::LogProxy &log;
18
19 // General statistics
20 int expanded_states; // no states for which successors were generated
21 int evaluated_states; // no states for which h fn was computed
22 int evaluations; // no of heuristic evaluations performed
23 int generated_states; // no states created in total (plus those removed since already in close list)
24 int reopened_states; // no of *closed* states which we reopened
25 int dead_end_states;
26
27 int generated_ops; // no of operators that were returned as applicable
28
29 // Statistics related to f values
30 int lastjump_f_value; //f value obtained in the last jump
31 int lastjump_expanded_states; // same guy but at point where the last jump in the open list
32 int lastjump_reopened_states; // occurred (jump == f-value of the first node in the queue increases)
33 int lastjump_evaluated_states;
34 int lastjump_generated_states;
35
36 void print_f_line() const;
37public:
38 explicit SearchStatistics(utils::LogProxy &log);
39 ~SearchStatistics() = default;
40
41 // Methods that update statistics.
42 void inc_expanded(int inc = 1) {expanded_states += inc;}
43 void inc_evaluated_states(int inc = 1) {evaluated_states += inc;}
44 void inc_generated(int inc = 1) {generated_states += inc;}
45 void inc_reopened(int inc = 1) {reopened_states += inc;}
46 void inc_generated_ops(int inc = 1) {generated_ops += inc;}
47 void inc_evaluations(int inc = 1) {evaluations += inc;}
48 void inc_dead_ends(int inc = 1) {dead_end_states += inc;}
49
50 // Methods that access statistics.
51 int get_expanded() const {return expanded_states;}
52 int get_evaluated_states() const {return evaluated_states;}
53 int get_evaluations() const {return evaluations;}
54 int get_generated() const {return generated_states;}
55 int get_reopened() const {return reopened_states;}
56 int get_generated_ops() const {return generated_ops;}
57
58 /*
59 Call the following method with the f value of every expanded
60 state. It will notice "jumps" (i.e., when the expanded f value
61 is the highest f value encountered so far), print some
62 statistics on jumps, and keep track of expansions etc. up to the
63 last jump.
64
65 Statistics until the final jump are often useful to report in
66 A*-style searches because they are not affected by tie-breaking
67 as the overall statistics. (With a non-random, admissible and
68 consistent heuristic, the number of expanded, evaluated and
69 generated states until the final jump is fully determined by the
70 state space and heuristic, independently of things like the
71 order in which successors are generated or the tie-breaking
72 performed by the open list.)
73 */
74 void report_f_value_progress(int f);
75 void print_checkpoint_line(int g) const;
76
77 // output
78 void print_basic_statistics() const;
79 void print_detailed_statistics() const;
80};
81
82#endif