原文链接:http://tecdat.cn/?p=4182
案例
一个加油站有一个繁多的泵,没有空间供车辆期待(如果车辆达到,泵不在,它就会来到)。车辆达到与以下的速率泊松过程加油站=3/20=3/20每分钟车辆,其中75%是汽车,25%是摩托车。加油工夫能够用一个指数随机变量建模,均匀汽车8分钟,摩托车3分钟,服务速率为C= 1 / 8C=1/8汽车和米= 1 / 3米=1/3 摩托车每分钟。
因而,咱们能够通过将这些概率乘以每个状态下的车辆数量来计算零碎中的均匀车辆数量。
# Arrival ratelambda <- 3/20# Service rate (cars, motorcycles)mu <- c(1/8,1/3)# Probability of carp <- 0.75#
当初,咱们将模拟系统simmer并验证
option.1<- function(t) {car <->% seize("pump",amount=1)%>% timeout(function()rexp(1, mu[1]))
为了辨别汽车和摩托车,咱们能够在获取资源后定义一个分支来抉择适合的服务工夫。
这option.3相当于option.1性能。 例如,
valueplot(gas.station,"resources","usage","pump",items="system")+ geom_hline(yintercept=N_average_theor)#> Warning: 'plot.simmer' is deprecated.#> Use 'plot(get_mon_resources(x))' instead.
这些是一些体现的后果:
library(microbenchmark)t <- 1000/lambdatm <- microbenchmark(option.1(t),option.2(t),option.3(t))autoplot(tm)+ scale_y_log10(breaks=function(limits)pretty(limits,5))+ ylab("Time [milliseconds]")