22 #ifndef __dgPathFinder__ 23 #define __dgPathFinder__ 32 #define DG_MAX_PATH_ENUMERATION_CHILDREN 128 34 template<
class NODEID,
class COST>
38 COST m_NodeCostToGoal;
39 COST m_NodeCostFromSource;
49 template<
class NODEID,
class COST>
56 template<
class NODEID,
class COST>
67 template<
class NODEID,
class COST>
72 dgPathFinder(dgInt32 maxElementsInOpenList, dgInt32 nodeMaxChildren);
79 virtual COST GetEstimatedCostToGoal(NODEID
id)
const;
80 virtual dgInt32 EnumerateChildren(NODEID parent, NODEID array[])
const;
86 template<
class NODEID,
class COST>
90 template<
class NODEID,
class COST>
96 template<
class NODEID,
class COST>
102 template<
class NODEID,
class COST>
108 template<
class NODEID,
class COST>
110 dgInt32 maxElementsInOpenList,
111 dgInt32 nodeMaxChildren)
113 m_openList(maxElementsInOpenList) {
114 maxChildren = nodeMaxChildren;
118 template<
class NODEID,
class COST>
122 template<
class NODEID,
class COST>
125 dgInt32 heapMaxCount;
131 NODEID idArray[DG_MAX_PATH_ENUMERATION_CHILDREN];
140 cell.m_NodeCostFromSource = COST(0);
141 cell.m_NodeCostToGoal = GetEstimatedCostToGoal(cell.m_Id);
143 node = close.Insert(cell, source);
145 heapMaxCount = m_openList.GetMaxCount();
146 m_openList.Push(node, cell.m_NodeCostFromSource + cell.m_NodeCostToGoal);
147 while (m_openList.GetCount()) {
148 node = m_openList[0];
150 if (parent.m_Id == goal) {
163 count = EnumerateChildren(node->GetKey(), idArray);
164 cell.m_Next = &parent;
165 for (
int i = 0; i < count; i ++) {
167 cell.m_Id = idArray[i];
169 COST newCostFromSource(GetCostFromParent(cell) + parent.m_NodeCostFromSource);
170 node = close.Insert(cell, cell.m_Id, state);
173 if (newCell.m_NodeCostFromSource <= newCostFromSource) {
179 newCell.m_NodeCostFromSource = newCostFromSource;
180 newCell.m_NodeCostToGoal = GetEstimatedCostToGoal(newCell.m_Id);
181 if (m_openList.GetCount() >= heapMaxCount) {
182 m_openList.Remove(heapMaxCount);
184 m_openList.Push(node, newCell.m_NodeCostFromSource + newCell.m_NodeCostToGoal);
190 template<
class NODEID,
class COST>
195 template<
class NODEID,
class COST>
200 template<
class NODEID,
class COST>
Definition: dgPathFinder.h:29
Definition: dgPathFinder.h:57
Definition: dgPathFinder.h:35
Definition: dgPathFinder.h:50