Advertisement
Guest User

fizykklika

a guest
Jun 24th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1.  
  2.  
  3. nr_of_players <- 10 #Tutaj nasze ustalone G - wielkość grafu w wierzchołkach
  4.  
  5. #Tutaj graf do testowania
  6. # |
  7. # v
  8.  
  9. main_adj_matrix <- rbind(c(0,1,1,0,1,1,0,0,0,0),c(1,0,1,1,1,1,0,0,0,0),c(1,1,0,0,1,1,1,0,0,0)
  10. ,c(0,1,0,0,0,0,0,1,0,0),c(1,1,1,0,0,1,0,1,0,0),c(1,1,1,0,1,0,0,0,1,0)
  11. ,c(0,0,1,0,0,0,0,0,1,0),c(0,0,0,1,1,0,0,0,0,1),c(0,0,0,0,0,1,1,0,0,1)
  12. ,c(0,0,0,0,0,0,0,1,1,0))
  13.  
  14.  
  15.  
  16. N <- 5
  17.  
  18. #Tworzenie macierzy kodów
  19.  
  20. nr_of_codes <- 2**(nr_of_players)
  21. emergency_counter <- 1
  22.  
  23. temp_adj_matrix <- main_adj_matrix
  24.  
  25. code_vector <- c(1:nr_of_codes)
  26. full_code_matrix <- matrix(0,nr_of_codes,nr_of_players)
  27.  
  28. for (i in code_vector){ #Pełna macierz kodów
  29. full_code_matrix[i,] <- rev(number2binary(i,nr_of_players))
  30. }
  31.  
  32.  
  33. #Redukcja macierzy kodów
  34.  
  35. reducer <- 0
  36.  
  37. for (i in code_vector){
  38. if(length(which(full_code_matrix[i,]==1))==N){
  39.  
  40. }
  41. else{
  42. reducer <- append(reducer,-i)
  43. }
  44.  
  45. }
  46.  
  47. reducer <- reducer[-1]
  48. if (length(reducer)>0)
  49. reduced_code_matrix <- full_code_matrix[reducer,]
  50.  
  51. qlique_found <- FALSE
  52. to_break <- FALSE
  53. reduced_code_vector <- c(1:nrow(reduced_code_matrix))
  54. ones_N <- replicate(N,1)
  55.  
  56. #Szukam kliki
  57.  
  58. for (i in reduced_code_vector){
  59. indices_vector <- which(reduced_code_matrix[i,] %in% c(1))
  60. temp_sub_matrix <- main_adj_matrix[indices_vector,indices_vector]
  61. temp_sub_matrix <- temp_sub_matrix + diag(N)
  62.  
  63. for(j in nrow(temp_sub_matrix))
  64. if(all(temp_sub_matrix[j,]==ones_N)){
  65. qlique <- indices_vector
  66. qlique_found <- TRUE
  67. to_break <- TRUE
  68. break
  69.  
  70. }
  71. if(isTRUE(to_break)) break
  72. emergency_counter <- emergency_counter + 1
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement