Skip to content

Undesired sub-trajectory behavior #91

Description

@mmarks13

I have put together some example code to reproduce the issue I'm having. In an attempt to keep my code clean, I have set up multiple sub-trajectories; however, as you can see by the output, the arrivals don't continue on the trajectory from which they started, after going down a shared sub-trajectory. It seems as though all arrivals continue down the trajectory of the first arrival to hit the sub-trajectory (see logging).

#'#Define Case Paths

#Trajectory to send signal to start Milling. 
#In real life milling starts at the end of the day and runs overnight. 
Milling_Start <- trajectory() %>%
  log_("Start_Milling") %>%
  send("Start_Milling")

#'##sub-paths for parts of the process with more detail or shared trajectories across materials

Milling_SubTraj <-   trajectory("Milling_SubTraj") %>%
  #When Start_Mill signal is sent, all cases in wait() will be sent here.
  trap("Start_Milling",
       handler =
         trajectory () %>%
         set_capacity("Mill",5) %>% #temporarily set capacity equal to 5 as another way to do batching.
         seize("Mill", 1) %>%
         timeout(10) %>%
         set_capacity("Mill",0) %>% #set capacity to zero to prevent more cases from moving through.
         release("Mill", 1)
  ) %>%
  #Upon a signal reception, the arrival stops the current waiting activity and executes the handler if provided. Then, the execution returns to the activity following the point of the interruption:
  wait() %>%
  #if a case has gotten here, Milling is complete. Unsubscribe the case from the Start_Milling signal.
  untrap("Start_Milling") %>%
  log_(function(attrs) paste("done milling - material", attrs[["material"]],sep=''))


#'##Path for each material##
Material1 <- trajectory("Material1_Path") %>%
  set_attribute("material", 1) %>%
  log_("Entering Milling on Material1 trajectory") %>%
  join(Milling_SubTraj) %>%
  log_("Exiting Milling on Material1 trajectory")


Material2 <- trajectory("Material2_Path") %>%
  set_attribute("material", 2) %>%
  log_("Entering Milling on Material2 trajectory") %>%
  join(Milling_SubTraj) %>%
  log_("Exiting Milling on Material2 trajectory")


Material3 <- trajectory("Material3") %>%
  set_attribute("material", 3) %>%
  log_("Entering Milling on Material3 trajectory") %>%
  join(Milling_SubTraj) %>%
  log_("Exiting Milling on Material3 trajectory")



#'Overall Path
#'build overall path based on the pct of each material coming into the system. The case will go down a trajectory based on the material prob. 
Overall_Path <- trajectory() %>%
  #'branch to different materials
  branch(function() sample(c(1,2,3),1,replace=TRUE,prob= c(.33,.33,.33)),continue=c(T,T,T),
         Material1,
         Material2,
         Material3) 



#'#Run Simulation
#############################################################################

runtime <- 30 #minutes

env <- simmer()
env %>%
  add_resource("Mill", 5) %>%
  add_generator("Case", Overall_Path,at(1,2,3,4,5), mon = 2) %>%
  add_generator("Milling_Start", Milling_Start, at(10)) %>%
  run(runtime)



#All cases continue after milling on the trajectory of the first case to enter the milling trajectory.  
># 1: Case0: Entering Milling on Material1 trajectory
># 2: Case1: Entering Milling on Material3 trajectory
># 3: Case2: Entering Milling on Material2 trajectory
># 4: Case3: Entering Milling on Material2 trajectory
># 5: Case4: Entering Milling on Material1 trajectory
># 10: Milling_Start0: Start_Milling
># 20: Case0: done milling - material1
># 20: Case1: done milling - material3
># 20: Case2: done milling - material2
># 20: Case3: done milling - material2
># 20: Case4: done milling - material1
># 20: Case0: Exiting Milling on Material1 trajectory
># 20: Case1: Exiting Milling on Material1 trajectory
># 20: Case2: Exiting Milling on Material1 trajectory
># 20: Case3: Exiting Milling on Material1 trajectory
># 20: Case4: Exiting Milling on Material1 trajectory
># simmer environment: anonymous | now: 20 | next: 
># { Resource: Mill | monitored: 1 | server status: 0(0) | queue status: 0(Inf) }
># { Generator: Case | monitored: 2 | n_generated: 5 }
># { Generator: Milling_Start | monitored: 1 | n_generated: 1 }

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