Skip to content
Snippets Groups Projects
Commit 2971a28a authored by Xiaochen Liu's avatar Xiaochen Liu
Browse files

corrected some mistakes in descriptions

parent 9c18f7e8
No related branches found
No related tags found
1 merge request!2Master
#' Euclidian algorithm to find the
#' Euclidean algorithm to find the
#' greatest common divisor of two numbers
#' @title euclidean algorithm
#' @param x first number
......@@ -31,18 +31,19 @@ euclidean <- function(x,y) {
#' @description init the detail table
#' @title initial the detail frame
#' @param init_node the start node to find the shortest path
#' @param graph the structure of the graph,
#' @param init_node the start node to find the shortest path, input should be one scalar of the graph
#' @param graph the structure of the graph, input should be data frame or matrix
#' eg:wiki_graph <- data.frame(v1=c(1,1,1,2,2,2,3,3,3,3,4,4,4,5,5,6,6,6),
#' v2=c(2,3,6,1,3,4,1,2,4,6,2,3,5,4,6,1,3,5),
#' w=c(7,9,14,7,10,15,9,10,11,2,15,11,6,6,9,14,2,9))
init_node_distance_list <- function (init_node, graph) {
node_distance_list <- list(init_node = 0)
# first, get all unqiue nodes
# first, get all unique nodes
all_nodes <- unique(append(graph[,'v1'],graph[,'v2']))
if (!init_node %in% all_nodes) {
stop('node is not in graph')
}
#built list and data frame for later comparison
detail_frame <- data.frame(matrix(ncol=length(all_nodes),nrow = 3))
names(detail_frame) <- all_nodes
row.names(detail_frame) <- c('is_best_node','node_distance','previous_node')
......@@ -58,11 +59,11 @@ init_node_distance_list <- function (init_node, graph) {
#' @description
#' the update method for detail table to record the shortest path
#' @title update the detail frame when traversing to a new node
#' @param node the current the node when traversing all the nodes to find the best way
#' @param node the current node when traversing all the nodes to find the best way
#' @param init_node the start node in the algorithm
#' @param checked_nodes the nodes that having found the shortest path
#' @param unchecked_nodes the nodes that having not found the shortest path
#' @param detail_frame to store the shorest path , if it is the best node and the related distance
#' @param checked_nodes the nodes that having been tested to find the shortest path
#' @param unchecked_nodes the nodes that having been tested to find the shortest path
#' @param detail_frame to store the shortest path , if it is the best node and the related distance
#' @param graph the graph indicates the relationship of different nodes
update_detail_path <- function(node,init_node,detail_frame,graph,checked_nodes,unchecked_nodes) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment