Skip to content

Very simple implementation of the Dijkstra algorithm in R language.

License

Notifications You must be signed in to change notification settings

sergioreyblanco/dijkstra_algorithm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Implementation of the Dijkstra Algorithm in R language

Here is a very simple implementation of the Dijkstra algorithm in R language.

An instance of this function execution with example1 is shown here:

alt text

The whole algorithm is implementated in the function dijkstraSolver. It is divided in three well diferenced steps: general initialization, first node initialization and processing of the rest of the nodes. Default, initial node is defined by a node that has no incident edges and the last node by a node that has no leaving edges.

The function takes as an input parameter a representation of a graph in the way of a matrix where each row is node and each cell in the row is related with the weight of the adjacent node of the current one (NA if the current one is not connected with it and an integer value if it is). The function gives a return value consisting of a list with two components in which the first is the optimal sequence of nodes from the first to the last one and the other is the cost of that route.

Example matrices are given (located in the last part of the code after the function), so you can test the function and create new graphs. The first example matrix will result in a graph like this one: alt text

The code does not need any additional libraries to run, besides the classical R environment.

About

Very simple implementation of the Dijkstra algorithm in R language.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages