Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Enchufa2 opened this issue Jul 4, 2021 Discussed in #255 · 0 comments
Closed

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

Enchufa2 opened this issue Jul 4, 2021 Discussed in #255 · 0 comments
Labels

Comments

@Enchufa2
Copy link
Member

Enchufa2 commented Jul 4, 2021

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   
@Enchufa2 Enchufa2 added the bug label Jul 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant