1 #ifndef GRAIL_PLANNER_H
2 #define GRAIL_PLANNER_H
4 #include "WorldState/WorldState.hh"
5 #include "Action/Action.hh"
6 #include "../../GrailData/GrailDebugInfo/PlannerSnapshots.h"
18 using ConditionFunction = std::function<bool(
const WorldState&)>;
19 using PlannerHeuristic = std::function<double(
const WorldState&,
const std::vector<ConditionFunction>&)>;
28 PlannerHeuristic heuristic =
nullptr;
29 std::size_t iterationLimit = 500;
30 int maxPlanLength = -1;
31 double maxPlanCost = -1;
32 std::size_t initialNodeCapacity = 128;
37 std::vector<Action> actions{};
38 float totalCost = 0.0f;
44 void SetIterationLimit(std::size_t iterationLimit);
45 void SetMaxPlanLength(
int maxDepth);
46 void SetMaxPlanCost(
double maxCost);
47 void SetHeuristic(PlannerHeuristic heuristic);
48 void ResetConfig(
const Config& config);
53 AbstractPlan GetPartialPlan()
const;
55 void Iterate(std::size_t iterationCount) noexcept;
56 void IterateWithSnapshot(std::size_t iterationCount,
PlannerReasonerSnapshot& snapshot, std::size_t minDebugSnapshotIteration = 0, std::size_t maxDebugSnapshotIteration = std::numeric_limits<std::size_t>::max()) noexcept;
57 void SetPlanFoundCallback(const std::function<
void(const AbstractPlan&)> callbackFunction);
58 void SetPlanningFailedCallback(const std::function<
void()> callbackFunction);
60 bool IsComputing() const;
70 double distanceFromGoal = std::numeric_limits<double>::max();
71 std::shared_ptr<Edge> pathEdge =
nullptr;
76 Node& operator=(Node&& other);
81 Edge(std::size_t sourceIndex, std::size_t destinationIndex,
Action&& action);
83 std::size_t sourceIndex = 0;
84 std::size_t destinationIndex = 0;
90 EdgePriority(
const std::shared_ptr<Edge>& edge,
double dijkstraScore,
double aStarScore);
92 std::shared_ptr<Edge> edge;
97 class EdgePriorityComparer
100 bool operator() (
const EdgePriority& one,
const EdgePriority& other)
102 return one.aStarScore > other.aStarScore;
107 void AddNode(Node&& node);
108 bool IsGoalAchieved(
const WorldState& state)
const;
110 WorldState initialState;
111 Config plannerConfig = {};
113 std::vector<ConditionFunction> goalConditions = {};
114 std::function<void(
const AbstractPlan&)> onPlanFound =
nullptr;
115 std::function<void()> onPlanningFailed =
nullptr;
118 std::size_t nextNodeIndex = 0;
119 std::size_t nodeClosestToGoalIndex = std::numeric_limits<std::size_t>::max();
120 std::size_t lastChosenNodeIndex = std::numeric_limits<std::size_t>::max();
121 int maxNodeDepth = 0;
122 std::priority_queue<EdgePriority, std::vector<EdgePriority>, EdgePriorityComparer> edges{};
123 std::vector<Node> generatedNodes{};
124 std::vector<std::size_t> closedNodeIndices{};
125 std::size_t currentIteration = 0;
126 bool isPlanningFinished =
true;
The MemoryPool class - preallocated memory container for optimization issues.
Definition: MemoryPool.hh:74
The main class responsible for finding paths in plan space.
Definition: Planner.hh:23
void PushCondition(ConditionFunction condition)
Definition: Planner.cpp:60
A class representing planner world state.
Definition: WorldState.hh:15
Definition: PlannerSnapshots.h:44
Definition: PlannerSnapshots.h:64
Definition: Planner.hh:36
Definition: Planner.hh:26