Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build a Weighted Graph with Ruby's RGL or GRATR to perform Dijkstra's algorithm?

I would like to see an example of a Dijkastra search algorithm for a graph built using Ruby's RGL (http://rgl.rubyforge.org/) or GRATR (http://rubyforge.org/projects/gratr/).

I know GRATR has Dijkastra support but I'm not really sure how to go about using it, any help would be appreciated.

like image 995
Andres Avatar asked May 28 '10 13:05

Andres


People also ask

Is Dijkstra's algorithm with weighted graph?

Dijkstra's Algorithm can only work with graphs that have positive weights. This is because, during the process, the weights of the edges have to be added to find the shortest path. If there is a negative weight in the graph, then the algorithm will not work properly.

What is weight in Dijkstra algorithm?

The total weight of a path in a weighted graph is the sum of the weights of all the edges on the path. A path between two nodes that has minimum total weight is called a shortest path.

Is Dijkstra weighted?

Dijkstra's algorithm, published in 1959 and named after its creator Dutch computer scientist Edsger Dijkstra, can be applied on a weighted graph. The graph can either be directed or undirected. One stipulation to using the algorithm is that the graph needs to have a nonnegative weight on every edge.


1 Answers

One of these should help:

http://snippets.dzone.com/posts/show/7331
http://snippets.dzone.com/posts/show/6100
http://github.com/dbrady/dijkstra

This is an example of dijkstra in GRATR
http://gratr.rubyforge.org/svn/examples/graph_self.rb

like image 185
Kalyan Maddu Avatar answered Oct 19 '22 18:10

Kalyan Maddu