Skip to content

Commit 4f7013f

Browse files
committed
Added functionality to retrieve total cost of solution path
- Exposed the total cost of the discovered solution path through a getter function. This will be useful in cases where the total cost is needed for further processing.
1 parent 95bd539 commit 4f7013f

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

‎stlastar.h‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ template <class UserState> class AStarSearch
214214
// The user is going to use the Goal Node he passed in
215215
// so copy the parent pointer of n
216216
m_Goal->parent = n->parent;
217+
m_Goal->g = n->g;
217218

218219
// A special case is that the goal was passed in as the start state
219220
// so handle that here
@@ -513,6 +514,20 @@ template <class UserState> class AStarSearch
513514
return NULL;
514515
}
515516

517+
// Get final cost of solution
518+
// Returns FLT_MAX if goal is not defined or there is no solution
519+
float GetSolutionCost()
520+
{
521+
if( m_Goal && m_State == SEARCH_STATE_SUCCEEDED )
522+
{
523+
return m_Goal->g;
524+
}
525+
else
526+
{
527+
return FLT_MAX;
528+
}
529+
}
530+
516531
// For educational use and debugging it is useful to be able to view
517532
// the open and closed list at each step, here are two functions to allow that.
518533

0 commit comments

Comments
 (0)