AI 24/25 Project Software
Documentation for the AI 24/25 course programming project software
Loading...
Searching...
No Matches
landmark_factory_h_m.h
1#ifndef LANDMARKS_LANDMARK_FACTORY_H_M_H
2#define LANDMARKS_LANDMARK_FACTORY_H_M_H
3
4#include "downward/landmarks/landmark_factory.h"
5
6namespace landmarks {
7using FluentSet = std::vector<FactPair>;
8
9std::ostream& operator<<(std::ostream& os, const FluentSet& fs);
10
11struct FluentSetComparer {
12 bool operator()(const FluentSet& fs1, const FluentSet& fs2) const
13 {
14 if (fs1.size() != fs2.size()) {
15 return fs1.size() < fs2.size();
16 }
17 for (size_t i = 0; i < fs1.size(); ++i) {
18 if (fs1[i] != fs2[i]) return fs1[i] < fs2[i];
19 }
20 return false;
21 }
22};
23
24// an operator in P_m. Corresponds to an operator from the original problem,
25// as well as a set of conditional effects that correspond to noops
26struct PMOp {
27 std::vector<int> pc;
28 std::vector<int> eff;
29 // pc separated from effect by a value of -1
30 std::vector<std::vector<int>> cond_noops;
31 int index;
32};
33
34// represents a fluent in the P_m problem
35struct HMEntry {
36 // propositions that belong to this set
37 FluentSet fluents;
38 // -1 -> current cost infinite
39 // 0 -> present in initial state
40 int level;
41
42 std::list<int> landmarks;
43 std::list<int>
44 necessary; // greedy necessary landmarks, disjoint from landmarks
45
46 std::list<int> first_achievers;
47
48 // first int = op index, second int conditional noop effect
49 // -1 for op itself
50 std::vector<FactPair> pc_for;
51
52 HMEntry()
53 : level(-1)
54 {
55 }
56};
57
58using FluentSetToIntMap = std::map<FluentSet, int, FluentSetComparer>;
59
60class LandmarkFactoryHM : public LandmarkFactory {
61 using TriggerSet = std::unordered_map<int, std::set<int>>;
62
63 virtual void
64 generate_landmarks(const std::shared_ptr<AbstractTask>& task) override;
65
66 void compute_h_m_landmarks(const TaskProxy& task_proxy);
67 void compute_noop_landmarks(
68 int op_index,
69 int noop_index,
70 std::list<int> const& local_landmarks,
71 std::list<int> const& local_necessary,
72 int level,
73 TriggerSet& next_trigger);
74
75 void propagate_pm_fact(
76 int factindex,
77 bool newly_discovered,
78 TriggerSet& trigger);
79
80 bool possible_noop_set(
81 const VariablesProxy& variables,
82 const FluentSet& fs1,
83 const FluentSet& fs2);
84 void build_pm_ops(const TaskProxy& task_proxy);
85 bool interesting(
86 const VariablesProxy& variables,
87 const FactPair& fact1,
88 const FactPair& fact2) const;
89
90 void postprocess(const TaskProxy& task_proxy);
91
92 void discard_conjunctive_landmarks();
93
94 void calc_achievers(const TaskProxy& task_proxy);
95
96 void add_lm_node(int set_index, bool goal = false);
97
98 void initialize(const TaskProxy& task_proxy);
99 void free_unneeded_memory();
100
101 void
102 print_fluentset(const VariablesProxy& variables, const FluentSet& fs) const;
103 void print_pm_op(const VariablesProxy& variables, const PMOp& op) const;
104
105 const int m_;
106 const bool conjunctive_landmarks;
107 const bool use_orders;
108
109 std::map<int, LandmarkNode*> lm_node_table_;
110
111 std::vector<HMEntry> h_m_table_;
112 std::vector<PMOp> pm_ops_;
113 // maps each <m set to an int
114 FluentSetToIntMap set_indices_;
115 // first is unsat pcs for operator
116 // second is unsat pcs for conditional noops
117 std::vector<std::pair<int, std::vector<int>>> unsat_pc_count_;
118
119 void get_m_sets_(
120 const VariablesProxy& variables,
121 int m,
122 int num_included,
123 int current_var,
124 FluentSet& current,
125 std::vector<FluentSet>& subsets);
126
127 void get_m_sets_of_set(
128 const VariablesProxy& variables,
129 int m,
130 int num_included,
131 int current_var_index,
132 FluentSet& current,
133 std::vector<FluentSet>& subsets,
134 const FluentSet& superset);
135
136 void get_split_m_sets(
137 const VariablesProxy& variables,
138 int m,
139 int ss1_num_included,
140 int ss2_num_included,
141 int ss1_var_index,
142 int ss2_var_index,
143 FluentSet& current,
144 std::vector<FluentSet>& subsets,
145 const FluentSet& superset1,
146 const FluentSet& superset2);
147
148 void get_m_sets(
149 const VariablesProxy& variables,
150 int m,
151 std::vector<FluentSet>& subsets);
152
153 void get_m_sets(
154 const VariablesProxy& variables,
155 int m,
156 std::vector<FluentSet>& subsets,
157 const FluentSet& superset);
158
159 void get_m_sets(
160 const VariablesProxy& variables,
161 int m,
162 std::vector<FluentSet>& subsets,
163 const State& state);
164
165 void get_split_m_sets(
166 const VariablesProxy& variables,
167 int m,
168 std::vector<FluentSet>& subsets,
169 const FluentSet& superset1,
170 const FluentSet& superset2);
171 void
172 print_proposition(const VariablesProxy& variables, const FactPair& fluent)
173 const;
174
175public:
176 LandmarkFactoryHM(
177 int m,
178 bool conjunctive_landmarks,
179 bool use_orders,
180 utils::Verbosity verbosity);
181
182 virtual bool supports_conditional_effects() const override;
183};
184} // namespace landmarks
185
186#endif