G2A Many GEOs
SHARE
TWEET

Untitled

a guest Mar 29th, 2020 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. library("igraph")
  2. library(gplots)
  3. #Zadanie 2
  4. setwd("E:/R/lab3")
  5. #graph <- read.graph("reachability.txt", format="edgelist")
  6. df <- read.table("reachability.txt", sep = " ", header = FALSE)
  7. graph<-graph.data.frame(df)
  8. #plot(graph)
  9.  
  10. #Wznaczyc srednice sieci i srednia najkrotsza sciezke dla grafow nieskierowanych
  11.  
  12. srednica_gns <- diameter(graph, directed = F, weights = NA)
  13.  
  14. #Najkrotsze sciezki
  15. x1 <- shortest.paths(graph)
  16. y2 <- shortest.paths(graph, 1, 10)
  17. c1 <- average.path.length(graph)
  18. #path.length.hist(graph)
  19.  
  20.  
  21. #Wyznaczyc srednice sieci i srednia najkrotsza sciezke dla grafow skierowanych
  22.  
  23. srednica_gs <- diameter(graph, directed = T, weights = NA)
  24. sredbuca_gs2 <- get.diameter(graph, directed = TRUE)
  25. x <- shortest.paths(graph, mode = "out")
  26. y <- shortest.paths(graph, mode = "in")
  27. z <- shortest.paths(graph, mode = "all")
  28. shortest.paths(graph, 8, 10, mode="out")
  29. c <- average.path.length(graph, directed = TRUE)
  30. w <- shortest.paths(graph, 27, 304, mode="out")
  31.  
  32. #Wyznaczyc degree, between, closeness
  33. #degree
  34. d<-degree(graph, mode="all")
  35. dsort <- tail(sort(d), 5)
  36. plot(dsort)
  37. plot(d, main="Degree")
  38. rozklad_degree_node <- degree(graph, mode="all")
  39. plot(degree.distribution(graph, cumulative = T), pch=20, xlab="degree", ylab="cumulative frequency", type="l", main="Rozklad Stopni wierzcholkow")
  40.  
  41. #Closeness dla grafów skierowanych i wazonych
  42. o <- closeness(graph)
  43. op <- closeness(graph, vids=c("1","2"))
  44. close <- closeness(graph ,normalized = TRUE,mode="all")
  45. dsort2 <- tail(sort(close), 5)
  46. plot(close, main="Closeness")
  47.  
  48. #Between
  49. between <- betweenness(graph)
  50. dsort3 <- tail(sort(between), 5)
  51. plot(between, main="Betweenness")
  52.  
  53. #top5 wspolne wierzcholki
  54. print(names(dsort))
  55. print(names(dsort2))
  56. print(names(dsort3))
  57.  
  58. names_nodes = names(dsort)
  59. M <- matrix(c(0:0), nrow = 5, ncol = 5)
  60. for (i in 1:5){
  61.   this_node = as.numeric(names_nodes[i])
  62.   for (j in 1:5){
  63.     test_against = as.numeric(names_nodes[j])
  64.     if (i != j){
  65.       M[i, j] = shortest.paths(graph, this_node, test_against)
  66.     }
  67.   }
  68. }
  69.  
  70. names_nodes = names(dsort2)
  71. M2 <- matrix(c(0:0), nrow = 5, ncol = 5)
  72. for (i in 1:5){
  73.   this_node = as.numeric(names_nodes[i])
  74.   for (j in 1:5){
  75.     test_against = as.numeric(names_nodes[j])
  76.     if (i != j){
  77.       M2[i, j] = shortest.paths(graph, this_node, test_against)
  78.     }
  79.   }
  80. }
  81.  
  82. names_nodes = names(dsort2)
  83. M3 <- matrix(c(0:0), nrow = 5, ncol = 5)
  84. for (i in 1:5){
  85.   this_node = as.numeric(names_nodes[i])
  86.   for (j in 1:5){
  87.     test_against = as.numeric(names_nodes[j])
  88.     if (i != j){
  89.       M3[i, j] = shortest.paths(graph, this_node, test_against)
  90.     }
  91.   }
  92. }
  93.  
  94. heatmap.2(M, cellnote = M, notecol="black", dendrogram='none', Rowv=TRUE, Colv=TRUE, trace='none')
RAW Paste Data
Ledger Nano X - The secure hardware wallet
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top