In this example (please see picture), the Manhattan heuristic delays the path because of the unwalkable block west of the destination block.
My question is how can I fix this? Do I need to keep checking the blocks on the open list (the gray blocks) even after I found the destination? I might as well use dijkstra if I have to do that. Do I have to live with an imperfection like this if I go with a-star or is there a solution?
I have done my research on it and implemented my own algorithm that works exactly as the tutorials / articles on the web have explained, but I keep running into specific instances like this where a* fails to find the shortest path.
Your heuristic needs to be admissible but is not. Use Diagonal or Euclidean distance instead.
Related
The question itself is pretty simple... This is a vechicle routing problem.
I have a directed graph
I need to get a linear programming model that will somehow tell me the shortest circuit that visits all nodes, and starts and ends at the star. You are allowed to go over an edge more than once. A node is any crossing on the image.
We had like 4 hours of this in class, I have no idea where to even start...
I'm not expection anyone to give me the full model, but I was hoping someone would tell a strategy so I could do this.
Thank you in advance.
I would start from Dijkstra's algorithm for undirected graphs. There are some variants with similar or better performance. Take a look at https://en.wikipedia.org/wiki/Shortest_path_problem#Undirected_graphs, pick a choice, and keep us informed ... :)
The answer here seems to be very easy. (That is, very easy in theory, very hard and a lot of work to code in practice).
This seems like a straight-forward TSP (Travelling Salesperson Problem). Read about some general literature on TSP. You need to set up and solve a TSP where your nodes are the "cities" in a TSP. You also need to include your star as a city in the TSP.
The Dijkstra algorithm will not give you a solution. The Dijkstra algorithm is used for finding fastest/shortest paths between a node and other nodes in a (typically road-) network. However, distance-wise your problem is super-simple: Getting the cheapest travel cost (and path) from one node to another node in your problem is (almost) trivial.
If you are to solve this problem "for real" (not just discuss it), you need to acquire a TSP solver that is able to take your network (both edges and nodes) as input. Your input needs to specify which edges are directed and which are uni-directed. A lot of work in practice: Even if you use a tool, you still need to familiarize yourself with the tool.
Working on a recent project I wondered how to find a good/perfect path to a target that is moving with a steady speed. I tried standart A* pathfinding but it failed, since the heuristic will be wrong the more the object moves and I just canĀ“t find a way to make that work for me. Maybe you guys got another algorith that should work with just fine or some calculation tuning with A* that would work...
Thanks for your afford :)
A* should in general work, but then of course you need to recalculate every time the target moves. For 99% of cases, this is actually ok. For example, in video games you can get away with only recalculating the best path once every second or so, so it's generally not a huge performance hit.
However, if you really need something more powerful, check out Generalized Adaptive A*, an algorithm specifically designed to handle moving targets. And if you really want to be on the bleeding-edge, there are multiple adaptations of GAA* that are faster in certain cases - see this post (under "moving target points") for more details.
Using A* with a moving target is ok, but you must recalculate the whole path again. I don't think A* likes just having it's destination / goal changed.
Your A* needs to be very well optimised to run in real time and recalculate the new path every time the target moves.
Remember to play with your H to get a balance between working out the shortest path and the quickest to calculate. All depends on your map and obstructions really.
However A* may not be the best path finder for your application, but I'd need to see your map and more info..
I've been looking for a robust method of pathfinding for a platformer based game I'm developing and A* looks like it's the best method available. I noticed there is a demo for the AStar implementation in Godot. However, it is written for a grid/tile based game and I'm having trouble adapting that to a platformer where the Y axis is limited by gravity.
I found a really good answer that describes how A* can be applied to platformers in Unity. My question is... Is it possible to use AStar in Godot to achieve the same thing described in the above answer? Is it possible this could be done better without using the built in AStar framework? What is a really simple example of how it would work (with or without AStar) in GDscript?
Though I have already posted a 100 point bounty (and it has expired), I would still be willing to post another 100 point bounty and award it, pending an answer to this question.
you could repurpose the Navigation2D node for platformer purposes. The picture below shows an example usage. The Navigation2D node makes it possible to navigate the shortest path between two point that lie within the combined navigation polygon (this is the union of all NavigationPolygonInstances).
You can use the get_simple_path method to get a vector2 array that describes the points your agent/character should try to reach (or get close to, by using some predefined margin) in sequence. Place each point in a queue, and move the character towards the different points by moving it horizontally. Whenever your agent's next point in the queue is too high up to reach, then you can make the agent jump.
I hope this makes sense!
The grey/dark-blue rectangles are platforms with collision whereas the green shapes are NavigationPolygonInstance nodes
This approach is by no means perfect. If you were to implement slopes into your game then the agent may jump up the slope instead of ascending it normally. It is also pretty tedious to create all the shapes needed.
A more robust solution would be to have a custom graph system that you could place in the scene and position its vertices. This opens up the possibility to make one-way paths and have certain edges/connections between vertices marked as "jumpable" only. This is a lot more work though if you can not find any such solution online.
I want to start building an app for public transport. I know I should use Dijkstra as the algorithm to find the shortest path between two points.
How can I get more than one path? I would like to give the user at least 3 or 4 options, not only the best route. The reason is that I want to include more variables, time, cost and bus capacity.
Is there any algorithm that could help me to do this? Or naively I was thinking I should modify Dijkstra to give me more than one path.
Cheers.
have a look at K shortest path routing, a generalization of dijkstra.
I want to use a Genetic Algorithm for finding the shortest path within an undirected graph. I have two questions about this regarding Crossover and Mutation. I've been researching how crossover can be performed in similar situations to this, and the most popular algorithm out there seems to be PMX, my understanding of this is a partial path is swapped between 2 parent chromosomes to make the offspring. The issue I'm having with this is, there is massive scope for almost all of the offspring to become invalid isn't there? I was wondering if you could confirm this for me, and if I'm wrong, please correct me and explain it.
On separate but relevant note; I did have an idea for how to do this, but I don't know if its a good idea, simply select 2 parents where they share the same node in their path and crossover at that point, so all of the offspring remain valid.
My second issue is with Mutation; I have a general idea for how this can be done; would it be wise to select one node and remove it, and relink the path by an alternative means?
Thanks :)!
First of all you study about the cross over and mutation, because you said that you may loss some efficient parent, but it the concept of " Elitism " in genetic algorithm. that you should overcome by your proposed cross over method. because in cross over itself we are having n method to do, i suggest you to do second variation cross over order. This is not murphy's law, so try hard you will achieve.