Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
lab
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Liuxi Mei
lab
Commits
2971a28a
Commit
2971a28a
authored
8 months ago
by
Xiaochen Liu
Browse files
Options
Downloads
Patches
Plain Diff
corrected some mistakes in descriptions
parent
9c18f7e8
No related branches found
No related tags found
1 merge request
!2
Master
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
R/lab_3_submission.R
+9
-8
9 additions, 8 deletions
R/lab_3_submission.R
with
9 additions
and
8 deletions
R/lab_3_submission.R
+
9
−
8
View file @
2971a28a
#' Euclid
i
an algorithm to find the
#' Euclid
e
an 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 un
q
iue nodes
# first, get all uni
q
ue 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
fou
nd the shortest path
#' @param unchecked_nodes the nodes that having
not fou
nd 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 fi
nd the shortest path
#' @param unchecked_nodes the nodes that having
been tested to fi
nd the shortest path
#' @param detail_frame to store the shor
t
est 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
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment