AI 24/25 Project Software
Documentation for the AI 24/25 course programming project software
Loading...
Searching...
No Matches
cg_cache.h
1#ifndef HEURISTICS_CG_CACHE_H
2#define HEURISTICS_CG_CACHE_H
3
4#include "downward/task_proxy.h"
5
6#include <vector>
7
8namespace domain_transition_graph {
9struct ValueTransitionLabel;
10}
11
12namespace utils {
13class LogProxy;
14}
15
16namespace cg_heuristic {
17class CGCache {
18 TaskProxy task_proxy;
19 std::vector<std::vector<int>> cache;
20 std::vector<std::vector<domain_transition_graph::ValueTransitionLabel*>>
21 helpful_transition_cache;
22 std::vector<std::vector<int>> depends_on;
23
24 int get_index(int var, const State& state, int from_val, int to_val) const;
25 int compute_required_cache_size(
26 int var_id,
27 const std::vector<int>& depends_on,
28 int max_cache_size) const;
29
30public:
31 static const int NOT_COMPUTED = -2;
32
33 CGCache(
34 const TaskProxy& task_proxy,
35 int max_cache_size,
36 utils::LogProxy& log);
37
38 bool is_cached(int var) const { return !cache[var].empty(); }
39
40 int lookup(int var, const State& state, int from_val, int to_val) const
41 {
42 return cache[var][get_index(var, state, from_val, to_val)];
43 }
44
45 void store(int var, const State& state, int from_val, int to_val, int cost)
46 {
47 cache[var][get_index(var, state, from_val, to_val)] = cost;
48 }
49
50 domain_transition_graph::ValueTransitionLabel* lookup_helpful_transition(
51 int var,
52 const State& state,
53 int from_val,
54 int to_val) const
55 {
56 int index = get_index(var, state, from_val, to_val);
57 return helpful_transition_cache[var][index];
58 }
59
60 void store_helpful_transition(
61 int var,
62 const State& state,
63 int from_val,
64 int to_val,
65 domain_transition_graph::ValueTransitionLabel* helpful_transition)
66 {
67 int index = get_index(var, state, from_val, to_val);
68 helpful_transition_cache[var][index] = helpful_transition;
69 }
70};
71} // namespace cg_heuristic
72
73#endif