30 #define __STDC_CONSTANT_MACROS
36 #define UINT32_MAX 4294967295U
40 #include <unordered_map>
50 template<
typename state>
66 template <
class state>
81 template <
class state,
class action,
class environment>
86 void GetPath(environment *
env,
const state& from,
const state& to, std::vector<state> &thePath);
88 void GetPath(environment *,
const state& ,
const state& , std::vector<action> & ) { assert(
false); };
94 bool InitializeSearch(environment *
env,
const state& from,
const state& to, std::vector<state> &thePath);
160 template <
class state,
class action,
class environment>
163 static char name[32];
164 sprintf(name,
"EPEAStar[]");
179 template <
class state,
class action,
class environment>
183 if (!InitializeSearch(_env, from, to, thePath))
187 while (!DoSingleSearchStep(thePath)) {}
200 template <
class state,
class action,
class environment>
212 openClosedList.Reset();
218 if (env->GoalTest(from, to) && (stopAfterGoal))
223 openClosedList.AddOpenNode(start, env->GetStateHash(start), 0, weight*theHeuristic->HCost(start, goal));
234 template <
class state,
class action,
class environment>
237 openClosedList.AddOpenNode(newState, env->GetStateHash(newState), 0, weight*theHeuristic->HCost(start, goal));
245 template <
class state,
class action,
class environment>
248 openClosedList.AddOpenNode(newState, env->GetStateHash(newState), cost, weight*theHeuristic->HCost(start, goal));
261 template <
class state,
class action,
class environment>
264 if (openClosedList.OpenSize() == 0)
270 uint64_t nodeid = openClosedList.Peek();
271 const state &currOpenNode = openClosedList.Lookup(nodeid).data;
273 if (!openClosedList.Lookup(nodeid).reopened)
274 uniqueNodesExpanded++;
277 if ((stopAfterGoal) && (env->GoalTest(currOpenNode, goal)))
279 ExtractPathToStartFromID(nodeid, thePath);
281 reverse(thePath.begin(), thePath.end());
287 bool moreMoves = env->GetNextSuccessor(currOpenNode, goal, next,
288 openClosedList.Lookup(nodeid).h,
289 openClosedList.Lookup(nodeid).special,
293 openClosedList.Close();
300 else if (moreMoves) {
301 openClosedList.KeyChanged(nodeid);
305 double edgeCost = env->GCost(currOpenNode, next);
311 switch (openClosedList.Lookup(env->GetStateHash(next), theID))
321 if (
fless(openClosedList.Lookup(nodeid).g+edgeCost, openClosedList.Lookup(theID).g))
323 openClosedList.Lookup(theID).parentID = nodeid;
324 openClosedList.Lookup(theID).g = openClosedList.Lookup(nodeid).g+edgeCost;
325 openClosedList.KeyChanged(theID);
330 openClosedList.AddOpenNode(next,
331 env->GetStateHash(next),
332 openClosedList.Lookup(nodeid).g+edgeCost,
333 weight*theHeuristic->HCost(next, goal),
348 template <
class state,
class action,
class environment>
351 uint64_t key = openClosedList.Peek();
352 return openClosedList.Lookup(key).data;
366 template <
class state,
class action,
class environment>
368 std::vector<state> &thePath)
371 thePath.push_back(openClosedList.Lookup(
node).data);
372 node = openClosedList.Lookup(
node).parentID;
373 }
while (openClosedList.Lookup(
node).parentID !=
node);
374 thePath.push_back(openClosedList.Lookup(
node).data);
383 template <
class state,
class action,
class environment>
386 printf(
"%u items in closed list\n", (
unsigned int)openClosedList.ClosedSize());
387 printf(
"%u items in open queue\n", (
unsigned int)openClosedList.OpenSize());
397 template <
class state,
class action,
class environment>
400 return openClosedList.size();
413 template <
class state,
class action,
class environment>
417 dataLocation loc = openClosedList.Lookup(env->GetStateHash(val), theID);
420 gCost = openClosedList.Lookat(theID).g;
432 template <
class state,
class action,
class environment>
435 double transparency = 1.0;
436 if (openClosedList.size() == 0)
439 if (openClosedList.OpenSize() > 0)
440 top = openClosedList.Peek();
441 for (
unsigned int x = 0; x < openClosedList.size(); x++)
446 env->SetColor(1.0, 1.0, 0.0, transparency);
447 env->OpenGLDraw(data.
data);
451 env->SetColor(0.0, 0.5, 0.5, transparency);
452 env->OpenGLDraw(data.
data);
456 env->SetColor(0.0, 1.0, 0.0, transparency);
457 env->OpenGLDraw(data.
data);
461 env->SetColor(0.5, 0.0, 0.5, transparency);
462 env->OpenGLDraw(data.
data);
466 env->SetColor(1.0, 0.0, 0.0, transparency);
467 env->OpenGLDraw(data.
data);