28 unsigned long long iterations = 0;
29 unsigned long long traps = 0;
31#if defined(EXPENSIVE_STATISTICS)
32 utils::Timer heuristic_search = utils::Timer(
true);
33 utils::Timer trap_identification = utils::Timer(
true);
34 utils::Timer trap_removal = utils::Timer(
true);
37 void print(std::ostream& out)
const;
40struct TarjanStateInformation {
41 static constexpr unsigned UNDEF = std::numeric_limits<unsigned int>::max();
43 unsigned stack_index = UNDEF;
44 unsigned lowlink = UNDEF;
47 bool is_explored()
const
49 return lowlink != UNDEF;
53 bool is_on_stack()
const
55 return stack_index != UNDEF;
58 void open(
const unsigned x)
64 void close() { stack_index = UNDEF; }
67struct ExplorationInfo {
68 ExplorationInfo(
StateID state_id, std::vector<StateID> successors)
70 , successors(std::move(successors))
75 std::vector<StateID> successors;
79template <
typename QAction>
82 std::vector<QAction> aops;
85 friend auto& get(StackInfo& info)
87 if constexpr (i == 0)
return info.state_id;
88 if constexpr (i == 1)
return info.aops;
92 friend const auto& get(
const StackInfo& info)
94 if constexpr (i == 0)
return info.state_id;
95 if constexpr (i == 1)
return info.aops;
128 typename GreedyGraphGenerator>
130 using Base =
typename FRET::MDPAlgorithm;
132 using PolicyType =
typename Base::PolicyType;
133 using MDPType =
typename Base::MDPType;
134 using EvaluatorType =
typename Base::EvaluatorType;
136 using QuotientSystem = quotients::QuotientSystem<State, Action>;
137 using QState = quotients::QuotientState<State, Action>;
138 using QAction = quotients::QuotientAction<Action>;
139 using QHeuristicSearchAlgorithm = heuristic_search::
140 FRETHeuristicSearchAlgorithm<QState, QAction, StateInfoT>;
143 using StackInfo = internal::StackInfo<QAction>;
146 const std::shared_ptr<QHeuristicSearchAlgorithm> base_algorithm_;
148 internal::Statistics statistics_;
151 explicit FRET(std::shared_ptr<QHeuristicSearchAlgorithm> algorithm);
153 std::unique_ptr<PolicyType> compute_policy(
155 EvaluatorType& heuristic,
158 double max_time)
override;
162 EvaluatorType& heuristic,
165 double max_time)
override;
171 QuotientSystem& quotient,
172 QEvaluator& heuristic,
178 QuotientSystem& quotient,
179 QEvaluator& heuristic,
182 utils::CountdownTimer& timer);
184 bool find_and_remove_traps(
185 QuotientSystem& quotient,
187 utils::CountdownTimer& timer);
190 QuotientSystem& quotient,
191 std::deque<internal::ExplorationInfo>& queue,
192 std::deque<StackInfo>& stack,
193 internal::TarjanStateInformation& info,
195 unsigned int& unexpanded);
198template <
typename State,
typename Action,
typename StateInfoT>
200 using QuotientSystem = quotients::QuotientSystem<State, Action>;
201 using QState = quotients::QuotientState<State, Action>;
202 using QAction = quotients::QuotientAction<Action>;
204 using QHeuristicSearchAlgorithm =
207 using AlgorithmValueType =
208 typename QHeuristicSearchAlgorithm::AlgorithmValueType;
212 std::unordered_set<StateID> ids_;
213 std::vector<Transition<QAction>> opt_transitions_;
214 std::vector<AlgorithmValueType> q_values;
218 QuotientSystem& quotient,
219 QHeuristicSearchAlgorithm& base_algorithm,
221 std::vector<QAction>& aops,
222 std::vector<StateID>& successors);
225template <
typename State,
typename Action,
typename StateInfoT>
227 using QuotientSystem = quotients::QuotientSystem<State, Action>;
228 using QState = quotients::QuotientState<State, Action>;
229 using QAction = quotients::QuotientAction<Action>;
230 using QHeuristicSearchAlgorithm =
239 QuotientSystem& quotient,
240 QHeuristicSearchAlgorithm& base_algorithm,
242 std::vector<QAction>& aops,
243 std::vector<StateID>& successors);
254template <
typename State,
typename Action,
typename StateInfoT>
266template <
typename State,
typename Action,
typename StateInfoT>