关于r语言:R语言连续时间马尔科夫链模拟案例-Markov-Chains

6次阅读

共计 875 个字符,预计需要花费 3 分钟才能阅读完成。

原文链接:http://tecdat.cn/?p=4182

案例

一个加油站有一个繁多的泵,没有空间供车辆期待(如果车辆达到,泵不在,它就会来到)。车辆达到与以下的速率泊松过程加油站 λ =3/20λ=3/20 每分钟车辆,其中 75%是汽车,25%是摩托车。加油工夫能够用一个指数随机变量建模,均匀汽车 8 分钟,摩托车 3 分钟,服务速率为 μC= 1 / 8μC=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]")

正文完
 0