473,394 Members | 1,781 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

A* 15-puzzle return path

I have to write a program that returns the optimal path from the input 4x4 matrix to the solution of the 15-puzzle using A* algorithm (in C/C++).
Now, I managed to write a program that finds a solution to the 15-puzzle (although it's really slow for more complicated inputs, is that normal?), but I'm not sure how to return the optimal path.
I'm using a structure which consists of a 4x4 matrix and the cost of that matrix.
http://en.wikipedia.org/wiki/A*_search_algorithm
If you look at the pseudocode on that link, my openset and closedset are actually two lists of (the structure I defined)'s... Maybe I should have used something else instead of lists, but now it's too late and I don't have the time to code everything from the beginning. Anyway, I don't know how to remember the parent of/path to every node in my path. In the above link, the pseudocode suggests using a map of navigated nodes, but using maps in my situation would be messy because you have to define operators like <= because maps only work with something that has (weak?) ordering... And even if I define something like that (I actually tried that), the whole thing still doesn't work for me: If A is a member of the structure I defined, and I write something like map[A] = B and try to print out map[A], I won't get B.
Another thing I tried was adding a pointer to parent as a part of my structure, but for some reason that doesn't work either.
So, what do you suggest, how should I remember paths?
Sorry for not providing any snippets of code, ask me if you need some parts of it in order to respond to my question properly and I'll post them.
Thanks.
Oct 24 '11 #1
3 2533
weaknessforcats
9,208 Expert Mod 8TB
Use a stack. Push as you go and pop as you return.
Oct 24 '11 #2
Yeah, but WHEN should I push something on my optimal stack? I can't know that some node belongs to the optimal path until I reach the end (and that's when I have to recursively reconstruct the optimal path).

Anyway, I returned to the idea of having pointer_to_parent as a part of my structure and then reconstructing the path by printing last node, last node's parent, last node's parent's parent... The problem is: My program will print the last node's parent correctly, but last node's parent's parent and everything after that will be the same as last node's parent. :/

Again, sorry for not providing any code, but there's a lot of code and I have no idea in which part of it the problem lies.
Oct 24 '11 #3
Looks like I had some dangling pointers. =) Problem solved...
Oct 25 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Gerlow | last post by:
Hi When I am using a ASP SQL question to my Access 2000 db via IIS 5.0 and have the SELECT TOP 15 syntax in the SQL question I get 15 rows in my answer if a have many rows in the table, but if I...
2
by: Michelle | last post by:
Hello! I have an .aspx web form in an ASP .NET application that I need to Auto Save every 15 minutes. Could anyone provide examples of client-side Javascript to count down the 15 minutes? ...
38
by: | last post by:
I have a script... ----- <SCRIPT language="JavaScript" type="text/javascript"> <!-- function makeArray() { for (i = 0; i<makeArray.arguments.length; i++) this = makeArray.arguments; } ...
2
by: zhengfish | last post by:
Hi,All, I try to install mysql-5.0.15 on RHEL3-U5. But It give me a error. MySQL-client-standard-5.0.15-0.rhel3.i386.rpm MySQL-devel-standard-5.0.15-0.rhel3.i386.rpm...
4
by: serge | last post by:
I am running a query in SQL 2000 SP4, Windows 2000 Server that is not being shared with any other users or any sql connections users. The db involves a lot of tables, JOINs, LEFT JOINs, UNIONS...
9
by: martin1 | last post by:
Hi, All, My question is how to set up timer start 15 sec past minute. It always start 15 sec past minute. For example, if current time is 8:30:45, the timer starts on 8:31:15 am; if current...
1
by: Ruth413 | last post by:
Hello - I am getting the these errors in my sql 2005 generated script. I am stuck with first error. Please help.... Msg 102, Level 15, State 1, Line 3 Incorrect syntax near '('. Msg 319,...
1
by: Yammi | last post by:
Ok, I know that there is a very smart programmer out there that can resovle my issue. I am trying to calculate time worked by 15 minute intervals. Example: ================= Emp 1 started...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.