16 #include <unordered_map>
25 template <
class state,
class action,
bool verbose = true>
31 std::vector<state> &thePath);
33 std::vector<action> &thePath);
44 state parent, state currState,
45 std::vector<state> &thePath,
double bound,
double g,
48 action forbiddenAction, state &currState,
49 std::vector<action> &thePath,
double bound,
double g,
50 double maxH,
double parentH);
80 std::function<void (state,
int)> func;
84 template <
class state,
class action,
bool verbose>
87 std::vector<state> &thePath)
92 nodesExpanded = nodesTouched = 0;
94 UpdateNextBound(0, heuristic->HCost(from, to));
96 thePath.push_back(from);
100 gCostHistogram.clear();
101 gCostHistogram.resize(nextBound+1);
103 printf(
"Starting iteration with bound %f\n", nextBound);
104 if (DoIteration(env, from, from, thePath, nextBound, 0, 0) == 0)
111 template <
class state,
class action,
bool verbose>
113 state from, state to,
114 std::vector<action> &thePath)
116 if (!storedHeuristic)
119 nodesExpanded = nodesTouched = 0;
125 double rootH = heuristic->
HCost(from, to);
126 UpdateNextBound(0, rootH);
128 std::vector<action> act;
130 while (thePath.size() == 0)
133 gCostHistogram.clear();
134 gCostHistogram.resize(nextBound+1);
136 printf(
"Starting iteration with bound %f; %" PRId64
" expanded, %" PRId64
" generated\n", nextBound, nodesExpanded, nodesTouched);
138 DoIteration(env, act[0], from, thePath, nextBound, 0, 0, rootH);
143 template <
class state,
class action,
bool verbose>
145 state parent, state currState,
146 std::vector<state> &thePath,
double bound,
double g,
149 double h = heuristic->HCost(currState, goal);
151 if (usePathMax &&
fless(h, maxH))
155 UpdateNextBound(bound, g+h);
162 std::vector<state> neighbors;
164 nodesTouched += neighbors.size();
168 for (
unsigned int x = 0; x < neighbors.size(); x++)
170 if (neighbors[x] == parent)
172 thePath.push_back(neighbors[x]);
173 double edgeCost = env->
GCost(currState, neighbors[x]);
174 double childH = DoIteration(env, currState, neighbors[x], thePath, bound,
175 g+edgeCost, maxH - edgeCost);
180 if (usePathMax &&
fgreater(childH-edgeCost, h))
186 UpdateNextBound(bound, g+h);
194 template <
class state,
class action,
bool verbose>
196 action forbiddenAction, state &currState,
197 std::vector<action> &thePath,
double bound,
double g,
198 double maxH,
double parentH)
200 double h = heuristic->HCost(currState, goal);
203 if (usePathMax &&
fless(h, maxH))
207 UpdateNextBound(bound, g+h);
215 std::vector<action> &actions = *actCache.getItem();
217 nodesTouched += actions.size();
220 int depth = (int)thePath.size();
222 func(currState, depth);
225 for (
unsigned int x = 0; x < actions.size(); x++)
227 if ((depth != 0) && (actions[x] == forbiddenAction))
230 thePath.push_back(actions[x]);
231 double edgeCost = env->
GCost(currState, actions[x]);
233 action a = actions[x];
236 double childH = DoIteration(env, a, currState, thePath, bound,
237 g+edgeCost, maxH - edgeCost, parentH);
241 actCache.returnItem(&actions);
248 if (usePathMax &&
fgreater(childH-edgeCost, h))
254 UpdateNextBound(bound, g+h);
255 actCache.returnItem(&actions);
260 actCache.returnItem(&actions);
265 template <
class state,
class action,
bool verbose>
268 if (!
fgreater(nextBound, currBound))
273 else if (
fgreater(fCost, currBound) &&
fless(fCost, nextBound))