Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::search_engine_detail Namespace Reference

Shared helper utilities used internally by all search engines. More...

Functions

template<typename Domain >
bool is_terminal_state (const Domain &domain, const typename Domain::State &state)
 Dispatch helper for the optional is_terminal hook.
 
template<typename Domain >
bool should_prune_state (Domain &domain, const typename Domain::State &state, const size_t depth)
 Dispatch helper for the optional should_prune hook.
 
template<typename Result >
void register_visit (const size_t depth, Result &result)
 Update visit counters and max-depth statistic.
 
template<typename Result >
bool expansion_limit_reached (Result &result, const SearchLimits &limits)
 Check whether the expansion limit has been reached.
 
template<typename Result >
bool stop_after_solution (Result &result, const ExplorationPolicy &policy, const SearchLimits &limits)
 Decide whether to stop the search after a solution was accepted.
 

Detailed Description

Shared helper utilities used internally by all search engines.

These functions encapsulate the optional-hook dispatch and common bookkeeping that was previously duplicated across state_search_detail, branch_and_bound_detail, and adversarial_search_detail. Engines should call these helpers instead of re-implementing the same logic locally.

Function Documentation

◆ expansion_limit_reached()

template<typename Result >
bool Aleph::search_engine_detail::expansion_limit_reached ( Result &  result,
const SearchLimits limits 
)

Check whether the expansion limit has been reached.

Marks the result as SearchStatus::LimitReached and increments the limit-hit counter when the number of expanded states meets or exceeds the configured maximum. Engines that need additional side-effects (e.g., setting an internal stop_ flag) should perform them after this call returns true.

Template Parameters
ResultSearch-result type that owns a SearchStats member.
Parameters
resultResult object to inspect and update.
limitsHard bounds for the current run.
Returns
true if the limit has been reached; false otherwise.

Definition at line 810 of file state_search_common.H.

References Aleph::LimitReached, and Aleph::SearchLimits::max_expansions.

Referenced by Aleph::Alpha_Beta< Domain >::expansion_limit_reached(), Aleph::Negamax< Domain >::expansion_limit_reached(), Aleph::Depth_First_Backtracking< Domain >::expansion_limit_reached(), and Aleph::Branch_And_Bound< Domain, ObjectivePolicy >::expansion_limit_reached().

◆ is_terminal_state()

template<typename Domain >
bool Aleph::search_engine_detail::is_terminal_state ( const Domain domain,
const typename Domain::State &  state 
)

Dispatch helper for the optional is_terminal hook.

Returns true if Domain satisfies Aleph::TerminalPredicate and the domain reports the state as a non-goal dead end. Returns false unconditionally when the domain does not expose is_terminal.

Template Parameters
DomainProblem-domain type.
Parameters
domainDomain adapter (const reference).
stateCurrent search state.

Definition at line 750 of file state_search_common.H.

Referenced by Aleph::ida_star_detail::dfs(), Aleph::Depth_First_Backtracking< Domain >::dfs(), Aleph::Branch_And_Bound< Domain, ObjectivePolicy >::dfs(), Aleph::Branch_And_Bound< Domain, ObjectivePolicy >::dfs_visited(), Aleph::Depth_First_Backtracking< Domain >::dfs_visited(), and Aleph::Branch_And_Bound< Domain, ObjectivePolicy >::process_best_first_candidate().

◆ register_visit()

template<typename Result >
void Aleph::search_engine_detail::register_visit ( const size_t  depth,
Result &  result 
)

Update visit counters and max-depth statistic.

Must be called once per node entry by any search engine.

Template Parameters
ResultSearch-result type that owns a SearchStats member.
Parameters
depthCurrent search depth.
resultResult object whose statistics are updated in-place.

Definition at line 790 of file state_search_common.H.

Referenced by Aleph::Branch_And_Bound< Domain, ObjectivePolicy >::register_visit(), Aleph::Negamax< Domain >::search_node(), and Aleph::Alpha_Beta< Domain >::search_node().

◆ should_prune_state()

template<typename Domain >
bool Aleph::search_engine_detail::should_prune_state ( Domain domain,
const typename Domain::State &  state,
const size_t  depth 
)

Dispatch helper for the optional should_prune hook.

Returns true if Domain satisfies Aleph::DomainPruner and the domain requests an early cutoff of the current state. Returns false when the domain does not expose should_prune.

Template Parameters
DomainProblem-domain type.
Parameters
domainDomain adapter.
stateCurrent search state.
depthCurrent search depth.

Definition at line 771 of file state_search_common.H.

Referenced by Aleph::ida_star_detail::dfs(), Aleph::Depth_First_Backtracking< Domain >::dfs(), Aleph::Branch_And_Bound< Domain, ObjectivePolicy >::dfs(), Aleph::Branch_And_Bound< Domain, ObjectivePolicy >::dfs_visited(), Aleph::Depth_First_Backtracking< Domain >::dfs_visited(), Aleph::Branch_And_Bound< Domain, ObjectivePolicy >::process_best_first_candidate(), Aleph::Negamax< Domain >::search_node(), and Aleph::Alpha_Beta< Domain >::search_node().

◆ stop_after_solution()

template<typename Result >
bool Aleph::search_engine_detail::stop_after_solution ( Result &  result,
const ExplorationPolicy policy,
const SearchLimits limits 
)

Decide whether to stop the search after a solution was accepted.

Returns true (and updates result.status) in two cases, checked in priority order:

  1. the configured maximum number of solutions has been reached (hard limit — increments limit_hits, sets SearchStatus::LimitReached);
  2. the policy requests stopping at the first solution (soft stop — sets SearchStatus::StoppedOnSolution).

The hard limit is evaluated first so that limit_hits and SearchStatus::LimitReached are always reported when max_solutions is finite and reached, regardless of the stop_at_first_solution flag.

Template Parameters
ResultSearch-result type that owns a SearchStats member.
Parameters
resultResult object to update.
policyExploration policy for the current run.
limitsHard bounds for the current run.
Returns
true if the engine should stop; false to keep searching.

Definition at line 843 of file state_search_common.H.

References Aleph::and, Aleph::LimitReached, Aleph::SearchLimits::max_solutions, Aleph::Search_Unlimited, Aleph::ExplorationPolicy::stop_at_first_solution, and Aleph::StoppedOnSolution.

Referenced by Aleph::Depth_First_Backtracking< Domain >::stop_after_solution(), and Aleph::Branch_And_Bound< Domain, ObjectivePolicy >::stop_after_solution().