AI 24/25 Project Software
Documentation for the AI 24/25 course programming project software
Loading...
Searching...
No Matches
refinement_hierarchy.h
1#ifndef CEGAR_REFINEMENT_HIERARCHY_H
2#define CEGAR_REFINEMENT_HIERARCHY_H
3
4#include "downward/cartesian_abstractions/types.h"
5
6#include <cassert>
7#include <memory>
8#include <ostream>
9#include <utility>
10#include <vector>
11
12class PlanningTask;
13class State;
14
15namespace cartesian_abstractions {
16class Node;
17
18/*
19 This class stores the refinement hierarchy of a Cartesian
20 abstraction. The hierarchy forms a DAG with inner nodes for each
21 split and leaf nodes for the abstract states.
22
23 It is used for efficient lookup of abstract states during search.
24
25 Inner nodes correspond to abstract states that have been split (or
26 helper nodes, see below). Leaf nodes correspond to the current
27 (unsplit) states in an abstraction. The use of helper nodes makes
28 this structure a directed acyclic graph (instead of a tree).
29*/
30class RefinementHierarchy {
31 std::shared_ptr<PlanningTask> task;
32 std::vector<Node> nodes;
33
34 NodeID add_node(int state_id);
35 NodeID get_node_id(const State& state) const;
36
37public:
38 explicit RefinementHierarchy(const std::shared_ptr<PlanningTask>& task);
39
40 /*
41 Update the split tree for the new split. Additionally to the left
42 and right child nodes add |values|-1 helper nodes that all have
43 the right child as their right child and the next helper node as
44 their left child.
45 */
46 std::pair<NodeID, NodeID> split(
47 NodeID node_id,
48 int var,
49 const std::vector<int>& values,
50 int left_state_id,
51 int right_state_id);
52
53 int get_abstract_state_id(const State& state) const;
54};
55
56class Node {
57 /*
58 While right_child is always the node of a (possibly split)
59 abstract state, left_child may be a helper node. We add helper
60 nodes to the hierarchy to allow for efficient lookup in case more
61 than one fact is split off a state.
62 */
63 NodeID left_child;
64 NodeID right_child;
65
66 /* Before splitting the corresponding state for var and value, both
67 members hold UNDEFINED. */
68 int var;
69 int value;
70
71 // When splitting the corresponding state, we change this value to
72 // UNDEFINED.
73 int state_id;
74
75 bool information_is_valid() const;
76
77public:
78 explicit Node(int state_id);
79
80 bool is_split() const;
81
82 void split(int var, int value, NodeID left_child, NodeID right_child);
83
84 int get_var() const
85 {
86 assert(is_split());
87 return var;
88 }
89
90 NodeID get_child(int value) const
91 {
92 assert(is_split());
93 if (value == this->value) return right_child;
94 return left_child;
95 }
96
97 int get_state_id() const
98 {
99 assert(!is_split());
100 return state_id;
101 }
102
103 friend std::ostream& operator<<(std::ostream& os, const Node& node);
104};
105} // namespace cartesian_abstractions
106
107#endif