daily pastebin goal
41%
SHARE
TWEET

Untitled

a guest Jul 13th, 2018 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. library(tidyverse)
  2. library(igraph)
  3.  
  4. g <- make_lattice(c(5, 5))
  5.  
  6. ego(g, order = 1, mindist = 1)
  7.  
  8. head_of(g, E(g))
  9.  
  10. he <- ego(g, order = 1, mindist = 1, nodes = head_of(g, E(g)))
  11. te <- ego(g, order = 1, mindist = 1, nodes = tail_of(g, E(g)))
  12.  
  13.  
  14. thirdN <- map2(te, he, function(x, y){c(x,y) %>% unique %>% as.numeric()})
  15.  
  16. elSL <- as_data_frame(g) %>%
  17.   as.tibble() %>%
  18.   mutate(third = thirdN) %>%
  19.   unnest() %>%
  20.   filter(third != from,
  21.          third != to) %>%
  22.   mutate(fourth = ego(g, order = 1, mindist = 1, nodes = third) %>%
  23.            map(as.numeric)) %>%
  24.   unnest() %>%
  25.   filter(fourth != from,
  26.          fourth != to) %>%
  27.   mutate(fifth = ego(g, order = 1, mindist = 1, nodes = fourth) %>%
  28.            map(as.numeric)) %>%
  29.   unnest() %>%
  30.   filter(fifth != from,
  31.          fifth != to,
  32.          fifth != third) %>%
  33.   apply(1, sort) %>%
  34.   t %>%
  35.   as.tibble() %>%
  36.   distinct() %>%
  37.   mutate_all(as.integer)
  38.  
  39. elY <- as_data_frame(g) %>%
  40.   as.tibble() %>%
  41.   mutate(third = thirdN) %>%
  42.   unnest() %>%
  43.   filter(third != from,
  44.          third != to) %>%
  45.   {
  46.     branch <<- ego(g, order = 1, mindist = 1, nodes = .$third)
  47.     branchData <<- mutate(., fourth = branch %>% map(as.numeric))
  48.     branchData
  49.   } %>%
  50.   unnest() %>%
  51.   filter(fourth != from,
  52.          fourth != to) %>%
  53.   left_join(rename(branchData, fifth = fourth)) %>%
  54.   unnest() %>%
  55.   filter(fifth != from,
  56.          fifth != to,
  57.          fifth != fourth) %>%
  58.   apply(1, sort) %>%
  59.   t %>%
  60.   as.tibble() %>%
  61.   distinct() %>%
  62.   mutate_all(as.integer) %>%
  63.   anti_join(elSL)
  64.  
  65. elT <- as_data_frame(g) %>%
  66.   as.tibble() %>%
  67.   mutate(third = thirdN) %>%
  68.   unnest %>%
  69.   filter(third != from,
  70.          third != to) %>%
  71.   left_join(rename(., fourth = third)) %>%
  72.   filter(fourth != third) %>%
  73.   left_join(rename(., fifth = third) %>% select(-fourth))  %>%
  74.   filter(fifth != third,
  75.          fifth != fourth) %>%
  76.   apply(1, sort) %>%
  77.   t %>%
  78.   as.tibble() %>%
  79.   distinct() %>%
  80.   anti_join(elSL) %>%
  81.   anti_join(elY) %>%
  82.   mutate_all(as.integer)
  83.  
  84. set.seed(4)
  85. plot(g)
  86.  
  87. saveGIF({
  88.  
  89.   ani.options(interval = 0.2)
  90.   for (i in seq_along(elY$V1)) {
  91.     set.seed(5)
  92.     plot(g,
  93.          vertex.color = ifelse(V(g) %in% unlist(elY[i,]), 'skyblue', 'pink')
  94.     )
  95.     title("All Y length 5")
  96.     ani.pause()
  97.   }}, movie.name = "Ylength5.gif", ani.width = 600, ani.height = 600)
  98.  
  99. saveGIF({
  100.   ani.options(interval = 0.2)
  101.   for (i in seq_along(elSL$V1)) {
  102.     set.seed(5)
  103.     plot(g,
  104.          vertex.color = ifelse(V(g) %in% unlist(elSL[i,]), 'skyblue', 'pink')
  105.     )
  106.     title("All Straight Line length 5")
  107.     ani.pause()
  108.   }}, movie.name = "SLlength5.gif", ani.width = 600, ani.height = 600)
  109.  
  110. saveGIF({
  111.   ani.options(interval = 0.2)
  112.   for (i in seq_along(elT$V1)) {
  113.     set.seed(5)
  114.     plot(g,
  115.          vertex.color = ifelse(V(g) %in% unlist(elT[i,]), 'skyblue', 'pink')
  116.     )
  117.     title("All T Line length 5")
  118.     ani.pause()
  119.   }}, movie.name = "Tlength5.gif", ani.width = 600, ani.height = 600)
RAW Paste Data
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