AI 24/25 Project Software
Documentation for the AI 24/25 course programming project software
Loading...
Searching...
No Matches
landmark_factory_zhu_givan.h
1#ifndef LANDMARKS_LANDMARK_FACTORY_ZHU_GIVAN_H
2#define LANDMARKS_LANDMARK_FACTORY_ZHU_GIVAN_H
3
4#include "downward/landmarks/landmark_factory_relaxation.h"
5
6#include "downward/utils/hash.h"
7
8#include <unordered_set>
9#include <utility>
10#include <vector>
11
12namespace landmarks {
13using lm_set = utils::HashSet<FactPair>;
14
15class LandmarkFactoryZhuGivan : public LandmarkFactoryRelaxation {
16 class plan_graph_node {
17 public:
18 lm_set labels;
19 inline bool reached() const
20 {
21 // NOTE: nodes are always labeled with itself,
22 // if they have been reached
23 return !labels.empty();
24 }
25 };
26
27 using PropositionLayer = std::vector<std::vector<plan_graph_node>>;
28
29 const bool use_orders;
30
31 // triggers[i][j] is a list of operators that could reach/change
32 // labels on some proposition, after proposition (i,j) has changed
33 std::vector<std::vector<std::vector<int>>> triggers;
34
35 void compute_triggers(const TaskProxy& task_proxy);
36
37 // Note: must include operators that only have conditional effects
38 std::vector<int> operators_without_preconditions;
39
40 bool operator_applicable(
41 const AxiomOrOperatorProxy& op,
42 const PropositionLayer& state) const;
43
44 bool operator_cond_effect_fires(
45 const EffectConditionsProxy& effect_conditions,
46 const PropositionLayer& layer) const;
47
48 // Apply operator and propagate labels to next layer. Returns set of
49 // propositions that:
50 // (a) have just been reached OR (b) had their labels changed in next
51 // proposition layer
52 lm_set apply_operator_and_propagate_labels(
53 const AxiomOrOperatorProxy& op,
54 const PropositionLayer& current,
55 PropositionLayer& next) const;
56
57 // Calculate the union of precondition labels of op, using the
58 // labels from current
59 lm_set union_of_precondition_labels(
60 const AxiomOrOperatorProxy& op,
61 const PropositionLayer& current) const;
62
63 // Calculate the union of precondition labels of a conditional effect,
64 // using the labels from current
65 lm_set union_of_condition_labels(
66 const EffectConditionsProxy& effect_conditions,
67 const PropositionLayer& current) const;
68
69 // Relaxed exploration, returns the last proposition layer
70 // (the fixpoint) with labels
71 PropositionLayer
72 build_relaxed_plan_graph_with_labels(const TaskProxy& task_proxy) const;
73
74 // Extract landmarks from last proposition layer and add them to the
75 // landmarks graph
76 void extract_landmarks(
77 const TaskProxy& task_proxy,
78 const PropositionLayer& last_prop_layer);
79
80 // Link operators to its propositions in trigger list.
81 void add_operator_to_triggers(const AxiomOrOperatorProxy& op);
82
83 virtual void generate_relaxed_landmarks(
84 const std::shared_ptr<AbstractTask>& task,
85 Exploration& exploration) override;
86
87public:
88 LandmarkFactoryZhuGivan(bool use_orders, utils::Verbosity verbosity);
89
90 virtual bool supports_conditional_effects() const override;
91};
92} // namespace landmarks
93
94#endif