AI 24/25 Project Software
Documentation for the AI 24/25 course programming project software
Loading...
Searching...
No Matches
merge_and_shrink_representation.h
1#ifndef MERGE_AND_SHRINK_MERGE_AND_SHRINK_REPRESENTATION_H
2#define MERGE_AND_SHRINK_MERGE_AND_SHRINK_REPRESENTATION_H
3
4#include <memory>
5#include <vector>
6
7class State;
8
9namespace utils {
10class LogProxy;
11}
12
13namespace merge_and_shrink {
14class Distances;
15class MergeAndShrinkRepresentation {
16protected:
17 int domain_size;
18
19public:
20 explicit MergeAndShrinkRepresentation(int domain_size);
21 virtual ~MergeAndShrinkRepresentation() = 0;
22
23 int get_domain_size() const;
24
25 // Store distances instead of abstract state numbers.
26 virtual void set_distances(const Distances &) = 0;
27 virtual void apply_abstraction_to_lookup_table(
28 const std::vector<int> &abstraction_mapping) = 0;
29 /*
30 Return the value that state is mapped to. This is either an abstract
31 state (if set_distances has not been called) or a distance (if it has).
32 If the represented function is not total, the returned value is DEAD_END
33 if the abstract state is PRUNED_STATE or if the (distance) value is INF.
34 */
35 virtual int get_value(const State &state) const = 0;
36 /* Return true iff the represented function is total, i.e., does not map
37 to PRUNED_STATE. */
38 virtual bool is_total() const = 0;
39 virtual void dump(utils::LogProxy &log) const = 0;
40};
41
42
43class MergeAndShrinkRepresentationLeaf : public MergeAndShrinkRepresentation {
44 const int var_id;
45
46 std::vector<int> lookup_table;
47public:
48 MergeAndShrinkRepresentationLeaf(int var_id, int domain_size);
49 virtual ~MergeAndShrinkRepresentationLeaf() = default;
50
51 virtual void set_distances(const Distances &) override;
52 virtual void apply_abstraction_to_lookup_table(
53 const std::vector<int> &abstraction_mapping) override;
54 virtual int get_value(const State &state) const override;
55 virtual bool is_total() const override;
56 virtual void dump(utils::LogProxy &log) const override;
57};
58
59
60class MergeAndShrinkRepresentationMerge : public MergeAndShrinkRepresentation {
61 std::unique_ptr<MergeAndShrinkRepresentation> left_child;
62 std::unique_ptr<MergeAndShrinkRepresentation> right_child;
63 std::vector<std::vector<int>> lookup_table;
64public:
65 MergeAndShrinkRepresentationMerge(
66 std::unique_ptr<MergeAndShrinkRepresentation> left_child,
67 std::unique_ptr<MergeAndShrinkRepresentation> right_child);
68 virtual ~MergeAndShrinkRepresentationMerge() = default;
69
70 virtual void set_distances(const Distances &distances) override;
71 virtual void apply_abstraction_to_lookup_table(
72 const std::vector<int> &abstraction_mapping) override;
73 virtual int get_value(const State &state) const override;
74 virtual bool is_total() const override;
75 virtual void dump(utils::LogProxy &log) const override;
76};
77}
78
79#endif