9 #ifndef IncrementalDFID_h
10 #define IncrementalDFID_h
16 template <
class state,
class action>
22 std::vector<state> &thePath);
24 std::vector<state> &thePath);
26 std::vector<action> &thePath);
41 { p.clear();
for (
auto &i :
search) p.push_back(i.currState); }
63 std::vector<std::pair<state, double>>
history;
76 template <
class state,
class action>
80 if (InitializeSearch(e, from, to, h, thePath))
82 while (!DoSingleSearchStep(thePath))
86 template <
class state,
class action>
88 std::vector<action> &thePath)
93 template <
class state,
class action>
95 std::vector<state> &thePath)
101 thePath.push_back(from);
109 SetupIteration(h->
HCost(start, goal));
113 template <
class state,
class action>
117 search.back().currState = start;
118 search.back().status = kGoingDown;
119 search.back().pathCost = 0;
120 previousBound = bound;
125 newNodesLastIteration = newNodeCount;
129 template <
class state,
class action>
132 if (env->GoalTest(search.back().currState, goal) &&
flesseq(search.back().pathCost, bound))
136 for (
size_t x = 0; x < search.size(); x++)
137 path.push_back(search[x].currState);
141 if (search.back().status == kGoingDown)
143 double f = search.back().pathCost+h->HCost(search.back().currState, goal);
150 else if (
fless(f, nextBound))
162 search.back().status = kGoingAcross;
163 env->GetSuccessors(search.back().currState, search.back().succ);
165 for (
size_t x = 0; x < search.back().succ.size(); x++)
167 if (search.size() > 1 && search.back().succ[x] == search[search.size()-2].currState)
169 search.back().succ.erase(search.back().succ.begin()+x);
175 std::reverse(search.back().succ.begin(), search.back().succ.end());
179 if (search.back().status == kGoingAcross)
182 if (search.back().succ.size() == 0)
191 search.resize(search.size()+1);
192 auto &s = search[search.size()-2];
193 search.back().currState = s.succ.back();
194 search.back().status = kGoingDown;
195 search.back().pathCost = s.pathCost+env->GCost(s.currState, s.succ.back());
205 template <
class state,
class action>
209 if (IterationComplete())
211 SetupIteration(nextBound);
216 return StepIteration();
219 template <
class state,
class action>
222 for (
int x = 1; x < search.size(); x++)
224 env->DrawLine(display, search[x-1].currState, search[x].currState, 10);
228 template <
class state,
class action>
233 for (
int x = 1; x < search.size(); x++)
234 env->GLDrawLine(search[x-1].currState, search[x].currState, 10);