AI 24/25 Project Software
Documentation for the AI 24/25 course programming project software
Loading...
Searching...
No Matches
evaluator.h
1#ifndef EVALUATOR_H
2#define EVALUATOR_H
3
4#include "downward/evaluation_result.h"
5
6#include "downward/utils/logging.h"
7
8#include <set>
9
10class EvaluationContext;
11class State;
12
13class Evaluator {
14 const std::string description;
15 const bool use_for_reporting_minima;
16 const bool use_for_boosting;
17 const bool use_for_counting_evaluations;
18
19protected:
20 mutable utils::LogProxy log;
21
22public:
23 Evaluator(
24 bool use_for_reporting_minima,
25 bool use_for_boosting,
26 bool use_for_counting_evaluations,
27 const std::string& description,
28 utils::Verbosity verbosity);
29 virtual ~Evaluator() = default;
30
31 /*
32 dead_ends_are_reliable should return true if the evaluator is
33 "safe", i.e., infinite estimates can be trusted.
34
35 The default implementation returns true.
36 */
37 virtual bool dead_ends_are_reliable() const;
38
39 /*
40 get_path_dependent_evaluators should insert all path-dependent
41 evaluators that this evaluator directly or indirectly depends on
42 into the result set, including itself if necessary.
43
44 The two notify methods below will be called for these and only
45 these evaluators. In other words, "path-dependent" for our
46 purposes means "needs to be notified of the initial state and
47 state transitions".
48 */
49 virtual void get_path_dependent_evaluators(std::set<Evaluator*>& evals) = 0;
50
51 virtual void notify_initial_state(const State& /*initial_state*/) {}
52
53 virtual void notify_state_transition(
54 const State& /*parent_state*/,
55 OperatorID /*op_id*/,
56 const State& /*state*/)
57 {
58 }
59
60 /*
61 compute_result should compute the estimate and possibly
62 preferred operators for the given evaluation context and return
63 them as an EvaluationResult instance.
64
65 It should not add the result to the evaluation context -- this
66 is done automatically elsewhere.
67
68 The passed-in evaluation context is not const because this
69 evaluator might depend on other evaluators, in which case their
70 results will be stored in the evaluation context as a side
71 effect (to make sure they are only computed once).
72
73 TODO: We should make sure that evaluators don't directly call
74 compute_result for their subevaluators, as this could circumvent
75 the caching mechanism provided by the EvaluationContext. The
76 compute_result method should only be called by
77 EvaluationContext. We need to think of a clean way to achieve
78 this.
79 */
80 virtual EvaluationResult
81 compute_result(EvaluationContext& eval_context) = 0;
82
83 void report_value_for_initial_state(const EvaluationResult& result) const;
84 void report_new_minimum_value(const EvaluationResult& result) const;
85
86 const std::string& get_description() const;
87 bool is_used_for_reporting_minima() const;
88 bool is_used_for_boosting() const;
89 bool is_used_for_counting_evaluations() const;
90
91 virtual bool does_cache_estimates() const;
92 virtual bool is_estimate_cached(const State& state) const;
93 /*
94 Calling get_cached_estimate is only allowed if an estimate for
95 the given state is cached, i.e., is_estimate_cached returns true.
96 */
97 virtual int get_cached_estimate(const State& state) const;
98};
99
100#endif