AI 24/25 Project Software
Documentation for the AI 24/25 course programming project software
Loading...
Searching...
No Matches
end_component_decomposition.h
1#ifndef PROBFD_PREPROCESSING_END_COMPONENT_DECOMPOSITION_H
2#define PROBFD_PREPROCESSING_END_COMPONENT_DECOMPOSITION_H
3
4#include "probfd/quotients/quotient_system.h"
5
6#include "probfd/storage/per_state_storage.h"
7
8#include "probfd/evaluator.h"
9#include "probfd/mdp.h"
10#include "probfd/type_traits.h"
11
12#include <deque>
13#include <limits>
14#include <memory>
15#include <ostream>
16#include <vector>
17
18// Forward Declarations
19namespace utils {
20class CountdownTimer;
21}
22
25
30 unsigned long long goals = 0;
31 unsigned long long terminals = 0;
32 unsigned long long selfloops = 0;
33
34 unsigned long long sccs1 = 0;
35 unsigned long long sccsk = 0;
36 unsigned long long sccs1_dead = 0;
37 unsigned long long sccsk_dead = 0;
38
39 unsigned long long ec1 = 0;
40 unsigned long long eck = 0;
41
42 unsigned long long ec_transitions = 0;
43
44 unsigned long long recursions = 0;
45
46 utils::Timer time;
47
48 void print(std::ostream& out) const;
49};
50
85template <typename State, typename Action>
89 using QSystem = quotients::QuotientSystem<State, Action>;
90
91 struct StateInfo {
92 enum { NEW, ONSTACK, CLOSED };
93
94 static constexpr uint32_t UNDEF =
95 std::numeric_limits<uint32_t>::max() >> 2;
96
97 unsigned explored : 1 = 0;
98 unsigned expandable_goal : 1 = 0; // non-terminal goal?
99 unsigned stackid : 30 = UNDEF;
100
101 [[nodiscard]]
102 bool onstack() const;
103 auto get_status() const;
104 };
105
106 struct ExpansionInfo {
107 // Tarjan's SCC algorithm: stack id and lowlink
108 const unsigned stck;
109 unsigned lstck;
110
111 // whether the transition has non-zero cost or can leave the scc
112 bool nz_or_leaves_scc;
113
114 // recursive decomposition flag
115 // Recursively decompose the SCC if there is a zero-cost transition
116 // in it that can leave and remain in the scc.
117 bool recurse = false;
118
119 std::vector<Action> aops;
120 std::vector<std::vector<StateID>> successors;
121
122 // Used in decomposition recursion
123 ExpansionInfo(
124 unsigned stck,
125 std::vector<Action> aops,
126 std::vector<std::vector<StateID>> successors);
127
128 // Used in root iteration
129 ExpansionInfo(
130 unsigned stck,
131 std::vector<Action> aops,
132 std::vector<std::vector<StateID>> successors,
133 MDPType& mdp);
134
135 // Used in decomposition recursion
136 bool next_action(std::nullptr_t);
137
138 // Used in root iteration
139 bool next_action(MDPType& mdp);
140
141 bool next_successor();
142
143 StateID get_current_successor();
144 Action& get_current_action();
145 };
146
147 struct StackInfo;
148
149 const bool expand_goals_;
150
151 storage::PerStateStorage<StateInfo> state_infos_;
152 std::deque<ExpansionInfo> expansion_queue_;
153 std::vector<StackInfo> stack_;
154
155 ECDStatistics stats_;
156
157public:
158 explicit EndComponentDecomposition(bool expand_goals);
159
167 std::unique_ptr<QSystem> build_quotient_system(
168 MDPType& mdp,
169 const EvaluatorType* pruning_function,
170 param_type<State> initial_state,
171 double max_time = std::numeric_limits<double>::infinity());
172
173 void print_statistics(std::ostream& out) const;
174
175 [[nodiscard]]
176 ECDStatistics get_statistics() const;
177
178private:
179 // Used in root iteration
180 bool push(
181 StateID state_id,
182 StateInfo& state_info,
183 MDPType& mdp,
184 const EvaluatorType* pruning_function);
185
186 // Used in decomposition recursion
187 bool push(StateID state_id, StateInfo& info);
188
189 void find_and_decompose_sccs(
190 QSystem& sys,
191 unsigned limit,
192 utils::CountdownTimer& timer,
193 auto&... mdp_and_h);
194
195 bool push_successor(
196 ExpansionInfo& e,
197 StackInfo& s,
198 utils::CountdownTimer& timer,
199 auto&... mdp_and_h);
200
201 template <bool RootIteration>
202 void scc_found(
203 QSystem& sys,
204 ExpansionInfo& e,
205 StackInfo& s,
206 utils::CountdownTimer& timer);
207
208 void decompose(QSystem& sys, unsigned start, utils::CountdownTimer& timer);
209};
210
211} // namespace probfd::preprocessing
212
213#define GUARD_INCLUDE_PROBFD_PREPROCESSING_END_COMPONENT_DECOMPOSITION_H
214#include "probfd/preprocessing/end_component_decomposition_impl.h"
215#undef GUARD_INCLUDE_PROBFD_PREPROCESSING_END_COMPONENT_DECOMPOSITION_H
216
217#endif // PROBFD_PREPROCESSING_END_COMPONENT_DECOMPOSITION_H
A builder class that implements end component decomposition.
Definition end_component_decomposition.h:86
std::unique_ptr< QSystem > build_quotient_system(MDPType &mdp, const EvaluatorType *pruning_function, param_type< State > initial_state, double max_time=std::numeric_limits< double >::infinity())
Build the quotient of the MDP with respect to the maximal end components.
Definition end_component_decomposition_impl.h:155
This namespace contains preprocessing algorithms for SSPs.
Definition end_component_decomposition.h:24
typename std::conditional_t< is_cheap_to_copy_v< T >, T, const T & > param_type
Alias template defining the best way to pass a parameter of a given type.
Definition type_traits.h:25
A StateID represents a state within a StateIDMap. Just like Fast Downward's StateID type,...
Definition types.h:22
Contains printable statistics for the end component decomposition.
Definition end_component_decomposition.h:29