1#ifndef PROBFD_ALGORITHMS_EXHAUSTIVE_DFS_H
2#define PROBFD_ALGORITHMS_EXHAUSTIVE_DFS_H
4#include "probfd/algorithms/state_properties.h"
6#include "probfd/algorithms/types.h"
8#include "probfd/storage/per_state_storage.h"
10#include "probfd/distribution.h"
11#include "probfd/mdp_algorithm.h"
12#include "probfd/progress_report.h"
19template <
typename,
typename>
20class TransitionSorter;
27 unsigned long long expanded = 0;
28 unsigned long long evaluations = 0;
29 unsigned long long evaluated = 0;
30 unsigned long long goal_states = 0;
31 unsigned long long transitions = 0;
32 unsigned long long dead_ends = 0;
33 unsigned long long terminal = 0;
34 unsigned long long self_loop = 0;
36 unsigned long long value_updates = 0;
37 unsigned long long backtracks = 0;
38 unsigned long long sccs = 0;
39 unsigned long long dead_end_sccs = 0;
40 unsigned long long pruned_dead_end_sccs = 0;
41 unsigned long long summed_dead_end_scc_sizes = 0;
43 void print(std::ostream& out)
const;
46struct ExpansionInformation {
47 explicit ExpansionInformation(
unsigned stack_index)
48 : stack_index(stack_index)
52 std::vector<Distribution<StateID>> successors;
53 Distribution<StateID>::const_iterator succ;
56 bool all_successors_are_dead =
true;
57 bool all_successors_marked_dead =
true;
59 void update_successors_dead(
bool successors_dead)
61 all_successors_are_dead = all_successors_are_dead && successors_dead;
71struct StackInformation {
72 explicit StackInformation(
StateID state_ref)
73 : state_ref(state_ref)
78 std::vector<SCCTransition> successors;
82template <
bool UseInterval>
83struct SearchNodeInformation {
84 static constexpr uint8_t NEW = 0;
85 static constexpr uint8_t CLOSED = 1;
86 static constexpr uint8_t OPEN = 2;
87 static constexpr uint8_t ONSTACK = 4;
88 static constexpr uint8_t DEAD = 3;
89 static constexpr uint8_t MARKED = 7;
93 unsigned lowlink = std::numeric_limits<unsigned int>::max();
101 return status == NEW;
106 return status == OPEN;
109 bool is_onstack()
const
111 return status == ONSTACK;
114 bool is_closed()
const
116 return status & CLOSED;
119 bool is_dead_end()
const
121 return status == DEAD || status == MARKED;
124 bool is_marked_dead_end()
const
126 return status == MARKED;
135 void set_onstack(
const unsigned idx)
142 void close() { status = CLOSED; }
146 assert(!is_marked_dead_end());
150 void mark_dead_end() { status = MARKED; }
155 if constexpr (UseInterval) {
165 if constexpr (!UseInterval) {
166 return Interval(value, INFINITE_VALUE);
173template <
bool UseInterval>
175 storage::PerStateStorage<SearchNodeInformation<UseInterval>> infos;
177 SearchNodeInformation<UseInterval>& operator[](
StateID state_id)
179 return infos[state_id];
182 const SearchNodeInformation<UseInterval>& operator[](
StateID state_id)
const
184 return infos[state_id];
189 return infos[state_id].get_value();
194 return infos[state_id].get_bounds();
209template <
typename State,
typename Action,
bool UseInterval>
211 using Base =
typename ExhaustiveDepthFirstSearch::MDPAlgorithm;
213 using MDPType =
typename Base::MDPType;
214 using EvaluatorType =
typename Base::EvaluatorType;
215 using PolicyType = Base::PolicyType;
220 using SearchNodeInfo = SearchNodeInformation<UseInterval>;
223 const std::shared_ptr<TransitionSorterType> transition_sort_;
226 const AlgorithmValueType trivial_bound_;
228 const bool value_propagation_;
229 const bool only_propagate_when_changed_;
232 SearchNodeInfos<UseInterval> search_space_;
234 std::deque<ExpansionInformation> expansion_infos_;
235 std::deque<StackInformation> stack_infos_;
236 std::vector<StateID> neighbors_;
238 bool last_all_dead_ =
true;
239 bool last_all_marked_dead_ =
true;
241 Statistics statistics_;
245 std::shared_ptr<TransitionSorterType> transition_sorting,
248 bool only_propagate_when_changed);
252 EvaluatorType& heuristic,
255 double max_time)
override;
257 std::unique_ptr<PolicyType> compute_policy(
259 EvaluatorType& heuristic,
262 double max_time)
override;
267 void register_value_reports(
268 const SearchNodeInfo& info,
271 bool initialize_search_node(
273 EvaluatorType& heuristic,
275 SearchNodeInfo& info);
277 bool initialize_search_node(
279 EvaluatorType& heuristic,
281 SearchNodeInfo& info);
285 EvaluatorType& heuristic,
287 SearchNodeInfo& info);
289 void run_exploration(
291 EvaluatorType& heuristic,
294 void propagate_value_along_trace(
299 bool check_early_convergence(
const SearchNodeInfo& node)
const;
304#define GUARD_INCLUDE_PROBFD_ALGORITHMS_EXHAUSTIVE_DFS_H
305#include "probfd/algorithms/exhaustive_dfs_impl.h"
306#undef GUARD_INCLUDE_PROBFD_ALGORITHMS_EXHAUSTIVE_DFS_H
A convenience class that represents a finite probability distribution.
Definition task_state_space.h:27
Interface for MDP algorithm implementations.
Definition mdp_algorithm.h:29
A registry for print functions related to search progress.
Definition progress_report.h:33
Interface providing access to various state properties during heuristic search.
Definition state_properties.h:22
An interface used to reorder a list of transitions.
Definition transition_sorter.h:27
Implementation of an anytime topological value iteration variant.
Definition exhaustive_dfs.h:210
void print_statistics(std::ostream &out) const override
Prints algorithm statistics to the specified output stream.
Definition exhaustive_dfs_impl.h:117
namespace for anytime TVI
Definition exhaustive_dfs.h:24
This namespace contains implementations of SSP search algorithms.
Definition acyclic_value_iteration.h:22
std::conditional_t< UseInterval, Interval, value_t > AlgorithmValue
Convenience value type alias for algorithms selecting interval iteration behaviour based on a templat...
Definition types.h:14
double value_t
Typedef for the state value type.
Definition aliases.h:7
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
Represents a closed interval over the extended reals as a pair of lower and upper bound.
Definition interval.h:12
A StateID represents a state within a StateIDMap. Just like Fast Downward's StateID type,...
Definition types.h:22