AI 24/25 Project Software
Documentation for the AI 24/25 course programming project software
Loading...
Searching...
No Matches
task_properties.h
1#ifndef TASK_UTILS_TASK_PROPERTIES_H
2#define TASK_UTILS_TASK_PROPERTIES_H
3
4#include "downward/per_task_information.h"
5#include "downward/task_proxy.h"
6
7#include "downward/algorithms/int_packer.h"
8
9namespace task_properties {
10inline bool is_applicable(const AxiomOrOperatorProxy& op, const State& state)
11{
12 for (FactProxy precondition : op.get_preconditions()) {
13 if (state[precondition.get_variable()] != precondition) return false;
14 }
15 return true;
16}
17
18inline bool is_applicable(const PartialOperatorProxy& op, const State& state)
19{
20 for (FactProxy precondition : op.get_preconditions()) {
21 if (state[precondition.get_variable()] != precondition) return false;
22 }
23 return true;
24}
25
26inline bool is_goal_state(const PlanningTaskProxy& task, const State& state)
27{
28 for (FactProxy goal : task.get_goals()) {
29 if (state[goal.get_variable()] != goal) return false;
30 }
31 return true;
32}
33
34/*
35 Return true iff all operators have cost 1.
36
37 Runtime: O(n), where n is the number of operators.
38*/
39extern bool is_unit_cost(const TaskProxy& task);
40
41// Runtime: O(1)
42extern bool has_axioms(const PlanningTaskProxy& task);
43
44/*
45 Report an error and exit with ExitCode::UNSUPPORTED if the task has axioms.
46 Runtime: O(1)
47*/
48extern void verify_no_axioms(const PlanningTaskProxy& task);
49
50// Runtime: O(n), where n is the number of operators.
51extern bool has_conditional_effects(const TaskProxy& task);
52
53/*
54 Report an error and exit with ExitCode::UNSUPPORTED if the task has
55 conditional effects.
56 Runtime: O(n), where n is the number of operators.
57*/
58extern void verify_no_conditional_effects(const TaskProxy& task);
59
60extern std::vector<int> get_operator_costs(const TaskProxy& task_proxy);
61extern double get_average_operator_cost(const TaskProxy& task_proxy);
62extern int get_min_operator_cost(const TaskProxy& task_proxy);
63
64/*
65 Return the number of facts of the task.
66 Runtime: O(n), where n is the number of state variables.
67*/
68extern int get_num_facts(const PlanningTaskProxy& task_proxy);
69
70/*
71 Return the total number of effects of the task, including the
72 effects of axioms.
73 Runtime: O(n), where n is the number of operators and axioms.
74*/
75extern int get_num_total_effects(const TaskProxy& task_proxy);
76
77template <class FactProxyCollection>
78std::vector<FactPair> get_fact_pairs(const FactProxyCollection& facts)
79{
80 std::vector<FactPair> fact_pairs;
81 fact_pairs.reserve(facts.size());
82 for (FactProxy fact : facts) {
83 fact_pairs.push_back(fact.get_pair());
84 }
85 return fact_pairs;
86}
87
88extern void print_variable_statistics(const PlanningTaskProxy& task_proxy);
89extern void dump_pddl(const State& state);
90extern void dump_fdr(const State& state);
91extern void dump_goals(const GoalsProxy& goals);
92extern void dump_task(const TaskProxy& task_proxy);
93
94extern PerTaskInformation<int_packer::IntPacker> g_state_packers;
95} // namespace task_properties
96
97#endif