15 #include <unordered_map>
22 template <
class state,
class action,
int buckets = 50,
bool verbose = true>
28 std::vector<action> &thePath);
41 action forbiddenAction, state &currState,
42 std::vector<action> &thePath,
double bound,
double g);
53 template <
class state,
class action,
int buckets,
bool verbose>
56 std::vector<action> &thePath)
60 solutionCost = DBL_MAX;
61 nodesExpanded = nodesTouched = 0;
70 std::vector<action> act;
74 double currBound = heuristic->HCost(from, to);
75 while (solution.size() == 0)
78 uint64_t oldNodes = nodesExpanded;
80 printf(
"Starting iteration with bound %f; %llu expanded, %llu generated\n", currBound, nodesExpanded, nodesTouched);
82 DoIteration(env, act[0], from, thePath, currBound, 0);
83 if (solution.size() != 0)
86 uint64_t newNodes = nodesExpanded-oldNodes;
87 uint64_t total = bucketCount[0];
88 double nextBound = currBound*(1.0+1.0/100.0);
89 for (
int i = 1; i < buckets; i++)
91 total+=bucketCount[i];
92 if (bucketCount[i] > 0)
93 nextBound = currBound*(1.0+
static_cast<double>(i)/100.0);
99 printf(
" Ending iteration next bound %f; %llu new exp %llu predicted\n", nextBound, newNodes, total);
100 currBound = nextBound;
106 template <
class state,
class action,
int buckets,
bool verbose>
108 action forbiddenAction, state &currState,
109 std::vector<action> &thePath,
double bound,
double g)
111 double h = heuristic->HCost(currState, goal);
114 unsigned int index = ((g+h)/bound-1)*100;
116 bucketCount[index]++;
126 printf(
"Improved solution to %1.5f\n", solutionCost);
131 std::vector<action> &actions = *actCache.getItem();
133 nodesTouched += actions.size();
135 int depth = (int)thePath.size();
137 for (
unsigned int x = 0; x < actions.size(); x++)
139 if ((depth != 0) && (actions[x] == forbiddenAction))
142 thePath.push_back(actions[x]);
143 double edgeCost = env->
GCost(currState, actions[x]);
145 action a = actions[x];
147 DoIteration(env, a, currState, thePath, bound, g+edgeCost);
151 actCache.returnItem(&actions);