Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library("igraph")
- library(gplots)
- #Zadanie 2
- setwd("E:/R/lab3")
- #graph <- read.graph("reachability.txt", format="edgelist")
- df <- read.table("reachability.txt", sep = " ", header = FALSE)
- graph<-graph.data.frame(df)
- #plot(graph)
- #Wznaczyc srednice sieci i srednia najkrotsza sciezke dla grafow nieskierowanych
- srednica_gns <- diameter(graph, directed = F, weights = NA)
- #Najkrotsze sciezki
- x1 <- shortest.paths(graph)
- y2 <- shortest.paths(graph, 1, 10)
- c1 <- average.path.length(graph)
- #path.length.hist(graph)
- #Wyznaczyc srednice sieci i srednia najkrotsza sciezke dla grafow skierowanych
- srednica_gs <- diameter(graph, directed = T, weights = NA)
- sredbuca_gs2 <- get.diameter(graph, directed = TRUE)
- x <- shortest.paths(graph, mode = "out")
- y <- shortest.paths(graph, mode = "in")
- z <- shortest.paths(graph, mode = "all")
- shortest.paths(graph, 8, 10, mode="out")
- c <- average.path.length(graph, directed = TRUE)
- w <- shortest.paths(graph, 27, 304, mode="out")
- #Wyznaczyc degree, between, closeness
- #degree
- d<-degree(graph, mode="all")
- dsort <- tail(sort(d), 5)
- plot(dsort)
- plot(d, main="Degree")
- rozklad_degree_node <- degree(graph, mode="all")
- plot(degree.distribution(graph, cumulative = T), pch=20, xlab="degree", ylab="cumulative frequency", type="l", main="Rozklad Stopni wierzcholkow")
- #Closeness dla grafów skierowanych i wazonych
- o <- closeness(graph)
- op <- closeness(graph, vids=c("1","2"))
- close <- closeness(graph ,normalized = TRUE,mode="all")
- dsort2 <- tail(sort(close), 5)
- plot(close, main="Closeness")
- #Between
- between <- betweenness(graph)
- dsort3 <- tail(sort(between), 5)
- plot(between, main="Betweenness")
- #top5 wspolne wierzcholki
- print(names(dsort))
- print(names(dsort2))
- print(names(dsort3))
- names_nodes = names(dsort)
- M <- matrix(c(0:0), nrow = 5, ncol = 5)
- for (i in 1:5){
- this_node = as.numeric(names_nodes[i])
- for (j in 1:5){
- test_against = as.numeric(names_nodes[j])
- if (i != j){
- M[i, j] = shortest.paths(graph, this_node, test_against)
- }
- }
- }
- names_nodes = names(dsort2)
- M2 <- matrix(c(0:0), nrow = 5, ncol = 5)
- for (i in 1:5){
- this_node = as.numeric(names_nodes[i])
- for (j in 1:5){
- test_against = as.numeric(names_nodes[j])
- if (i != j){
- M2[i, j] = shortest.paths(graph, this_node, test_against)
- }
- }
- }
- names_nodes = names(dsort2)
- M3 <- matrix(c(0:0), nrow = 5, ncol = 5)
- for (i in 1:5){
- this_node = as.numeric(names_nodes[i])
- for (j in 1:5){
- test_against = as.numeric(names_nodes[j])
- if (i != j){
- M3[i, j] = shortest.paths(graph, this_node, test_against)
- }
- }
- }
- heatmap.2(M, cellnote = M, notecol="black", dendrogram='none', Rowv=TRUE, Colv=TRUE, trace='none')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement