AI 24/25 Project Software
Documentation for the AI 24/25 course programming project software
Loading...
Searching...
No Matches
hm_heuristic.h
1#ifndef HEURISTICS_HM_HEURISTIC_H
2#define HEURISTICS_HM_HEURISTIC_H
3
4#include "downward/heuristic.h"
5
6#include <algorithm>
7#include <iostream>
8#include <map>
9#include <string>
10#include <vector>
11
12namespace hm_heuristic {
13/*
14 Haslum's h^m heuristic family ("critical path heuristics").
15
16 This is a very slow implementation and should not be used for
17 speed benchmarks.
18*/
19
20class HMHeuristic : public Heuristic {
21 using Tuple = std::vector<FactPair>;
22 // parameters
23 const int m;
24 const bool has_cond_effects;
25
26 const Tuple goals;
27
28 // h^m table
29 std::map<Tuple, int> hm_table;
30 bool was_updated;
31
32 // auxiliary methods
33 void init_hm_table(const Tuple& t);
34 void update_hm_table();
35 int eval(const Tuple& t) const;
36 int update_hm_entry(const Tuple& t, int val);
37 void extend_tuple(const Tuple& t, const OperatorProxy& op);
38
39 int check_tuple_in_tuple(const Tuple& tuple, const Tuple& big_tuple) const;
40
41 int get_operator_pre_value(const OperatorProxy& op, int var) const;
42 Tuple get_operator_pre(const OperatorProxy& op) const;
43 Tuple get_operator_eff(const OperatorProxy& op) const;
44 bool contradict_effect_of(const OperatorProxy& op, int var, int val) const;
45
46 void generate_all_tuples();
47 void generate_all_tuples_aux(int var, int sz, const Tuple& base);
48
49 void generate_all_partial_tuples(
50 const Tuple& base_tuple,
51 std::vector<Tuple>& res) const;
52 void generate_all_partial_tuples_aux(
53 const Tuple& base_tuple,
54 const Tuple& t,
55 int index,
56 int sz,
57 std::vector<Tuple>& res) const;
58
59 void dump_table() const;
60
61protected:
62 virtual int compute_heuristic(const State& ancestor_state) override;
63
64public:
65 HMHeuristic(
66 int m,
67 const std::shared_ptr<AbstractTask>& transform,
68 bool cache_estimates,
69 const std::string& description,
70 utils::Verbosity verbosity);
71
72 virtual bool dead_ends_are_reliable() const override;
73};
74} // namespace hm_heuristic
75
76#endif