9

okay, so i have a program with an arbitrary number of nodes. each nodes is connected to an arbitrary number of nodes. how can i find the shortest path between two nodes efficiently?

also, im thinking of gpgpu to speed this up, what do you guys think?

Comments
  • 2
    Are there nodes that have access to other modes that some don’t? Is there some kind of metric to decide whether or not a path is more efficient than the other (latency)?
  • 2
    Not 100% sure what you mean by node, not really my area of development. But maybe you could somehow adapt the A* pathfinding algorithm ?
  • 1
    Depth First Search (Kappa)
  • 1
    @Andrian was about to say this too.
  • 2
    @host127001 I thought it was Breadth First Search for finding Shortest path? I could be wrong....
  • 2
    Assign a weight of 1 to each edge. And then use BFS. If edges have different weights, like node A to B takes longer than node A to C plus C to B, then you'd need dijkstra.
    Look them up on Youtube and there should be plemty of examples on github. This is all assuming there are no negative weighted edges.
  • 1
    @billgates it is. My comment wasn't serious
  • 0
    As @Andrian said, it seems a perfect case for Dijkstra's algorithm.
  • 0
    Sinatra would solve this, but A* (a-star) is a bit more efficient. It's also possible to improve it with parallel computing
  • 1
    @cachoputa doesn't A* require a direction?
  • 0
    @cachoputa OH FUCK I meant "Dijkstra" and not "Sinatra" wtf

    And @Wack, it needs to know where the start and end nodes are in space (the coordinates) so it can know the distance
  • 1
    @cachoputa since that information isn't (nessesary) provided, I'd go with a BFS here
Add Comment