Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. # This version of the algorithm always selects the first column. We need to make it
  2. # traverse all branches.
  3. algorithmX <- function(A) {
  4. for (c in 1:ncol(A)) {
  5. r <- which.min(A[,c])
  6. memory <- data.frame(LP_Number = colnames(A)[c],
  7. Visit_Number = rownames(A)[r],
  8. cost = as.numeric(A[r,c]))
  9. if (length(colnames(A))>1) {
  10. Ared <- A[-r, -c, drop=FALSE]
  11. return( rbind(memory, algorithmX(Ared)) )
  12. }
  13. else {
  14. return(memory)
  15. }
  16. }
  17. }
  18.  
  19. foo <- c(8.95,3.81,1.42,1.86,4.32,7.16,12.86,7.59,5.47,2.12,
  20. 0.52,3.19,13.97,8.79,6.52,3.37,0.91,2.03)
  21. colnames(foo) <- paste0("col",c(1:3))
  22. rownames(foo) <- paste0("row",c(1:6))
  23. algorithmX(foo)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement