Skip to content

Unexpected behavior when numeric(0) passed to at() #256

Closed
@Enchufa2

Description

@Enchufa2

Discussed in #255, related to #253

Originally posted by rmwoody July 4, 2021
While building some dynamic simulations I encountered some unexpected results. I am not sure if this is a know or expected outcome. In the reported simulation arrivals, I was seeing start times that were greater than end times. After some troubleshooting, it became clear the strange result only occurred when a function passed a numeric(0) to at(), instead of an empty vector declared as c(). I encountered this on both windows and mac and was not sure why this was occurring.

library(simmer)
library(dplyr)

traj1 <-
  trajectory() %>%
  seize("worker", 1) %>%
  timeout(1) %>%
  release("worker", 1)


traj2 <-
  trajectory() %>%
  seize("worker", 1) %>%
  timeout(1) %>%
  release("worker", 1)


both_traj_present <- simmer() %>%
  add_resource("worker", 12, queue_size = Inf ) %>%
  add_generator("traj1", traj1, at(runif(100000,1,30000) %>% sort())) %>%
  add_generator("traj2", traj2, at(runif(100000,1,30000) %>% sort())) %>%
  run(until = 30000)


one_traj_blank_c <- simmer() %>%
  add_resource("worker", 12, queue_size = Inf ) %>%
  add_generator("traj1", traj1, at(runif(100000,1,30000) %>% sort())) %>%
  add_generator("traj2", traj2, at(c() %>% sort() ) ) %>%
  run(until = 30000)



# numeric(0) passed to at
one_traj_numeric_0 <- simmer() %>%
  add_resource("worker", 12, queue_size = Inf ) %>%
  add_generator("traj1", traj1, at(runif(100000,1,30000) %>% sort())) %>%
  add_generator("traj2", traj2, at(numeric(0) %>% sort())) %>%
  run(until = 30000)



# Returns Zero Rows
get_mon_arrivals(one_traj_blank_c) %>%
  filter(start_time > end_time) %>%
  mutate(order =as.integer(gsub(pattern = "[^0-9]",'', name)) )%>%
  arrange(order)


# Returns Zero Rows
get_mon_arrivals(one_traj_blank_c) %>%
  filter(start_time > end_time) %>%
  mutate(order =as.integer(gsub(pattern = "[^0-9]",'', name)) )%>%
  arrange(order)


# Returns Many Rows
get_mon_arrivals(one_traj_numeric_0) %>%
  filter(start_time > end_time) %>%
  mutate(order =as.integer(gsub(pattern = "[^0-9]",'', name)) )%>%
  arrange(order)
R version 3.6.3 (2020-02-29)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS  10.16

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] dplyr_1.0.2  simmer_4.4.2

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.5       codetools_0.2-16 crayon_1.3.4     R6_2.5.0         lifecycle_0.2.0  magrittr_2.0.1  
 [7] pillar_1.4.7     rlang_0.4.9      rstudioapi_0.13  vctrs_0.3.5      generics_0.1.0   ellipsis_0.3.1  
[13] tools_3.6.3      glue_1.4.2       purrr_0.3.4      compiler_3.6.3   pkgconfig_2.0.3  tidyselect_1.1.0
[19] tibble_3.0.4   

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions