Grail (C++)
1.4.0
A multi-platform, modular, universal engine for embedding advanced AI in games.
|
#include <Planner.hh>
Classes | |
struct | AbstractPlan |
Represents a formulated plan as a sequence of actions and a cost. More... | |
struct | Config |
The Planner's run-time configuration parameters. More... | |
Public Member Functions | |
Planner (std::unique_ptr< WorldState > initialState, const Config &config=Config{}) | |
void | SetIterationLimit (std::size_t iterationLimit) |
SetIterationLimit - sets maximum number of iterations per each execution of the planning problem. Each iteration ends with one candidate plan. More... | |
void | SetMaxPlanLength (int maxLength) |
SetMaxPlanLength - Limits generated plans to not exceed given number of steps to achieve goal conditions. More... | |
void | SetMaxPlanCost (double maxCost) |
SetMaxPlanCost - Limits generated plans cost (measured as the sum of costs of actions it consists of) needed to achieve goal conditions. More... | |
void | SetHeuristic (PlannerHeuristic heuristic) |
void | SetConfig (const Config &config) |
ResetConfig - Sets planner config: max iteration, cost, length, plan heuristic, and node count. More... | |
void | PushCondition (ConditionFunction condition) |
AbstractPlan | GetPartialPlan () const |
GetPartialPlan - returns currently best plan, regardless if goal conditions are met. Will return an empty plan if no calculations were finished. More... | |
data::PlannerIterationSnapshot | GetPlanSnapshot (std::size_t goalNodeIndex, std::size_t iteration) const |
GetPlanSnapshot - Get debug data on a single iteration of a plan. More... | |
void | Iterate (std::size_t iterationCount) noexcept |
Formulate a plan trying to meet goalConditions from initialState. It will call "OnPlanningFailed" or "OnPlanFound" when finished. More... | |
void | IterateWithSnapshot (std::size_t iterationCount, data::PlannerReasonerSnapshot &snapshot, std::size_t minDebugSnapshotIteration=0, std::size_t maxDebugSnapshotIteration=std::numeric_limits< std::size_t >::max()) noexcept |
IterateWithSnapshot - Formulates a plan trying to meet goalConditions from initialState. Outputs debug data during every iteration if not limited by min or max snapshot iteration parameters. More... | |
void | SetPlanFoundCallback (const std::function< void(const AbstractPlan &)> callbackFunction) |
SetPlanFoundCallback - Binds a function handle to call if a sufficient plan is found. Best plan will be passed as function argument. More... | |
void | SetPlanningFailedCallback (const std::function< void()> callbackFunction) |
SetPlanningFailedCallback - Binds a function handle to call if no sufficient plan was found. More... | |
void | Reset (std::unique_ptr< WorldState > initialState) |
Reset - Resets planner to given world state. Any existing plans and goal conditions will be cleared. More... | |
bool | IsComputing () const |
IsComputing - Returns true if no suitable plan was found and planning hasn't failed. This does not mean that planner is currently formulating a plan. More... | |
The main class encapsulating the planning algorithm in Grail. Responsible for finding paths in an abstract plans space. You can use this class directly (as a raw algorithm) or indirectly through a Reasoners::PlannerReasoner instead.
grail::planner::Planner::Planner | ( | std::unique_ptr< WorldState > | initialState, |
const Config & | config = Config{} |
||
) |
Constructs a new planner object with a provided initial state and a default configuration.
initialState | - the initial state of the planning space. The plans will be created from this state to the goal state. |
config | - optional configuration parameters. |
Planner::AbstractPlan grail::planner::Planner::GetPartialPlan | ( | ) | const |
GetPartialPlan - returns currently best plan, regardless if goal conditions are met. Will return an empty plan if no calculations were finished.
data::PlannerIterationSnapshot grail::planner::Planner::GetPlanSnapshot | ( | std::size_t | goalNodeIndex, |
std::size_t | iteration | ||
) | const |
bool grail::planner::Planner::IsComputing | ( | ) | const |
IsComputing - Returns true if no suitable plan was found and planning hasn't failed. This does not mean that planner is currently formulating a plan.
|
noexcept |
Formulate a plan trying to meet goalConditions from initialState. It will call "OnPlanningFailed" or "OnPlanFound" when finished.
Runs the planning process for the given number of iterations.
iterationCount | - the max number of plan iterations to calculate. |
|
noexcept |
IterateWithSnapshot - Formulates a plan trying to meet goalConditions from initialState. Outputs debug data during every iteration if not limited by min or max snapshot iteration parameters.
iterationCount | Max number of plan iterations to calculate |
snapshot | Plan debug data |
minDebugSnapshotIteration | Min number of plan iterations to include in debug data from |
maxDebugSnapshotIteration | Max number of plan iteration to include in debug data |
void grail::planner::Planner::PushCondition | ( | ConditionFunction | condition | ) |
Adds a single goal condition to the planner. The planner may have multiple independent conditions defined.
condition | - a boolean function representing a single goal condition |
void grail::planner::Planner::Reset | ( | std::unique_ptr< WorldState > | initialState | ) |
Reset - Resets planner to given world state. Any existing plans and goal conditions will be cleared.
initialState | New WorldState planner will start formulating plans from |
void grail::planner::Planner::SetConfig | ( | const Config & | config | ) |
ResetConfig - Sets planner config: max iteration, cost, length, plan heuristic, and node count.
config | New planner config |
void grail::planner::Planner::SetHeuristic | ( | PlannerHeuristic | heuristic | ) |
Enables the planner to heuristically evaluate the calculated plans. Similarly to A* pathfinding heuristic, it should return the estimation of the distance (cost) between an arbitrary state and the goal state.
heuristic | Plan evaluation heuristic |
void grail::planner::Planner::SetIterationLimit | ( | std::size_t | iterationLimit | ) |
SetIterationLimit - sets maximum number of iterations per each execution of the planning problem. Each iteration ends with one candidate plan.
iterationLimit | Iteration limit |
void grail::planner::Planner::SetMaxPlanCost | ( | double | maxCost | ) |
SetMaxPlanCost - Limits generated plans cost (measured as the sum of costs of actions it consists of) needed to achieve goal conditions.
maxCost | Maximum plan cost. Set -1 for no limit. |
void grail::planner::Planner::SetMaxPlanLength | ( | int | maxLength | ) |
SetMaxPlanLength - Limits generated plans to not exceed given number of steps to achieve goal conditions.
maxLength | - the maximum number of plan steps. Set -1 for unlimited plans. |
void grail::planner::Planner::SetPlanFoundCallback | ( | const std::function< void(const AbstractPlan &)> | callbackFunction | ) |
SetPlanFoundCallback - Binds a function handle to call if a sufficient plan is found. Best plan will be passed as function argument.
callbackFunction | Function to call if plan is found |
void grail::planner::Planner::SetPlanningFailedCallback | ( | const std::function< void()> | callbackFunction | ) |
SetPlanningFailedCallback - Binds a function handle to call if no sufficient plan was found.
callbackFunction | Function to call if planning failed |