-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AStar add #45
base: master
Are you sure you want to change the base?
AStar add #45
Conversation
What are pros of AStar method ? |
AStar can increase performance of the pathfinding algorithm (Video example) Note: Since I made this request I have made additional commits to my master branch. If you wish to add AStar to your master, make sure to either reject the unrelated changes if possible, I can submit a new pull request omitting the unrelated commits, or change my master branch to only include the AStar add commit |
Hi, really nice feature. Could you provide more refinement to your contribution ? I prefer to keep graph data stracture still immutable. Instead modify NodeComparer would be better just extend it by inheritance. Why we need to expose herusitc method to be public ? Is it posible to have default implementation ? |
Thanks! Dijkstra's algorithm is a special case of the AStar algorithm when it has null heuristic, so the default implementation of AStar is Dijkstra's algorithm.
In this implementation AStar requires a heuristic, because Dijkstra should be used for Dijkstra. Optionally, I could allow null heuristic in AStar which would perform Dijkstra's algorithm. In that case it might be worth considering removing Dijkstra if you do not want redundancy, but it might be confusing to have no Dijkstra in Dijkstra.NET public static ShortestPathResult GetShortestPath(IDijkstraGraph graph, uint from, uint to, int depth, Func<uint, uint, int> heuristic = null)
{
var path = new Dictionary<uint, uint>();
var distance = new Dictionary<uint, int> {[from] = 0};
var d = new Dictionary<uint, int> {[from] = 0};
var comparer = heuristic is null ? new NodeComparer(distance) : new HeuristicNodeComparer(distance, heuristic);
var q = new SortedSet<uint>(new[] {from}, comparer);
var current = new HashSet<uint>();
... |
Now, it looks much better. Could you provide unit tests as well ? Then we will be certain about reliabilty your solution. |
Not sure if you want this included in the project, but it's a simple addition that can be very useful