-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSearchBase.cpp
49 lines (40 loc) · 1.17 KB
/
SearchBase.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
* (C) 2014 Douglas Sievers
*
* SearchBase.cpp
*/
#include <iostream>
#include <stack>
#include "SearchBase.h"
SearchBase::SearchBase(Graph& g) : graph(g)
{
// empty constructor
}
void SearchBase::printSolution() const
{
//build out the solution...
// maybe this is a do...while
//
stack<nodePtr> solnNodePtrStack;
nodePtr currentNodePtr = goalNodePtr;
solnNodePtrStack.push(goalNodePtr);
while (! (currentNodePtr->getParentNode().expired()) )
{
nodePtr nextNode = currentNodePtr->getParentNode().lock();
solnNodePtrStack.push(nextNode);
currentNodePtr = nextNode;
};
cout << "\nResult\n------\n";
while (solnNodePtrStack.top().get() != goalNodePtr.get())
{
currentNodePtr = solnNodePtrStack.top();
cout << "From " << currentNodePtr->getNodeID();
solnNodePtrStack.pop();
currentNodePtr = solnNodePtrStack.top();
edgePtr solnEdge = currentNodePtr->getParentAction().lock();
cout << ", take route " << solnEdge->getEdgeID()
<< " for " << solnEdge->getEdgeCost() << "km to "
<< currentNodePtr->getNodeID() << endl;
}
cout << "\nTotal distance is " << goalNodePtr->getPathCost() << "km\n\n";
}