1 #ifndef GRAIL_PLANNER_H
2 #define GRAIL_PLANNER_H
4 #include "../../GrailData/DebugInfo/PlannerSnapshots.h"
5 #include "Action/Action.hh"
6 #include "WorldState/WorldState.hh"
23 using ConditionFunction = std::function<bool(
const WorldState&)>;
24 using PlannerHeuristic = std::function<double(
const WorldState&,
const std::vector<ConditionFunction>&)>;
36 PlannerHeuristic heuristic =
nullptr;
37 std::size_t iterationLimit = 500;
38 int maxPlanLength = -1;
39 double maxPlanCost = -1;
40 std::size_t initialNodeCapacity = 128;
45 std::vector<Action> actions{};
46 float totalCost = 0.0f;
52 void SetIterationLimit(std::size_t iterationLimit);
53 void SetMaxPlanLength(
int maxLength);
54 void SetMaxPlanCost(
double maxCost);
55 void SetHeuristic(PlannerHeuristic heuristic);
56 void ResetConfig(
const Config& config);
61 AbstractPlan GetPartialPlan()
const;
63 void Iterate(std::size_t iterationCount) noexcept;
64 void IterateWithSnapshot(std::size_t iterationCount,
66 std::size_t minDebugSnapshotIteration = 0,
67 std::size_t maxDebugSnapshotIteration = std::numeric_limits<std::size_t>::max())
69 void SetPlanFoundCallback(const std::function<
void(const AbstractPlan&)> callbackFunction);
70 void SetPlanningFailedCallback(const std::function<
void()> callbackFunction);
71 void Reset(std::unique_ptr<
WorldState> initialState);
72 bool IsComputing() const;
84 double distanceFromGoal = std::numeric_limits<double>::max();
85 std::shared_ptr<Edge> pathEdge =
nullptr;
87 Node(Node&& other) noexcept;
90 Node& operator=(Node&& other) noexcept;
95 Edge(std::size_t sourceIndex, std::size_t destinationIndex,
Action&& action);
96 Edge(Edge&& otherEdge) =
default;
98 std::size_t sourceIndex = 0;
99 std::size_t destinationIndex = 0;
105 EdgePriority(
const std::shared_ptr<Edge>& edge,
double dijkstraScore,
double aStarScore);
107 std::shared_ptr<Edge> edge;
108 double dijkstraScore;
112 class EdgePriorityComparer
115 bool operator()(
const EdgePriority& one,
const EdgePriority& other)
117 return one.aStarScore > other.aStarScore;
123 void AddNode(Node&& node);
124 bool IsGoalAchieved(
const WorldState& state)
const;
126 std::unique_ptr<WorldState> initialState;
127 Config plannerConfig = {};
129 std::vector<ConditionFunction> goalConditions = {};
130 std::function<void(
const AbstractPlan&)> onPlanFound =
nullptr;
131 std::function<void()> onPlanningFailed =
nullptr;
134 std::size_t nextNodeIndex = 0;
135 std::size_t nodeClosestToGoalIndex = std::numeric_limits<std::size_t>::max();
136 std::size_t lastChosenNodeIndex = std::numeric_limits<std::size_t>::max();
137 int maxNodeDepth = 0;
138 std::priority_queue<EdgePriority, std::vector<EdgePriority>, EdgePriorityComparer> edges{};
139 std::vector<Node> generatedNodes{};
140 std::vector<std::size_t> closedNodeIndices{};
141 std::size_t currentIteration = 0;
142 bool isPlanningFinished =
true;
146 #endif //GRAIL_PLANNER_H