AI 24/25 Project Software
Documentation for the AI 24/25 course programming project software
Loading...
Searching...
No Matches
causal_graph.h
1#ifndef PROBFD_TASK_UTILS_CAUSAL_GRAPH_H
2#define PROBFD_TASK_UTILS_CAUSAL_GRAPH_H
3
4#include <vector>
5
6namespace utils {
7class LogProxy;
8}
9
10namespace probfd {
11class ProbabilisticTask;
12class ProbabilisticTaskProxy;
13} // namespace probfd
14
15namespace probfd::causal_graph {
16
17using IntRelation = std::vector<std::vector<int>>;
18
19class ProbabilisticCausalGraph {
20 IntRelation pre_to_eff;
21 IntRelation eff_to_pre;
22 IntRelation eff_to_eff;
23
24 IntRelation successors;
25 IntRelation predecessors;
26
27 void
28 dump(const ProbabilisticTaskProxy& task_proxy, utils::LogProxy& log) const;
29
30public:
31 /* Use the factory function get_causal_graph to create causal graphs
32 to avoid creating more than one causal graph per AbstractTask. */
33 explicit ProbabilisticCausalGraph(const ProbabilisticTaskProxy& task_proxy);
34
35 /*
36 All below methods querying neighbors (of some sort or other) of
37 var guarantee that:
38 - the return vertex list is sorted
39 - var itself is not in the returned list
40
41 "Successors" and "predecessors" are w.r.t. the common definition
42 of causal graphs, which have pre->eff and eff->eff arcs.
43
44 Note that axioms are treated as operators in the causal graph,
45 i.e., their condition variables are treated as precondition
46 variables and the derived variable is treated as an effect
47 variable.
48
49 For effect conditions, we only add pre->eff arcs for the respective
50 conditional effect.
51 */
52
53 const std::vector<int>& get_pre_to_eff(int var) const
54 {
55 return pre_to_eff[var];
56 }
57
58 const std::vector<int>& get_eff_to_pre(int var) const
59 {
60 return eff_to_pre[var];
61 }
62
63 const std::vector<int>& get_eff_to_same_eff(int var) const
64 {
65 return eff_to_eff[var];
66 }
67
68 const std::vector<int>& get_eff_to_co_eff(int var) const
69 {
70 return eff_to_eff[var];
71 }
72
73 const std::vector<int>& get_successors(int var) const
74 {
75 return successors[var];
76 }
77
78 const std::vector<int>& get_predecessors(int var) const
79 {
80 return predecessors[var];
81 }
82
83 const std::vector<std::vector<int>>& get_arcs() const { return successors; }
84
85 const std::vector<std::vector<int>>& get_inverse_arcs() const
86 {
87 return predecessors;
88 }
89};
90
91/* Create or retrieve a causal graph from cache. If causal graphs are created
92 with this function, we build at most one causal graph per AbstractTask. */
93extern const ProbabilisticCausalGraph&
94get_causal_graph(const ProbabilisticTask* task);
95
96} // namespace probfd::causal_graph
97
98#endif // PROBFD_TASK_UTILS_CAUSAL_GRAPH_H
The top-level namespace of probabilistic Fast Downward.
Definition command_line.h:8