Generic selectors
Exact matches only
Search in title
Search in content

# Reply To: Erlang Formula

#32975 Erik
Guest

Hi Tim,

your question was a good exercise. I created the following macro in VBA (you can just copy/paste). It has the following characteristics:
– limitation in the number of channels (creates buffer overflow if too many channels): I did not want to waste time solving this problem. You can have a look at it by yourself I guess.
– configurable number of circuits
– configurable GOS
– configurable precision desired on the capacity (that’s the variable “dblDesiredPrecision”)
– configurable range of research of the value.
– optimised calculation of the factorials (we dont calculate the same values over and over again. Once is enough… and so much faster!!)

In short, how is it calculated?
1) You know that your capacity is more than zero
2) you guess that your capacity is less than a certain value (I chose 1000000000 Erlangs)
3) you try some value in between (dichotomia) and you look at the corresponding GOS. If the GOS obtained corresponds to some over-estimated capacity, your new range of research is now more than zero, and less than this value…
4) repeat until the precision obtained is satisfying

—————–
Public Sub main()

Dim resultCapacity, dblGradeOfService, dblNumCircuits As Double

dblGradeOfService = 0.02 ‘”2%” is equivalent to “0.02”. You can modify this value if you have a different GOS
dblNumCircuits = 10 ‘In this example, we use 10 circuits (channels)

‘capacity calculation
resultCapacity = dblCapacity(dblGradeOfService, dblNumCircuits)

End Sub

Function factorial(ByVal myNumber As Double) As Double

Dim i As Integer

‘keeps in memory the values already calculated of factorials. This avoids to recalculate the factorial each time
Static varFactoBuffer As Variant
If (IsEmpty(varFactoBuffer)) Then
varFactoBuffer = Array(“1”, “1”)
End If

‘we extend the factorial buffer and add the corresponding values
For j = UBound(varFactoBuffer) To myNumber
ReDim Preserve varFactoBuffer(j)
varFactoBuffer(j) = varFactoBuffer(j – 1) * j
Next j

factorial = varFactoBuffer(myNumber)

End Function

Function GOS(ByRef capacity As Double, ByRef numCircuits As Double) As Double

Dim denominator, numerator As Double
Dim i As Long

Dim capacityElevatedToPower As Variant
capacityElevatedToPower = Array(“1”, capacity)
For i = 1 To numCircuits
ReDim Preserve capacityElevatedToPower(i + 1)
capacityElevatedToPower(i + 1) = capacityElevatedToPower(i) * capacity
Next i

‘ we calculate the denominator of the Erlang B formula
For i = 0 To numCircuits
denominator = denominator + capacityElevatedToPower(i) / (factorial(i))
Next i

‘ we calculate the numerator of the Erlang B formula
numerator = capacityElevatedToPower(numCircuits) / (factorial(numCircuits))

GOS = numerator / denominator

End Function

Public Function dblCapacity(ByVal dblGradeOfService As Double, ByVal dblNumCircuits As Double) As Double
‘ The program will look for the desired value of the capacity between those limits
Dim dblMinCapacity, dblMaxCapacity, dblEstimCapacity As Double
dblMinCapacity = 0
dblMaxCapacity = 1000000000
dblEstimCapacity = (dblMaxCapacity + dblMinCapacity) / 2

Dim dblEstimPrecision, dblDesiredPrecision As Double
‘ the precision (in Erlang) on the estimation of the capacity
dblEstimPrecision = (dblMaxCapacity – dblMinCapacity) / 2
‘ precision desired on the capacity (in Erlang) calculation
‘ I chose 1E-6 because this sets the error to less than 1 Erlang on the total capacity of a normal national network
dblDesiredPrecision = 0.000001

While dblEstimPrecision > dblDesiredPrecision

‘ we estimate the GOS that can be obtained by the current value of the estimated capacity
dblEstimGOS = GOS(dblEstimCapacity, dblNumCircuits)

‘ we improve our estimation of the capacity and we reduce the interval of research of the capacity
If (dblEstimGOS > dblGradeOfService) Then
dblMaxCapacity = dblEstimCapacity
dblEstimCapacity = (dblMinCapacity + dblEstimCapacity) / 2
Else
dblMinCapacity = dblEstimCapacity
dblEstimCapacity = (dblMaxCapacity + dblEstimCapacity) / 2
End If

‘ we readjust the estimated precision because we have improved our knowledge of the value of the capacity
dblEstimPrecision = (dblMaxCapacity – dblMinCapacity) / 2

Wend

dblCapacity = dblEstimCapacity

End Function