Original link:tecdat.cn/?p=4182

Original source:Tuo End number according to the tribe public number

 

case

A gas station has a fuel pile and no space for vehicles to wait (if the vehicle arrives and the pile is occupied, it will leave). The rate at which vehicles arrive at petrol stations follows the Poisson process λ=3/20 per minute, of which 75% are cars and 25% are motorcycles. Refueling time can be modeled with an exponential random variable, with an average of 8 minutes for cars and 3 minutes for motorcycles, and service rates for cars μC= 1/8 and motorcycles μ= 1/3 per minute.

Therefore, we can calculate the average number of vehicles in the system by multiplying these probabilities by the number of vehicles in each state.

Lambda < -3/20 A < -matrix (c(1, mu[1], 0, 1, lambda, (1-p)*lambda, c(1, mu[1], 0, 1, lambda, (1-p)*lambda, 0.5031056 N_average_theor # > [1]Copy the code

Now, we will simulate the system and verify

optio<-

    seize("pump", amount=1) %>%
    timeout(function() rexp(1, mu[1])) %>%
    release("pump", amount=1)
  
Copy the code

To differentiate between cars and motorcycles, we can define a branch to select the appropriate service time after obtaining the resource.

This option.3 is equivalent to option.1 performance. For example,

opti2 <- function(t) {
  
    seize("pump", amount=1) %>%
    branch(function() sample(c(1, 2), 1, prob=c(p, 1-p)), c(T, T), 
           trajectory("car") 
             timeout(function() rexp(1, mu[2]))) %>
Copy the code

This option, however, adds unnecessary computation because additional calls to the R function are required to select the branch, thus reducing performance. A better option is to select the service time directly within the timeout function.

optio3 <- function(t) {
  vehicle <- trajectory() %>%
    seize("pump", amount=1) % > %if (runif(1) < p) rexp(1, mu[1])  # the car
      else rexp(1, mu[2])               # motorcycle% > %})Copy the code

This option.3 is equivalent to option.1 in performance. But we got the same result. For example,


# Usage rate + theoretical value
plot(get_mon_resources(gas.station), "usage"."pump", items="system") +
  geom_hline(yintercept=N_average_theor)
Copy the code

 

These are some of the results of performance:

t <- 1000/lambda tm <- microbenchmark(option.1(t), autoplot(tm) + scale_y_log10(breaks=function(limits) pretty(limits, + 5))Copy the code


Most welcome insight

1. Use R language to simulate the mixed queuing random service queuing system

2. Queuing theory is used in R language to predict waiting time

3. Realize markov chain Monte Carlo MCMC model in R language

4. Markov regime switching model in R language

5. Matlab Bayesian hidden Markov HMM model

6. Use R language to simulate the mixed queuing random service queuing system

7. Portfolio optimization in Python based on particle swarm optimization

8. Research on accident prediction of traffic casualties by R Language Markov Transformation model

9. Identifying changing Stock Market Conditions with Machine learning: Application of Hidden Markov Models