Skip to content
Snippets Groups Projects
Commit 86488765 authored by Liuxi Mei's avatar Liuxi Mei
Browse files

UPDATE

parent 48db6487
No related branches found
No related tags found
2 merge requests!2Master,!1presetation
Pipeline #140502 failed
Package: Advanced_R_Group_Cooperation Package: Cooperation
Type: Package Type: Package
Title: Lab 3 exercise Title: Advanced R Group Cooperation
Version: 1.0 Version: 1.0
Date: 2024-09-12 Date: 2024-09-12
Author: Liuxi Mei Author: Liuxi Mei
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#' @param y second number #' @param y second number
euclidean <- function(x,y) { euclidean <- function(x,y) {
x <- abs(x)
y <- abs(y)
if (!is.numeric(x) | length(x) != 1){ if (!is.numeric(x) | length(x) != 1){
stop('pls check your input x') stop('pls check your input x')
} }
...@@ -38,6 +40,9 @@ init_node_distance_list <- function (init_node, graph) { ...@@ -38,6 +40,9 @@ init_node_distance_list <- function (init_node, graph) {
node_distance_list <- list(init_node = 0) node_distance_list <- list(init_node = 0)
# first, get all unqiue nodes # first, get all unqiue nodes
all_nodes <- unique(append(graph[,'v1'],graph[,'v2'])) all_nodes <- unique(append(graph[,'v1'],graph[,'v2']))
if (!init_node %in% all_nodes) {
stop('node is not in graph')
}
detail_frame <- data.frame(matrix(ncol=length(all_nodes),nrow = 3)) detail_frame <- data.frame(matrix(ncol=length(all_nodes),nrow = 3))
names(detail_frame) <- all_nodes names(detail_frame) <- all_nodes
row.names(detail_frame) <- c('is_best_node','node_distance','previous_node') row.names(detail_frame) <- c('is_best_node','node_distance','previous_node')
......
...@@ -7,4 +7,4 @@ ...@@ -7,4 +7,4 @@
#' \item{w}{the weight between node v1 and node v2} #' \item{w}{the weight between node v1 and node v2}
#' ... #' ...
#' } #' }
wiki_graph "wiki_graph"
\ No newline at end of file \ No newline at end of file
...@@ -18,6 +18,10 @@ update_detail_path( ...@@ -18,6 +18,10 @@ update_detail_path(
\item{init_node}{the start node in the algorithm} \item{init_node}{the start node in the algorithm}
\item{detail_frame}{to store the shorest path , if it is the best node and the related distance}
\item{graph}{the graph indicates the relationship of different nodes}
\item{checked_nodes}{the nodes that having found the shortest path} \item{checked_nodes}{the nodes that having found the shortest path}
\item{unchecked_nodes}{the nodes that having not found the shortest path} \item{unchecked_nodes}{the nodes that having not found the shortest path}
......
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/wiki_graph.R
\docType{data}
\name{wiki_graph}
\alias{wiki_graph}
\title{graph}
\format{
A data frame with 18 rows and 3 columns:
\describe{
\item{v1}{node name}
\item{v2}{node name}
\item{w}{the weight between node v1 and node v2}
...
}
}
\usage{
wiki_graph
}
\description{
graph
}
\keyword{datasets}
...@@ -7,6 +7,6 @@ ...@@ -7,6 +7,6 @@
# * https://testthat.r-lib.org/articles/special-files.html # * https://testthat.r-lib.org/articles/special-files.html
library(testthat) library(testthat)
library(Advanced_R_Group_Cooperation) library(Cooperation)
test_check("Advanced_R_Group_Cooperation") test_check("Cooperation")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment