dijkstra: dijkstra algorithm

Description Usage Arguments Value References Examples

View source: R/dijkstra.R

Description

This function uses dijkstra algorithms to find the shortest distance between two nodes in a graph. Starting from the init_node,the algorithm creates two sets for invisited nodes and visited nodes.To every node,set zero to init_node and infinity to other nodes. For the current node,calculate the distance to its neighbors and compare with the known distances,assign the shortest.Once after finding the shortest distance to a node,divide the node into visited set and set a new init_node.Reverse the step until all nodes are visited.

Usage

1
dijkstra(graph, init_node)

Arguments

graph

A data.frame.

init_node

A number.

Value

the shortest path to every other node from the starting node as a vector.

References

https://en.wikipedia.org/wiki/Dijkstra

Examples

1
2

rui0027/lab03 documentation built on Dec. 22, 2021, 8:12 p.m.