15 #include <unordered_map>
20 template <
class state,
class action>
26 std::vector<state> &thePath);
28 std::vector<action> &thePath);
37 state &currState, state &goalState,
38 action forbiddenForwardAction,
bool validForward,
39 action forbiddenBackAction,
bool validBack,
40 std::vector<action> &thePath,
double bound,
double g);
42 double gCost,
double bound);
44 double gCost,
double bound);
50 template <
class state,
class action>
53 std::vector<state> &thePath)
55 assert(!
"Not implemented -- too expensive for large state reps.");
58 template <
class state,
class action>
61 std::vector<action> &thePath)
64 nodesExpanded = nodesTouched = 0;
66 UpdateNextBound(0, env->
HCost(from, to));
67 std::vector<action> act;
69 while (thePath.size() == 0)
72 DoIteration(env, from, to, act[0],
false, act[0],
false, thePath, nextBound, 0);
76 template <
class state,
class action>
78 state &currState, state &goalState,
79 action forbiddenForwardAction,
bool validForward,
80 action forbiddenBackAction,
bool validBack,
81 std::vector<action> &thePath,
double bound,
double g)
84 double h = env->
HCost(currState, goalState);
88 UpdateNextBound(bound, g+h);
92 if (env->
GoalTest(currState, goalState))
95 if (ShouldSearchForward1(env, currState, goalState, g, bound))
97 std::vector<action> actions;
99 nodesTouched += actions.size();
101 for (
unsigned int x = 0; x < actions.size(); x++)
103 if (validForward && (actions[x] == forbiddenForwardAction))
106 thePath.push_back(actions[x]);
108 double edgeCost = env->
GCost(currState, actions[x]);
111 double childH = DoIteration(env, currState, goalState,
113 forbiddenBackAction, validBack,
124 std::vector<action> actions;
126 nodesTouched += actions.size();
128 for (
unsigned int x = 0; x < actions.size(); x++)
130 if (validBack && (actions[x] == forbiddenBackAction))
133 thePath.push_back(actions[x]);
135 double edgeCost = env->
GCost(goalState, actions[x]);
138 double childH = DoIteration(env, currState, goalState,
139 forbiddenForwardAction, validForward,
153 template <
class state,
class action>
155 double gCost,
double bound)
157 std::vector<action> actions;
193 if (forward < backward)
198 template <
class state,
class action>
200 double gCost,
double bound)
202 std::vector<action> actions;
203 std::vector<action> actions2;
210 for (
unsigned int x = 0; x < actions.size(); x++)
215 double firstCost = env->
GCost(currState, actions[x]);
217 for (
unsigned int y = 0; y < actions2.size(); y++)
219 if (actions[x] == actions2[y])
continue;
222 if (firstCost + gCost + env->
GCost(currState, actions[y]) + env->
HCost(currState, goalState) > bound)
224 if (firstCost + gCost + env->
GCost(currState, actions[y]) + env->
HCost(currState, goalState) == bound)
233 for (
unsigned int x = 0; x < actions.size(); x++)
244 if (gCost + env->
GCost(goalState, actions[x]) + env->
HCost(goalState, currState) > bound)
246 if (gCost + env->
GCost(goalState, actions[x]) + env->
HCost(goalState, currState) == bound)
253 if (forward > backward)
259 template <
class state,
class action>
262 if (!
fgreater(nextBound, currBound))
267 else if (
fgreater(fCost, currBound) &&
fless(fCost, nextBound))