I had this laying around from 10th grade lol, releasing random codes now.
So what is Dijkstra`s algorithm? It calculates the shortest path from one node to all the other nodes in a weighted graph. For node-to-node paths use the A* algorithm instead, if you need the path from every node to every node, use Roy-Floyd or Floyd-Warshall algorithm.
The code reads a weighted graph from a file format that looks like this...
NUMBER_OF_NODES
edgelength(0,0) edgelength(0,1) ... edgelength(0,n)
...
edgelength(n,0) ... edgelength(n,n)
edgelength(x,y) equals the length of the edge if there is an edge between the nodes, and 0 if there isn`t an edge (or x=y)
Here`s a video of how it works:
So what is Dijkstra`s algorithm? It calculates the shortest path from one node to all the other nodes in a weighted graph. For node-to-node paths use the A* algorithm instead, if you need the path from every node to every node, use Roy-Floyd or Floyd-Warshall algorithm.
The code reads a weighted graph from a file format that looks like this...
NUMBER_OF_NODES
edgelength(0,0) edgelength(0,1) ... edgelength(0,n)
...
edgelength(n,0) ... edgelength(n,n)
edgelength(x,y) equals the length of the edge if there is an edge between the nodes, and 0 if there isn`t an edge (or x=y)
Here`s a video of how it works:
|
[Only registered and activated users can see links. Click Here To Register...]
02/09/2015 09:59
Xio.#2
Re-Implemented in C#. Was kinda slow so I had to stackalloc the array.
Using it for Co2 pathfinding from A to B on the same map (not mobs, more like a GPS) and it completes from Warehouse man to Mine Teleporter in 161ms (Twin City) I'm satisfied. It also appears to be very close to the Pathfinding algo used in the client. It's almost always aligned. I'm spawning squamas on each node so I can compare that :D
02/09/2015 11:01
werdi9#3
I program in C ++ so it can help you something?
02/09/2015 12:10
KraHen#4
I think that it would be way better if you used this for map-to-map travels (the nodes being the maps), and on the same map A* would probably yield better results. Then again, I`m happy if you`re happy with the results. :)
02/09/2015 14:48
Xio.#5
I used A* before, it's faster for short paths but it tends to have too much "noise" in it.. I don't know if that made sense.. Lets say the path is like Start-------------------------End (a straight line) A* would end up having useless 1 node turns in it like: Start--------___-----_-----------_---End While Dijkstra does exactly what it should. A straight line: Start-------------------------End If i play around with the cost and heuristics it ends up being way slower than Dijkstra's approach in many cases. A* is faster for < 35 nodes but since I expect a min. of 80 nodes for my case of use, I'll stick with Dijkstra for now :) Thanks for your suggestion though! <3
02/10/2015 12:01
KraHen#6
Well, yes, A* is a heuristic search, hence it won`t always yield the absolute very best, but a close approximation, putting more focus on efficiency. Also, is that a problem? I mean you have to split that path in jump points anyway, so does it really matter? Or are you using it for walk/run only (ex. mobs)?
A* will also produce a straight line if you implement tie-breaking.
02/10/2015 21:33
Xio.#7
I'm using it to display every step they need to take. It will put a squama on every tile thats in the path. It's used for more complex quests where they have to talk to npcs that may be really far away or on different maps, so it shows them the way. Conquer GPS basically :D |