Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- nr_of_players <- 10 #Tutaj nasze ustalone G - wielkość grafu w wierzchołkach
- #Tutaj graf do testowania
- # |
- # v
- 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)
- ,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)
- ,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)
- ,c(0,0,0,0,0,0,0,1,1,0))
- N <- 5
- #Tworzenie macierzy kodów
- nr_of_codes <- 2**(nr_of_players)
- emergency_counter <- 1
- temp_adj_matrix <- main_adj_matrix
- code_vector <- c(1:nr_of_codes)
- full_code_matrix <- matrix(0,nr_of_codes,nr_of_players)
- for (i in code_vector){ #Pełna macierz kodów
- full_code_matrix[i,] <- rev(number2binary(i,nr_of_players))
- }
- #Redukcja macierzy kodów
- reducer <- 0
- for (i in code_vector){
- if(length(which(full_code_matrix[i,]==1))==N){
- }
- else{
- reducer <- append(reducer,-i)
- }
- }
- reducer <- reducer[-1]
- if (length(reducer)>0)
- reduced_code_matrix <- full_code_matrix[reducer,]
- qlique_found <- FALSE
- to_break <- FALSE
- reduced_code_vector <- c(1:nrow(reduced_code_matrix))
- ones_N <- replicate(N,1)
- #Szukam kliki
- for (i in reduced_code_vector){
- indices_vector <- which(reduced_code_matrix[i,] %in% c(1))
- temp_sub_matrix <- main_adj_matrix[indices_vector,indices_vector]
- temp_sub_matrix <- temp_sub_matrix + diag(N)
- for(j in nrow(temp_sub_matrix))
- if(all(temp_sub_matrix[j,]==ones_N)){
- qlique <- indices_vector
- qlique_found <- TRUE
- to_break <- TRUE
- break
- }
- if(isTRUE(to_break)) break
- emergency_counter <- emergency_counter + 1
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement