Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This version of the algorithm always selects the first column. We need to make it
- # traverse all branches.
- algorithmX <- function(A) {
- for (c in 1:ncol(A)) {
- r <- which.min(A[,c])
- memory <- data.frame(LP_Number = colnames(A)[c],
- Visit_Number = rownames(A)[r],
- cost = as.numeric(A[r,c]))
- if (length(colnames(A))>1) {
- Ared <- A[-r, -c, drop=FALSE]
- return( rbind(memory, algorithmX(Ared)) )
- }
- else {
- return(memory)
- }
- }
- }
- foo <- c(8.95,3.81,1.42,1.86,4.32,7.16,12.86,7.59,5.47,2.12,
- 0.52,3.19,13.97,8.79,6.52,3.37,0.91,2.03)
- colnames(foo) <- paste0("col",c(1:3))
- rownames(foo) <- paste0("row",c(1:6))
- algorithmX(foo)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement