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

2024-04-26 10:19:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我的代码的作用:

模拟N通道网络上发生的100个语音呼叫,并计算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次呼叫开始时间的均匀分布。你知道吗

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

我将通道计数器变量和阻塞计数器变量设置为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


Tags: of代码numberforifnp时间计数器
1条回答
网友
1楼 · 发布于 2024-04-26 10:19:26

好的,这里的问题是,取任何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左右。你知道吗

相关问题 更多 >