A* implemented in C - c

Where can I find an A* implementation in C?
I was looking around but it seems my google-fu is not strong enough. I've started writing my own implementation, but then I remembered Stack Overflow and I thought I should ask here first. It seems a bit complicated to write a real A* implementation - I was tempted to just write an implementation of Dijkstra's algorithm for a binary grid, since that's all I really need, but I feel like I want to have a C A* implementation in my repertoire.

Your google-fu is indeed weak, young padawan :-)
Try googling for astar c.
The first and second links are actual code implementations (the first under a liberal MIT licence, no idea about the second).

here you can find the pseudocode: http://en.wikipedia.org/wiki/A*
to find the right code for you just search after:
astar graph search algorithm C

Related

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.

PACMAN: a short path for eating all the dots

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

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.

Writing expressions: Infix, Postfix and Prefix

My task is to write an app(unfortunatly on C) which reads expression in infix notation(with variables, unary and binary operators) and store it in memory, then evaluate it. Also, checks for correctness should be performed.
for example:
3*(A+B)-(-2-78)*2+(0*A)
After I got all values, program should calculate it.
The question is:
What is the best way to do this?(with optimization and validation)
What notation to choice as the base of tree?
Should I represent expression as tree? If so I can easily optimize it(just drop nodes which returns 0 or smth else).
Cheers,
The link suggested in the comment by Greg Hewgill above contains all the info you'll need:
If you insist on writing your own,
a recursive descent parser is probably the simplest way to do it by hand.
Otherwise you could use a tool like Bison (since you're working in C). This tutorial is the best I've seen for working with Flex and Bison (or Lex/Yacc)
You can also search for "expression evaluator" on Codeproject - they have a lot of articles on the topic.
I came across the M4 program's expression evaluator some time ago. You can study its code to see how it works. I think this link on Google Codesearch is the version I saw.
Your question hints at requirements being put on your solution:
unfortunatly on C
so some suggestions here might not be permissible. Nevertheless, I would suggest that this is quite a complicated problem to solve, and that you would be much better off trying to find a suitable existing library which you could link into your C code to do this for you. This would likely reduce the time and effort required to get the code working, and reduce the ongoing maintenance effort. Of course, you'd have to think about licensing, but I'd be surprised if there wasn't a good parsing/evaluation library "out there" which could do a good job of this.

Resources