如何修复我编写的用于查找被阻止呼叫数量的计数器?

How can I fix this counter I wrote used to find the number of blocked calls?

我的代码的用途:

模拟100个在N信道网络上发生的语音呼叫,计算60分钟内的服务等级(即呼叫阻塞百分比)。

我的代码:

import numpy as np
import pandas as pd

#Uniformly distributed start times
startTimes = np.random.randint(0,60,100)
startTimes.sort()

#Average call time for 100 people 
callDuration = np.random.poisson(20, 100)

channelCounter = 0;
blockedCounter = 0;

endTimes = np.add(callDuration, startTimes)

numberChannels = 1

for x in range(0,60): 

    for y in range(0, startTimes.size):

        if startTimes[y] == x: 
            if channelCounter < numberChannels:
                channelCounter=channelCounter+1

            elif channelCounter == numberChannels: 

                blockedCounter = blockedCounter + 1

        if (endTimes[y] == x):
            if channelCounter >= 1:
                channelCounter=channelCounter-1

我的方法:

我生成从 0 分钟到 60 分钟的 100 个呼叫开始时间的均匀分布。

我生成了 100 个通话持续时间的随机泊松分布,平均通话时间为 20 分钟。

我将频道计数器变量和阻塞计数器变量设置为 0。

最后,我创建了另一个数组,由通话开始时间+平均通话时长的总和组成,以获得通话结束时间。

阻塞计数器递增背后的伪代码逻辑如下:

if number of channels occupied < number channels available:
    put a call through 
else if number of channels occupied == number channels available ( ie full):
    call is dropped so counter incremements 

if a call that is ongoing finishes: 
    decrement number of channels occupied 

我的阻塞计数器没有像我预期的那样增加。我对出了什么问题有一个模糊的想法,但我不知道如何解决它。在输入当前值的情况下,我应该期望看到阻塞计数器的值约为 95。然而,我得到的是一个徘徊在 70-75 左右的值。

如果有人发现我哪里出错了,我将不胜感激!

Screen shot of the data im working with

好的,所以你的问题是,你采用任何 endTime 值,它在给定的分钟内发生,作为释放频道的标志。而其中一些实际上被阻止了。这就是为什么你要夸大非阻塞呼叫的总数。您更想要的是计算非重叠 <startTime, endTime> 间隔的数量(假设在给定分钟内可能的最大重叠调用等于 numberChannels 和调用的顺序优先级)

所以假设一个频道你可以做:

minute=0
nonBlockedCounter=0

while(minute<=60):
    minute = min(startTimes[minute<=startTimes])
    if(minute>=0):
        nonBlockedCounter+=1
        minute=endTimes[startTimes==minute][0]
blockedCounter=100-nonBlockedCounter
print(blockedCounter)

输出通常在 96-97 左右。