From e7ccaa39620134773a06c0a1f698bf905b279a42 Mon Sep 17 00:00:00 2001 From: Rose McKeon Date: Wed, 31 Jul 2019 00:24:40 +0000 Subject: [PATCH] for #89 @bradduthie does this make sense to do? --- R/disturploidy.R | 16 ++++++++++++---- R/functions.R | 11 ++++++++++- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/R/disturploidy.R b/R/disturploidy.R index 30f2430..87e0738 100644 --- a/R/disturploidy.R +++ b/R/disturploidy.R @@ -318,9 +318,15 @@ disturploidy <- function( if(nrow(seeds) > 0){ tic("Germination") # decide which seeds germimate - seeds <- seeds %>% germinate( - germination_prob - ) + if(seed_survival_prob == 0){ + # we decided the germination fate already to reduce computation + # so germinate all seeds + seeds <- seeds %>% germinate(1) + message(" Germinating all seeds (germination fate already decided).") + } else { + # germination needs to happen as usual + seeds <- seeds %>% germinate(germination_prob) + } new_juveniles <- seeds %>% filter( life_stage == 1 ) @@ -461,7 +467,9 @@ disturploidy <- function( genome_size, ploidy_prob, mutation_rate, - grid_size + grid_size, + germination_prob, + seed_survival_prob ) # make sure we have some new seeds # (stop any mutate errors) diff --git a/R/functions.R b/R/functions.R index c0aecfc..7c3fc77 100644 --- a/R/functions.R +++ b/R/functions.R @@ -83,7 +83,9 @@ reproduce <- function( genome_size = 10, ploidy_prob = .01, mutation_rate = .001, - grid_size + grid_size = 100, + germination_prob = .5, + seed_survival_prob = 0 ){ # make sure we have the right kind of parameters stopifnot( @@ -190,6 +192,13 @@ reproduce <- function( } message(" ", nrow(zygotes), " zygotes created in TOTAL.") if(nrow(zygotes) > 0){ + # see if we can reduce computation and decide the germination fate now + if(seed_survival_prob == 0){ + # seeds with genomes will not persist so we don't need to fill them + # we'll check for this at the germination stage too + zygotes <- zygotes %>% survive(germination_prob) + message(" ", nrow(zygotes), " zygotes destined to become seeds that will germinate.") + } # make sure all the new zygotes become seeds with genetic info seeds <- create_seeds( zygotes, adults, generation, genome_size, mutation_rate