我需要创建一个客户到达时间、客户等待时间、服务时间和客户离开时间的多列表。服务时间是收银员帮助顾客的时间。到达时间和服务时间由使用 rexp 命令的函数提供。
该表需要如下所示:
我的代码如下所示:
singleTime = function(Rate)
{
data = rexp(1,Rate)
return(data)
}
waitTimes = function(m,arrivalRate,serviceRate)
{
arrivalTimes = c(1:m)
waitTimes = c(1:m)
serviceTimes = c(1:m)
leaveTimes = c(1:m)
previousLeaveTime = 0
for(i in (1:m))
{
arrivalTimes[i] = singleTime(arrivalRate)
if(i == 0)
{
waitTimes[i] = 0
}
else if((previousLeaveTime - arrivalTimes[i])<= 0)
{
waitTimes[i] = 0
}
else
{
waitTimes[i] = leaveTimes[i-1] - arrivalTimes[i]
}
serviceTimes[i] = singleTime(serviceRate)
leaveTimes[i] = waitTimes[i] + serviceTimes[i] + arrivalTimes[i]
previousLeaveTime = leaveTimes[i]
i = i + 1
}
waitTimesTable = table(arrivalTimes,waitTimes,serviceTimes,leaveTimes)
View(waitTimesTable)
}