Grail (C++)  1.4.0
A multi-platform, modular, universal engine for embedding advanced AI in games.
grail::planner::Planner Class Reference

#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...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Planner()

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.

Parameters
initialState- the initial state of the planning space. The plans will be created from this state to the goal state.
config- optional configuration parameters.

Member Function Documentation

◆ GetPartialPlan()

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.

Returns
Currently best plan

◆ GetPlanSnapshot()

data::PlannerIterationSnapshot grail::planner::Planner::GetPlanSnapshot ( std::size_t  goalNodeIndex,
std::size_t  iteration 
) const

GetPlanSnapshot - Get debug data on a single iteration of a plan.

Parameters
goalNodeIndexIndex of Planner generatedNodes
iterationPlan iteration to gather debug data from
Returns
Plan iteration debug data

◆ IsComputing()

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.

Returns
Plan hasn't finished

◆ Iterate()

void grail::planner::Planner::Iterate ( std::size_t  iterationCount)
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.

Parameters
iterationCount- the max number of plan iterations to calculate.

◆ IterateWithSnapshot()

void grail::planner::Planner::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.

Parameters
iterationCountMax number of plan iterations to calculate
snapshotPlan debug data
minDebugSnapshotIterationMin number of plan iterations to include in debug data from
maxDebugSnapshotIterationMax number of plan iteration to include in debug data

◆ PushCondition()

void grail::planner::Planner::PushCondition ( ConditionFunction  condition)

Adds a single goal condition to the planner. The planner may have multiple independent conditions defined.

Parameters
condition- a boolean function representing a single goal condition

◆ Reset()

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.

Parameters
initialStateNew WorldState planner will start formulating plans from

◆ SetConfig()

void grail::planner::Planner::SetConfig ( const Config config)

ResetConfig - Sets planner config: max iteration, cost, length, plan heuristic, and node count.

Parameters
configNew planner config

◆ SetHeuristic()

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.

Parameters
heuristicPlan evaluation heuristic

◆ SetIterationLimit()

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.

Parameters
iterationLimitIteration limit

◆ SetMaxPlanCost()

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.

Parameters
maxCostMaximum plan cost. Set -1 for no limit.

◆ SetMaxPlanLength()

void grail::planner::Planner::SetMaxPlanLength ( int  maxLength)

SetMaxPlanLength - Limits generated plans to not exceed given number of steps to achieve goal conditions.

Parameters
maxLength- the maximum number of plan steps. Set -1 for unlimited plans.

◆ SetPlanFoundCallback()

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.

Parameters
callbackFunctionFunction to call if plan is found

◆ SetPlanningFailedCallback()

void grail::planner::Planner::SetPlanningFailedCallback ( const std::function< void()>  callbackFunction)

SetPlanningFailedCallback - Binds a function handle to call if no sufficient plan was found.

Parameters
callbackFunctionFunction to call if planning failed

The documentation for this class was generated from the following files: