Created
January 11, 2019 21:51
-
-
Save marcosci/ca8300c1be8763fd38ade452926c10ed to your computer and use it in GitHub Desktop.
nlrx Team Assembly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Step1: Create a nl obejct: | |
nl <- nl(nlversion = "6.0.4", | |
nlpath = "/home/marco/nlrx_usecase/1_Helper/NetLogo 6.0.4/", | |
modelpath = "/home/marco/nlrx_usecase/1_Helper/NetLogo 6.0.4/app/models/Sample Models/Networks/Team Assembly.nlogo", | |
jvmmem = 1024) | |
## Step2: Add Experiment | |
# Inspect the model available model parameters: | |
nl@experiment <- experiment(expname = "links_team", | |
outpath = "/home/marco/", | |
repetition = 1, # If repetitions is > 1, a different random seed will be set for each netlogo run | |
tickmetrics = "true", | |
idsetup = "setup", # you can define multiple setup procedures with c() | |
idgo = "go", # you can define multiple go procedures with c() | |
idfinal = NA_character_, # you can define one or more final commands here | |
runtime = 100, | |
evalticks = seq(1,100), | |
constants = list("layout?" = TRUE), | |
metrics.turtles=c("who", | |
"pxcor", | |
"pycor", | |
"color", | |
"size"), | |
metrics.links=c("end1", | |
"end2", | |
"color"), | |
metrics.patches=c("pxcor", | |
"pycor")) | |
nl@simdesign <- simdesign_simple(nl=nl, nseeds = 1) | |
## Run parallel | |
results <- run_nl_one(nl = nl, | |
seed = getsim(nl, "simseeds")[1], | |
siminputrow = 1) | |
# Attach results to nl | |
setsim(nl, "simoutput") <- results | |
nl_spatial <- get_nl_spatial(nl, format = "tibble", patches = FALSE, links = TRUE, turtles = TRUE) | |
nl_links <- nl_spatial %>% | |
dplyr::filter(group == "links") %>% | |
dplyr::select(-who, -pxcor, -pycor, -size) | |
nl_turtles <- nl_spatial %>% | |
dplyr::filter(group == "turtles") %>% | |
dplyr::select(step, who, pxcor, pycor, color, size) | |
# %>% | |
# dplyr::mutate(size = dplyr::case_when(size == 0.9 ~ 1)) | |
nl_links <- nl_links %>% | |
dplyr::left_join(nl_turtles, by=c("step"="step","end1" = "who")) %>% | |
dplyr::left_join(nl_turtles, by=c("step"="step","end2" = "who")) | |
library(ggplot2) | |
library(gganimate) | |
library(ggnewscale) | |
p1 <- ggplot() + | |
geom_segment(data=nl_links, aes(x = pxcor.x, y = pycor.x, xend = pxcor.y, yend = pycor.y, color = factor(color.x)), size=0.5) + | |
rcartocolor::scale_color_carto_d(palette = "Prism") + | |
new_scale_color() + | |
geom_point(data=nl_turtles, aes(x = pxcor, y = pycor, group=who, size = size, color = factor(color))) + | |
rcartocolor::scale_color_carto_d(palette = "Earth") + | |
transition_time(step) + | |
coord_equal() + | |
theme_void() + | |
theme(legend.position="none") | |
gganimate::animate(p1, , nframes=max(nl_spatial$step), width=600, height=600, fps=10) | |
anim_save("/home/marco/network_team.gif") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment