[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.0

Print out values from open & closed lists?

Asked by Arcyani in C++ Programming Language

Hello ..

I want to print out the "Node Index" from the Open list & the Closed list into the console.

What is an open & closed list?, I also presume I have to Cout in one of the loops in the code but this will most likely just spam the console and make it unreadable, anyone have any suggestions ? ^^
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:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
list<int> Level::planPathAStar(short currentX, short currentY, short goalX, short goalY, short debugMode)
{
	list<int> path; // Final path to be constructed
	list<graphNode> open; // List of open nodes to be explored
	list<graphNode> closed; // List of closed nodes which have been explored 
	int goalIndex; // Index of the goal node
	int currentIndex; // Index of the current node
	graphNode currentNode; // Current graph node  
	goalIndex = index(goalX, goalY); // Set goal node index
	currentIndex = index(currentX, currentY); // Set current node index 
	currentNode.index = currentIndex; // Set the index of the currentgraph node
	currentNode.parentIndex = -1; // Set the parent of the current node to NULL
	currentNode.score(0.0, currentX, currentY, goalX, goalY); // Score the current node 
	open.push_back(currentNode); // Put the current node on the open list  
	while(currentIndex != goalIndex)
	{
		open.sort(); // Sort the list of open node by list quality 
		currentNode = open.front(); // Take the node that scored best on the open list
		open.pop_front(); // Take it off the open list
		closed.push_back(currentNode); // Add that node to the closed list
		currentIndex = currentNode.index; // Set the current index 
		// Look in the adjacency matrix for connections to other nodes
		for(int otherIndex = 0; otherIndex < nNodes; otherIndex++)
		{	
			// Check for a connection
			if(adjacencyMatrix[currentIndex][otherIndex])
			{
				// If there is a connection 
				list<graphNode>::iterator graphListIter;
				bool onClosed = false;
				bool onOpen = false;
				
				// Find out whether it's on the closed list
				for(graphListIter = closed.begin();graphListIter != closed.end();++graphListIter)
				{
					if((*graphListIter).index == otherIndex)
					{
						// Found on closed list
						onClosed = true;
						// Check g value
						// If the current g value is less than that of the node found on the closed list
						// then update that nodes parent to the current node
						if(currentNode.g + 1.0 < (*graphListIter).g)
						{
							(*graphListIter).parentIndex = currentIndex;
						}
					}
				} 
				if(!onClosed)
				{
					// Find out whether it's on the open list list
					for(graphListIter = open.begin();graphListIter != open.end();++graphListIter)
					{
						if((*graphListIter).index == otherIndex)
						{
							// Found on closed list
							onOpen = true;
							// Check g values
							// If the current g value is less than that of the node found on the closed list
							// then update that nodes parent to the current node
							if(currentNode.g + 1.0 < (*graphListIter).g)
							{
								(*graphListIter).parentIndex = currentIndex;
							}
						}
					}
				} 
				if(!onClosed && !onOpen)
				{
					// It its not on open or closed
					graphNode tmpNode; 
					// Set the parent node to the curretn node
					tmpNode.parentIndex = currentIndex;
					// Set the node index to other index
					tmpNode.index = otherIndex;
					// Find the X and Y posiiton of that node
					inverseIndex(otherIndex,&currentX, &currentY);
					// Score the node
					tmpNode.score(currentNode.g, currentX, currentY, goalX, goalY);
					// Add it to the open list
					open.push_back(tmpNode);
				}
			}
		}
	} 
	// Reconstruct the path
	// Start with goal node working backwards towarsd the first node
	// We know that we're at the first node because it has a parent of -1
	int parent;
	list<graphNode>::iterator graphListIter; 
	currentNode = closed.back(); // Set the current node to goal node
	parent = currentNode.parentIndex; // Set parent to be the parent of the current node
	path.push_front(currentIndex); // Add the current node the the start of the path
	closed.pop_back(); // Remove the curretn node from the closed list 
	//Now work backwards throught the closed list reconstructing the path
	for(graphListIter = closed.end(), graphListIter--;graphListIter != closed.begin();--graphListIter)
	{
		currentNode = *graphListIter;
		if(currentNode.index == parent) // Fount the node
		{
			// Add it to the path
			path.push_front(parent);
			// Set parent to be this nodes parent
			parent = currentNode.parentIndex;
			// Remove this node from the closed list
			closed.erase(graphListIter);
			// Start working backward throguht the cloased list again from the end
			graphListIter = closed.end();
		}
	}
	return path;
}
[+][-]11/08/09 02:24 AM, ID: 25770036Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/08/09 07:27 AM, ID: 25770733Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/09/09 10:14 AM, ID: 25778448Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/09/09 05:42 PM, ID: 25781780Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: C++ Programming Language
Sign Up Now!
Solution Provided By: trinitrotoluene
Participating Experts: 2
Solution Grade: A
 
 
Loading Advertisement...
20091111-EE-VQP-89 - Hierarchy / EE_QW_3_20080625