![]() |
mutable
A Database System for Research and Fast Prototyping
|
Implements a generic A* search algorithm. More...
#include <HeuristicSearch.hpp>
Public Types | |
using | state_type = State |
using | expand_type = Expand |
using | heuristic_type = Heuristic |
using | static_search_config = StaticConfig |
using | callback_t = std::function< void(state_type, double)> |
using | state_manager_type = StateManager< State, Expand, Heuristic, not(use_beam_search and is_monotone), use_beam_search, StaticConfig, Context... > |
Public Member Functions | |
genericAStar (Context &... context) | |
genericAStar (const genericAStar &)=delete | |
genericAStar (genericAStar &&)=default | |
genericAStar & | operator= (genericAStar &&)=default |
const state_manager_type & | state_manager () const |
float | weighting_factor () const |
Returns the weighting factor for the heuristic value. | |
float | weighting_factor (float new_factor) |
Set the weighting factor for the heuristic value and returns the old value. | |
const State & | search (state_type initial_state, expand_type expand, heuristic_type &heuristic, const SearchConfiguration< StaticConfig > &config, Context &... context) |
Search for a path from the given initial_state to a goal state. | |
void | clear () |
Resets the state of the search. | |
void | dump (std::ostream &out) const |
void | dump () const |
Static Public Attributes | |
static constexpr bool | use_weighted_search = StaticConfig::PerformWeightedSearch |
| |
static constexpr float | beam_width = StaticConfig::BeamWidth::num / StaticConfig::BeamWidth::den |
| |
static constexpr bool | use_beam_search = StaticConfig::BeamWidth::num != 0 |
| |
static constexpr bool | use_dynamic_beam_sarch = use_beam_search and beam_width < 1.f |
| |
static constexpr bool | is_lazy = StaticConfig::Lazy |
| |
static constexpr bool | is_monotone = StaticConfig::IsMonotone |
| |
static constexpr float | BEAM_FACTOR = .2f |
| |
static constexpr bool | use_anytime_search = StaticConfig::PerformAnytimeSearch |
| |
Private Member Functions | |
DEF_COUNTER (cached_heuristic_value) struct weighted_state | |
A state plus its heuristic value. | |
void | beam (state_type state, double h, Context &... context) |
void | beam_dynamic (expand_type &expand, Context &... context) |
void | for_each_successor_lazily (callback_t &&callback, const state_type &state, heuristic_type &heuristic, expand_type &expand, Context &... context) |
Expands the given state by lazily evaluating the heuristic function. | |
void | for_each_successor_eagerly (callback_t &&callback, const state_type &state, heuristic_type &heuristic, expand_type &expand, Context &... context) |
Expands the given state by eagerly evaluating the heuristic function. | |
void | for_each_successor (callback_t &&callback, const state_type &state, heuristic_type &heuristic, expand_type &expand, Context &... context) |
Expands the given state according to is_lazy . | |
void | explore_state (const state_type &state, heuristic_type &heuristic, expand_type &expand, Context &... context) |
Explores the given state . | |
Private Attributes | |
float | weighting_factor_ = 1. |
| |
state_manager_type | state_manager_ |
| |
std::vector< weighted_state > | candidates |
| |
Friends | |
std::ostream & | operator<< (std::ostream &out, const genericAStar &AStar) |
Implements a generic A* search algorithm.
Allows for specifying a weighting factor for the heuristic value. Allows for lazy evaluation of the heuristic.
Definition at line 620 of file HeuristicSearch.hpp.
using m::ai::genericAStar< State, Expand, Heuristic, StaticConfig, Context >::callback_t = std::function<void(state_type, double)> |
Definition at line 644 of file HeuristicSearch.hpp.
using m::ai::genericAStar< State, Expand, Heuristic, StaticConfig, Context >::expand_type = Expand |
Definition at line 623 of file HeuristicSearch.hpp.
using m::ai::genericAStar< State, Expand, Heuristic, StaticConfig, Context >::heuristic_type = Heuristic |
Definition at line 624 of file HeuristicSearch.hpp.
using m::ai::genericAStar< State, Expand, Heuristic, StaticConfig, Context >::state_manager_type = StateManager< State, Expand, Heuristic, not (use_beam_search and is_monotone), use_beam_search, StaticConfig, Context... > |
Definition at line 646 of file HeuristicSearch.hpp.
using m::ai::genericAStar< State, Expand, Heuristic, StaticConfig, Context >::state_type = State |
Definition at line 622 of file HeuristicSearch.hpp.
using m::ai::genericAStar< State, Expand, Heuristic, StaticConfig, Context >::static_search_config = StaticConfig |
Definition at line 625 of file HeuristicSearch.hpp.
|
inlineexplicit |
Definition at line 705 of file HeuristicSearch.hpp.
|
delete |
|
default |
|
inlineprivate |
Definition at line 752 of file HeuristicSearch.hpp.
References M_insist, and m::ai::StateManager< State, Expand, Heurisitc, HasRegularQueue, HasBeamQueue, Config, Context >::push_regular_queue().
|
inlineprivate |
Definition at line 787 of file HeuristicSearch.hpp.
References M_insist, m::ai::StateManager< State, Expand, Heurisitc, HasRegularQueue, HasBeamQueue, Config, Context >::push_beam_queue(), and m::ai::StateManager< State, Expand, Heurisitc, HasRegularQueue, HasBeamQueue, Config, Context >::push_regular_queue().
|
inline |
Resets the state of the search.
Definition at line 740 of file HeuristicSearch.hpp.
References m::ai::StateManager< State, Expand, Heurisitc, HasRegularQueue, HasBeamQueue, Config, Context >::clear().
|
inlineprivate |
A state plus its heuristic value.
Definition at line 673 of file HeuristicSearch.hpp.
|
inline |
Definition at line 890 of file HeuristicSearch.hpp.
References m::ai::genericAStar< State, Expand, Heuristic, StaticConfig, Context >::dump().
Referenced by m::ai::genericAStar< State, Expand, Heuristic, StaticConfig, Context >::dump().
|
inline |
Definition at line 889 of file HeuristicSearch.hpp.
|
inlineprivate |
Explores the given state
.
Definition at line 855 of file HeuristicSearch.hpp.
|
inlineprivate |
Expands the given state
according to is_lazy
.
Definition at line 845 of file HeuristicSearch.hpp.
|
inlineprivate |
Expands the given state
by eagerly evaluating the heuristic function.
Definition at line 824 of file HeuristicSearch.hpp.
|
inlineprivate |
Expands the given state
by lazily evaluating the heuristic function.
Definition at line 804 of file HeuristicSearch.hpp.
References m::ai::StateManager< State, Expand, Heurisitc, HasRegularQueue, HasBeamQueue, Config, Context >::end(), and m::ai::StateManager< State, Expand, Heurisitc, HasRegularQueue, HasBeamQueue, Config, Context >::find().
|
default |
const State & m::ai::genericAStar< State, Expand, Heuristic, StaticConfig, Context >::search | ( | state_type | initial_state, |
expand_type | expand, | ||
heuristic_type & | heuristic, | ||
const SearchConfiguration< StaticConfig > & | config, | ||
Context &... | context | ||
) |
Search for a path from the given initial_state
to a goal state.
Uses the given heuristic to guide the search. Provides an upper bound for the cost of the shortest path.
initial_state
to a goal state Definition at line 901 of file HeuristicSearch.hpp.
References m::and, m::ai::SearchConfiguration< StaticConfig >::expansion_budget, M_insist, m::ai::SearchConfiguration< StaticConfig >::upper_bound, and m::ai::SearchConfiguration< StaticConfig >::weighting_factor.
|
inline |
Definition at line 719 of file HeuristicSearch.hpp.
|
inline |
Returns the weighting factor for the heuristic value.
Definition at line 722 of file HeuristicSearch.hpp.
|
inline |
Set the weighting factor for the heuristic value and returns the old value.
Definition at line 725 of file HeuristicSearch.hpp.
References M_insist.
|
friend |
Definition at line 884 of file HeuristicSearch.hpp.
|
staticconstexpr |
The fraction of a state's successors to add to the beam (if performing beam search)
Definition at line 640 of file HeuristicSearch.hpp.
|
staticconstexpr |
The width of a beam used for beam search. Set to 0 to disable beam search.
Definition at line 630 of file HeuristicSearch.hpp.
|
private |
candidates for the beam
Definition at line 702 of file HeuristicSearch.hpp.
|
staticconstexpr |
Whether to evaluate the heuristic lazily
Definition at line 636 of file HeuristicSearch.hpp.
|
staticconstexpr |
Whether the state space is acyclic and without dead ends (useful in combination with beam search)
Definition at line 638 of file HeuristicSearch.hpp.
|
private |
the search's state manager, tracking heuristic value, checking for duplicates, and ordering by f-value
Definition at line 699 of file HeuristicSearch.hpp.
|
staticconstexpr |
Whether to search with a fixed, finite budget and return early when the budget is exhausted
Definition at line 642 of file HeuristicSearch.hpp.
|
staticconstexpr |
Whether to perform beam search or regular A*
Definition at line 632 of file HeuristicSearch.hpp.
|
staticconstexpr |
Whether to use a dynamic beam width for beam search
Definition at line 634 of file HeuristicSearch.hpp.
|
staticconstexpr |
Whether to perform weighted search with a given weighting factor for the heuristic value
Definition at line 628 of file HeuristicSearch.hpp.
|
private |
the weighting factor for the heuistic value of a state
Definition at line 658 of file HeuristicSearch.hpp.