AI 24/25 Project Software
Documentation for the AI 24/25 course programming project software
Loading...
Searching...
No Matches
stubborn_sets.h
1#ifndef PRUNING_STUBBORN_SETS_H
2#define PRUNING_STUBBORN_SETS_H
3
4#include "downward/pruning_method.h"
5
6#include "downward/task_proxy.h"
7
8namespace stubborn_sets {
9inline FactPair find_unsatisfied_condition(
10 const std::vector<FactPair>& conditions,
11 const State& state);
12
13class StubbornSets : public PruningMethod {
14 void compute_sorted_operators(const TaskProxy& task_proxy);
15 void compute_achievers(const TaskProxy& task_proxy);
16 virtual void
17 prune(const State& state, std::vector<OperatorID>& op_ids) override;
18
19protected:
20 /*
21 We copy some parts of the task here, so we can avoid the more expensive
22 access through the task interface during the search.
23 */
24 int num_operators;
25 std::vector<std::vector<FactPair>> sorted_op_preconditions;
26 std::vector<std::vector<FactPair>> sorted_op_effects;
27 std::vector<FactPair> sorted_goals;
28
29 /* achievers[var][value] contains all operator indices of
30 operators that achieve the fact (var, value). */
31 std::vector<std::vector<std::vector<int>>> achievers;
32
33 /* stubborn[op_no] is true iff the operator with operator index
34 op_no is contained in the stubborn set */
35 std::vector<bool> stubborn;
36
37 /*
38 Return the first unsatified precondition,
39 or FactPair::no_fact if there is none.
40
41 Note that we use a sorted list of preconditions here intentionally.
42 The ICAPS paper "Efficient Stubborn Sets: Generalized Algorithms and
43 Selection Strategies" (Wehrle and Helmert, 2014) contains a limited study
44 of this (see section "Strategies for Choosing Unsatisfied Conditions" and
45 especially subsection "Static Variable Orderings"). One of the outcomes
46 was the sorted version ("static orders/FD" in Table 1 of the paper)
47 is dramatically better than choosing preconditions and goals randomly
48 every time ("dynamic orders/random" in Table 1).
49
50 The code also intentionally uses the "causal graph order" of variables
51 rather than an arbitrary variable order. (However, so far, there is no
52 experimental evidence that this is a particularly good order.)
53 */
54 FactPair find_unsatisfied_precondition(int op_no, const State& state) const
55 {
56 return find_unsatisfied_condition(
57 sorted_op_preconditions[op_no],
58 state);
59 }
60
61 virtual void compute_stubborn_set(const State& state) = 0;
62
63public:
64 explicit StubbornSets(utils::Verbosity verbosity);
65 virtual void initialize(const std::shared_ptr<AbstractTask>& task) override;
66};
67
68// Return the first unsatified condition, or FactPair::no_fact if there is none.
69inline FactPair find_unsatisfied_condition(
70 const std::vector<FactPair>& conditions,
71 const State& state)
72{
73 for (const FactPair& condition : conditions) {
74 if (state[condition.var].get_value() != condition.value)
75 return condition;
76 }
77 return FactPair::no_fact;
78}
79} // namespace stubborn_sets
80
81#endif