PACMAN: a short path for eating all the dots - artificial-intelligence

I am trying to find a solution for the PACMAN problem of finding a short path (not the shortest, but a good one) that eats all the dots in a big maze. I've seen a lot of people talking about TSP, Dijsktra, BFS, A*. I don't think this is a TSP since I don't have to go back where I started and I can repeat node if I want. And I don't think Dijsktra, BFS and A* would help because I'm not looking for the shortest path and even if that was the case, it wouldn't give a answer in a reasonable time.
Could anyone give me hints on this? What kind of problem is this? Is this a kind of TSP? What kind of algorithms approach this problem in a efficient way? I'd appreciate any hints on implementation.

I take it you're trying to do contest where you find the shortest path in the big maze in under 30 seconds?
I actually did this last year for fun (my college class didn't do the contest). After weeks of research, I was able to do an exact solution of the maze in under 30 seconds.
The heuristic I used was actually an exact heuristic. I wrote a bunch of code to find the minimal path length using a much more efficient algorithm based on graph decomposition and dynamic programming, and then fed the results back into A* as the 'heuristic' value.
The key thing to realize is that while the graph is very big (273 nodes), it has a low carving width (5), meaning that it can be solved efficiently using a fixed parameter tractable algorithm.
Hopefully that's enough keywords to get you on the right track.
Update: I wrote a blog post explaining the solution

Related

why DFS is not optimal but BFs is optimal

I have this question in my mind for long but never got reasonable answer for that :
Usually in artifitial intelligent course when it comes to search it is always said that BFS is optimal but DFS is not but I can come up with many example that shows with DFS we can even get the answer faster. So can anyone explain it ? Am I missing something?
Optimal as in "produces the optimal path", not "is the fastest algorithm possible". When searching a state space for a path to a goal, DFS may produce a much longer path than BFS. Note that BFS is only optimal when actions are unweighted; if different actions have different weights, you need something like A*.
This is because by optimal strategy they mean the one whose returned solution maximizes the utility.
Regarding this, nothing guarantees that the first solution found by DFS s optimal. Also BFS is not optimal in a general sense, so your statement as-is is wrong.
The main point here is about being guaranteed that a certain search strategy will always return the optimal result. Any strategy might be the best in a given case, but often (especially in AI), you don't know in what specific case you are, at most you have some hypothesis on that case.
However, DFS is optimal when the search tree is finite, all action costs are identical and all solutions have the same length. However limitating this may sound, there is an important class of problems that satisfies these conditions: the CSPs (constraint satisfaction problems). Maybe all the examples you thought about fall in this (rather common) category.
You can refer to my answer to this question in which I explain why DFS is not optimal and why BFS is not the best choice for solving uninformed state-space search problems.
You can refer to the link below it considers an eg of a tree and solves it with both the approaches.
link

Search Algorithm for Pacman

I need to find the path with the lower cost in a graph represented by a matrix. I researched a bit on the Dijkstra's algorithm but I need a vector with the sequence of nodes in the shortest path, not the distance itself. The game is being made ​​for Assembly, but if anyone knows an implementation in C at least it's gonna help a lot. I will use it to calculate the route of ghosts, matching heuristic algorithms to create the Very Hard Mode of the game. I also tried something with A*, but the implementations I found used struct, which are not applicable to the situation. Thanks a lot since now. ^^
This problem is the basis for the edx AI course. I've managed to google a breadth first search code written in C here. From what I can remember breadth first search is guarenteed to find the shortest path if it exists.
I don't think it would be too hard to add a heuristic algorithm in there either, there should be notes on the edx link that would help with that.

C spell checking, string concepts, algorithms

this is my first question on stack overflow. Some quick background, this is not for a school project, just for fun and practice and learning. I'm trying to make a spell checker in C. The problem I'm having is coming up with possible words to replace a misspelled word.
I should also point at that in my courses we haven't gotten to higher level programming concepts like time complexity or algorithm development. I say that because I have a feeling there are names for the concepts I'm really asking about, I just haven't heard of them yet.
In other similar posts here most people suggest using the levenshtein distance or traversing patricia trees; would it be a problem to just compare substrings? The (very much inefficient) algorithm I've come up with is:
compare the first N characters, where N = length of the misspelled word - 1, to dictionary words (they would be read from a system file into a dynamically allocated array)
if N characters from the misspelled word and a word from a dictionary match, add it to a list of suggestions; if no more matches are found, decrement N
continue until 10 suggestions are found or N = 0
It feels clunky and awkward, but it's sort of how our textbook suggests approaching this. I've read wiki articles on traversing trees and calculating all kinds of interesting things for efficiency and accuracy, but they're over my head at this point. Any help is appreciated, and thank you for taking the time to read this.
Modern computers are fast, really fast. It would be worthwhile for you to code this up using the algorithm you describe, and see how well it works for you on your machine with your dictionary. If it works acceptably well, then great! Otherwise, you can try to optimise it by choosing a better algorithm.
All the fancy algorithms you read about have one or both of the following goals:
Speed up the spell checking
Offer better suggestions for corrections
But that's only important if you're seriously concerned about performance. There's nothing wrong with writing your own code to do this. It may not be great, but you'll learn a lot more than jumping in and implementing an algorithm you don't understand yet.

IDA* with 15-puzzle, help needed

I have to make a visualisation of the IDA*(iterative deepening A star) algorithm when it is running a 15-puzzle problem. Exactly, I need to visualize the tree and the puzzle.
IDA* algorithm is similar to the A* algorithm. link 1 2 3
There are 3 things I need to implement:
1)The IDA* code.
2)After that, the IDA* connected with the problem(15-puzzle).
3)And, after that, I need to visualize the tree of the algorithm.
But I believe that someone before must have implemented the code for the IDA* running the 15-puzzle problem. I need your help to find this source code so that I would not spent 2 months writing code that has been written by someone else before, so that I would have time to focus on the visualization.
15-puzzle link 1 , link 2
I know some C,C++ and C#.
I need a simple source code, that I would comprehend, in which you input a table as a puzzle and it gives you back as a table with the solved puzzle.
Secondly, what programming language from the 3 above do you suggest me to use for the visualization?
I have found some implementations:
IDA* in LISP
A* in C++, I need IDA*
IDA* in java
IDA* in pheudocode link1 link2 link3
IDA* in C
IDA* with 15-puzzle
15-puzzle solved in an applet
A* and IDA* that solves Sliding puzzle (This one uses templates that aren't defined)
IDA* takes approximately ten minutes to implement. Your heuristic function is trivial, I guess you at least manage to implement manhattan distance (there are better heuristics, but this'll do).
Then you simply implement A* and then add the cut-off limit criteria. The Wikipedia article you link to even has an implementation in Python you simply can translate.

Building a suffix tree for a string matching algorithm in large database

I had an internship interview last week and I was given a question regarding searching for a particular string in a large database. I was totally clueless about it during the interview though I just gave a reply the"multi-level hashing" as that was the only hin I knew which had the best time efficiency, After a bit googling I think the answer he expected was that of suffix tree. Now during my search I found my algorithms for building suffix trees and there were even research papers on how to build suffix tree!! So is it really possible to implement the suffix tree for string matching algorithm especially during interview time?
It would be great if someone can throw light on it.
Thanks in advance
Usually the interviewer don't need a precise answer for these kind of questions, they're more interested in the way you think about the problem and try to solve it.
Of course, mentioning known algorithms to solve the problem would be a plus, but I find it hard to believe that someone would require "suffix tree" as an answer for that question.
That being said, I don't consider the algorithms to build suffix trees trivial to implement.

Resources