What my code is meant to do:
Simulate 100 voice calls that occur over an N channel network and calculate the grade of service (that is, the percentage of blocked calls) over a period of 60 minutes.
My Code:
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
My Approach:
I generate a uniform distribution of 100 call start times beginning from 0 min to 60 minutes.
I generate a random poisson distribution of 100 call durations for an average call time of 20 minutes.
I set my channel counter variable and blocked counter variables to 0.
Finally, I create another array consisting of the sum of call start time + average call duration to get the call end time.
The pseudo code logic behind blocked counter incrementing is as follows:
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
My blocked counter isn't incrementing as I expect it to. I have a vague idea of what is going wrong but I don't know how to fix it. With the current values im inputting, I should expect to see a value of around 95 for blocked counter. What I get however is a value that hovers around 70-75.
If anyone spots where im going wrong, I would greatly appreciate it!
Ok, so your problem here is, that you take ANY endTime
value, which happens on given minute as a sign of freeing a channel. Whereas some of these were actually blocked. Which is why you are inflating the total number of non blocked calls. What you rather want is to compute number of non-overlapping < startTime
, endTime
> intervals (assuming possible max overlapping calls at given minute equal to numberChannels
AND order priority of calls)
So assuming one channel you can do:
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)
Output is around 96-97 most often.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.