AI 24/25 Project Software
Documentation for the AI 24/25 course programming project software
Loading...
Searching...
No Matches
delete_relaxation_rr_constraints.h
1#ifndef OPERATOR_COUNTING_DELETE_RELAXATION_RR_CONSTRAINTS_H
2#define OPERATOR_COUNTING_DELETE_RELAXATION_RR_CONSTRAINTS_H
3
4#include "downward/operator_counting/constraint_generator.h"
5
6#include "downward/task_proxy.h"
7#include "downward/utils/hash.h"
8
9#include <memory>
10#include <vector>
11
12namespace lp {
13class LPConstraint;
14struct LPVariable;
15} // namespace lp
16
17namespace operator_counting {
18class VEGraph;
19using LPConstraints = named_vector::NamedVector<lp::LPConstraint>;
20using LPVariables = named_vector::NamedVector<lp::LPVariable>;
21
22enum class AcyclicityType { TIME_LABELS, VERTEX_ELIMINATION, NONE };
23
24class DeleteRelaxationRRConstraints : public ConstraintGenerator {
25 struct LPVariableIDs {
26 /*
27 The variables f_p in the paper represent if a fact p is reached by the
28 relaxed plan encoded in the LP solution. We only store the offset for
29 each variable (LP variables for different facts of the same variable
30 are consecutive).
31 */
32 std::vector<int> fp_offsets;
33
34 /*
35 The variables f_{p,a} in the paper represent if an action a is used to
36 achieve a fact p in the relaxed plan encoded in the LP solution. The
37 variable is only needed for combinations of p and a where p is an
38 effect of a. We store one hash map for each operator a that maps facts
39 p to LP variable IDs.
40 */
41 std::vector<utils::HashMap<FactPair, int>> fpa_ids;
42
43 /*
44 The variable e_{i,j} in the paper is used as part of the vertex
45 elimination method. It represents that fact p_i is used before fact
46 p_j. Not all pairs of facts have to be ordered, the vertex elimination
47 graph ensures that enough variables are created to exclude all cycles.
48 */
49 utils::HashMap<std::pair<FactPair, FactPair>, int> e_ids;
50
51 /*
52 The variable t_p in the paper is used as part of the time labels
53 method. It represents the time at which fact p is first made true.
54 We store the offsets here, analogous to fp.
55 */
56 std::vector<int> t_offsets;
57
58 int id_of_fp(FactPair f) const;
59 int id_of_fpa(FactPair f, const OperatorProxy& op) const;
60 int id_of_e(std::pair<FactPair, FactPair> edge) const;
61 int has_e(std::pair<FactPair, FactPair> edge) const;
62 int id_of_t(FactPair f) const;
63 };
64
65 AcyclicityType acyclicity_type;
66 bool use_integer_vars;
67
68 /*
69 Store offsets to identify Constraints (2) in the paper. We need to
70 reference them when updating constraints for a given state. The constraint
71 for a fact with variable v and value d has ID (constraint_offsets[v] + d).
72 */
73 std::vector<int> constraint_offsets;
74
75 /* The state that is currently used for setting the bounds. Remembering
76 this makes it faster to unset the bounds when the state changes. */
77 std::vector<FactPair> last_state;
78
79 int get_constraint_id(FactPair f) const;
80
81 LPVariableIDs create_auxiliary_variables(
82 const TaskProxy& task_proxy,
83 LPVariables& variables) const;
84 void create_auxiliary_variables_ve(
85 const TaskProxy& task_proxy,
86 const VEGraph& ve_graph,
87 LPVariables& variables,
88 LPVariableIDs& lp_var_ids) const;
89 void create_auxiliary_variables_tl(
90 const TaskProxy& task_proxy,
91 LPVariables& variables,
92 LPVariableIDs& lp_var_ids) const;
93 void create_constraints(
94 const TaskProxy& task_proxy,
95 const LPVariableIDs& lp_var_ids,
96 lp::LinearProgram& lp);
97 void create_constraints_ve(
98 const TaskProxy& task_proxy,
99 const VEGraph& ve_graph,
100 const LPVariableIDs& lp_var_ids,
101 lp::LinearProgram& lp);
102 void create_constraints_tl(
103 const TaskProxy& task_proxy,
104 const LPVariableIDs& lp_var_ids,
105 lp::LinearProgram& lp);
106
107public:
108 DeleteRelaxationRRConstraints(
109 AcyclicityType acyclicity_type,
110 bool use_integer_vars);
111
112 virtual void initialize_constraints(
113 const std::shared_ptr<AbstractTask>& task,
114 lp::LinearProgram& lp) override;
115 virtual bool
116 update_constraints(const State& state, lp::LPSolver& lp_solver) override;
117};
118} // namespace operator_counting
119
120#endif