49# ifndef STATE_SEARCH_IDA_STAR_H
50# define STATE_SEARCH_IDA_STAR_H
73template <
typename Domain>
85template <
typename Distance>
102template <
typename Solution,
typename Distance>
114namespace ida_star_detail {
125template <
typename Distance>
128 if constexpr (std::is_floating_point_v<Distance>)
129 return std::numeric_limits<Distance>::infinity();
131 return std::numeric_limits<Distance>::max();
135template <
typename Distance>
148template <IDAStarDomain Domain,
typename Solution,
typename OnSolution>
151 typename Domain::State &state,
153 const typename Domain::Distance g,
154 const typename Domain::Distance threshold,
159 using Distance =
typename Domain::Distance;
165 const Distance h = domain.heuristic(state);
171 if (domain.is_goal(state))
174 Solution solution{state, path, depth};
180 return {
true, threshold};
210 using Move =
typename Domain::Move;
213 (
void) domain.for_each_successor(state,
214 [&](
const Move &move) ->
bool
227 domain.apply(state, move);
231 child =
dfs(domain, state, path, g +
step, threshold, depth + 1, result,
on_solution);
238 domain.undo(state, move);
243 domain.undo(state, move);
284template <IDAStarDomain Domain>
291 using State =
typename Domain::State;
293 using Move =
typename Domain::Move;
389 template <
typename OnSolution>
394 <<
"IDA_Star_State_Search only supports depth-first strategy";
396 <<
"SearchLimits::max_solutions must be positive or Search_Unlimited";
402 const auto start_time = SearchClock::now();
422 result.iterations.append(iteration);
437 if (next_bound >= ida_star_detail::distance_unreachable<Distance>())
443 threshold = next_bound;
461template <IDAStarDomain Domain>
472template <IDAStarDomain Domain,
typename OnSolution>
Minimal depth-first backtracking engine for implicit state spaces.
Exception handling system with formatted messages for Aleph-w.
#define ah_invalid_argument_if(C)
Throws std::invalid_argument if condition holds.
Simple dynamic array with automatic resizing and functional operations.
T & append(const T &data)
Append a copy of data
bool consider(const Solution &candidate)
Consider a candidate by copy.
IDA* engine for implicit state spaces with an admissible heuristic.
Domain & domain() noexcept
Mutable access to the bound domain adapter.
typename Domain::Move Move
Move type.
typename Domain::State State
Concrete search state type.
Domain Domain_Type
Type of the problem domain.
Result search(State initial_state, OnSolution &on_solution)
Run IDA* and invoke on_solution when the goal is reached.
const SearchLimits & limits() const noexcept
Current hard limits.
Result search(State initial_state)
Run IDA* from initial_state.
IDA_Star_State_Search(Domain domain, ExplorationPolicy policy={}, const SearchLimits &limits={})
Construct an engine bound to one domain adapter.
const ExplorationPolicy & policy() const noexcept
Current exploration policy.
ExplorationPolicy policy_
const Domain & domain() const noexcept
Read-only access to the bound domain adapter.
static constexpr bool supports_best_first
Compile-time marker: IDA_Star_State_Search only supports Depth_First strategy.
void set_policy(const ExplorationPolicy &policy) noexcept
Replace the exploration policy for future runs.
void set_limits(const SearchLimits &limits) noexcept
Replace the hard limits for future runs.
Concept for domains that provide the cost of applying a move.
Minimal contract for DFS/backtracking domains.
Concept for domains that provide an admissible heuristic.
Minimal contract for IDA* domains.
Concept for callbacks invoked on each accepted solution.
DFSResult< typename Domain::Distance > dfs(Domain &domain, typename Domain::State &state, SearchPath< typename Domain::Move > &path, const typename Domain::Distance g, const typename Domain::Distance threshold, const size_t depth, IDAStarResult< Solution, typename Domain::Distance > &result, OnSolution &on_solution)
Core recursive DFS used by IDA* for a single threshold pass.
constexpr Distance distance_unreachable() noexcept
Sentinel value representing an unreachable or pruned f-cost.
bool should_prune_state(Domain &domain, const typename Domain::State &state, const size_t depth)
Dispatch helper for the optional should_prune hook.
bool is_terminal_state(const Domain &domain, const typename Domain::State &state)
Dispatch helper for the optional is_terminal hook.
Main namespace for Aleph-w library functions.
and
Check uniqueness with explicit hash + equality functors.
auto ida_star_search(Domain domain, typename Domain::State initial_state, ExplorationPolicy policy={}, SearchLimits limits={})
Convenience wrapper for a one-shot IDA* search.
@ LimitReached
Search stopped because an external hard limit was hit.
@ Exhausted
Search space within the configured bounds was exhausted.
@ StoppedOnSolution
Search stopped because solution handling requested it.
@ NotStarted
Search object exists but no traversal has run yet.
void reserve_search_path(SearchPath< Move > &path, const SearchLimits &limits)
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
double search_elapsed_ms(const SearchClock::duration &duration) noexcept
@ Domain
Preserve the order emitted by for_each_successor().
Common infrastructure for implicit state-space search.
Default solution visitor that always continues the search.
Exploration controls shared across engines.
Strategy strategy
Traversal strategy.
@ Depth_First
Recursive depth-first traversal (all engines).
Result of one threshold pass of IDA*.
bool found_solution
True if a goal was reached at or below threshold.
Distance next_threshold
Minimum f-value that exceeded threshold.
size_t visited_states
States visited during this pass.
Distance threshold
F-cost threshold used for this pass.
Aggregated result of a complete IDA* run.
Array< IDAStarIteration< Distance > > iterations
One entry per completed threshold pass.
Distance total_cost
Optimal path cost (valid when found_solution()).
Hard bounds applied by the search engine.
size_t max_expansions
Maximum expanded states.
size_t max_solutions
Maximum accepted solutions.
size_t max_depth
Maximum expansion depth.
Aggregates the outcome of one search execution.
SearchStats stats
Statistics collected during the run.
ExplorationPolicy policy
Exploration policy used for the run.
SearchLimits limits
Limits used for the run.
SearchStatus status
Final execution state.
Incumbent_Type best_solution
Best incumbent retained by the engine.
Snapshot of a concrete solution encountered during the traversal.
size_t limit_hits
Number of hard-limit stops triggered.
size_t pruned_by_domain
States discarded by domain-side pruning.
size_t terminal_states
Non-solution terminal states cut by the domain.
double elapsed_ms
Wall-clock time spent inside the search call.
size_t pruned_by_depth
States not expanded due to max depth.
size_t generated_successors
Number of successor moves emitted.
size_t max_depth_reached
Deepest path depth visited.
size_t solutions_found
Number of goal states accepted.
size_t expanded_states
Number of non-terminal states expanded.
size_t visited_states
Number of states entered by the engine.
Outcome of one recursive DFS step inside IDA*.