a-star

AI: Fastest algorithm to find if path exists?

老子叫甜甜 提交于 2019-12-04 02:58:31
I am looking for a pathfinding algorithm to use for an AI controlling an entity in a 2D grid that needs to find a path from A to B. It does not have to be the shortest path but it needs to be calculated very fast. The grid is static (never changes) and some grid cells are occupied by obstacles. I'm currently using A* but it is too slow for my purposes because it always tries to calculate the fastest path. The main performance problem occurs when the path does not exist, in which case A* will try to explore too many cells. Is there a different algorithm I could use that could find a path faster

A-star algorithm

廉价感情. 提交于 2019-12-04 02:43:13
I'm having issues with my A-star implemention. It does find path from my point A to B but not if the terrain is more 'complex', then my Find() function seems to not be ending. For instance, it does work on the 20 x 20 array here but if you add a square ('#') in the bottom to the most-right obstacle/wall then it fails. I hope someone can point out any mistakes I'm doing. Here's my code: #include <iostream> #include <string> #include <cmath> #include <vector> #include <utility> #include <algorithm> #include <queue> using namespace std; class CNode { public: CNode() : xPos(0), yPos(0), travelCost

AStar - explanation of name

て烟熏妆下的殇ゞ 提交于 2019-12-04 01:53:28
I am looking for an explanation why the AStar / A* algorithm is called AStar. All similar (shortest path problem) algorithms are often named like its developer(s), so what is AStar standing for? There were algorithms called A1 and A2. Later, it was proved that A2 was optimal and in fact also the best algorithm possible, so he gave it the name A* which symbolically includes all possible version numbers. Source: In 1964 Nils Nilsson invented a heuristic based approach to increase the speed of Dijkstra's algorithm. This algorithm was called A1. In 1967 Bertram Raphael made dramatic improvements

A* Pathfinding in a hexagonal grid

 ̄綄美尐妖づ 提交于 2019-12-03 22:39:56
Can anyone point me to a simple example that implements A* path-finding algorithm on a hexagonal grid (in JS). I have made it working on a square grid, however all my attempts to make it work on a hexagonal grid have failed. This is how my grid looks like: I'm using the same technique to both draw the grid and generate coordinates as seen in this topic . Here's the grid coords data along with the start, end coords: [0, 0] , [0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [1, 3], [2, 0], [2, 1], [2, 2], [2, 3], [2, 4], [3, 0], [3, 1], [3, 2], [3, 3], [4, 0], [4, 1], [4, 2] start_point: [0,2] end_point:

How to set target vertex in QuickGraph Dijkstra or A*

丶灬走出姿态 提交于 2019-12-03 17:16:24
I am using QuickGraph version 3.6 and I found function SetRootVertex, but no SetTagretVertex. I need this because I am searching short paths in huge graph and this would speed up program a lot. Clases in question are DijkstraShortestPathAlgorithm and AStarShortestPathAlgorithm. I don't think there is a way to this without using events. You could wrap the necessary code in one extension method, making things clear, e.g.: public static class Extensions { class AStarWrapper<TVertex, TEdge> where TEdge : IEdge<TVertex> { private TVertex target; private AStarShortestPathAlgorithm<TVertex, TEdge>

Why A* is faster if i use 4xManhattan Distances as Heuristic for 15-Puzzle

♀尐吖头ヾ 提交于 2019-12-03 16:21:52
I have implemented an A* algorithm for solving the 15-puzzle. I made a research for finding some viable or admissible heuristics, looking for a fast solution, and i find that using 4*Manhattan Distance as heuristic always solve any 15-puzzle in less than a second. I tried this and effectively works. I tried to find a answer for that but i cant find it. Any one can explain this? 4* manhattan distance is not admissible heuristic, this makes the algorithm behave "closer" to greedy best first (where the algorithm chooses which node to develop solely based on the heuristic function). This makes the

Finding minimum cut-sets between bounded subgraphs

我与影子孤独终老i 提交于 2019-12-03 12:23:53
If a game map is partitioned into subgraphs, how to minimize edges between subgraphs? I have a problem, Im trying to make A* searches through a grid based game like pacman or sokoban, but i need to find "enclosures". What do i mean by enclosures? subgraphs with as few cut edges as possible given a maximum size and minimum size for number of vertices for each subgraph that act as a soft constraints. Alternatively you could say i am looking to find bridges between subgraphs, but its generally the same problem. Example Gridbased gamemap example http://dl.dropbox.com/u/1029671/map1.jpg Given a

A* Search Algorithm

霸气de小男生 提交于 2019-12-03 11:21:36
I would like to have something clarified with regards to the following A* Search example: The sections highlighted with the red ellipses are the areas that I do not understand; it appears that {S,B} f=2+6=8 has been taken/moved/copied from Expand S (above) and used in Expand A . It also appears that {S,A,X} f=(1+4)+5=10 has been taken/moved/copied from Expand A and used in Expand B . Could somebody kindly explain why this happens? I am able to read the graph perfectly well and do not have any trouble interpreting it - it is merely the fact that I do not know why the aforementioned paths/routes

Why is the complexity of A* exponential in memory?

旧街凉风 提交于 2019-12-03 09:36:55
问题 Wikipedia says on A* complexity the following (link here): More problematic than its time complexity is A*’s memory usage. In the worst case, it must also remember an exponential number of nodes. I fail to see this is correct because: Say we explore node A, with successors B, C, and D. Then we add B, C, and D to the list of open nodes, each accompanied by a reference to A, and we move A from the open nodes to the closed nodes. If at some time we find another path to B (say, via Q), that is

Manhattan Heuristic function for A-star (A*)

前提是你 提交于 2019-12-03 09:04:30
I found this algorithm here . I have a problem, I cant seem to understand how to set up and pass my heuristic function. static public Path<TNode> AStar<TNode>(TNode start, TNode destination, Func<TNode, TNode, double> distance, Func<TNode, double> estimate) where TNode : IHasNeighbours<TNode> { var closed = new HashSet<TNode>(); var queue = new PriorityQueue<double, Path<TNode>>(); queue.Enqueue(0, new Path<TNode>(start)); while (!queue.IsEmpty) { var path = queue.Dequeue(); if (closed.Contains(path.LastStep)) continue; if (path.LastStep.Equals(destination)) return path; closed.Add(path