0

我正在尝试在 ErlangC 函数中使用这个阶乘。但是我的代理数量可以达到 300 多个。有了这个,你可以获得相当大的数字。例如. _ 我的问题是如何存储和计算这些数字?本机 SQL 有没有办法。我知道我可以去 CLR 做一个外部函数。但为了简单起见,我想保留这个原生 SQL。真的想从这里到 9 点和 10 点。但是当我解决这个问题时,我会完成的。提前感谢您提供的任何帮助。

ALTER FUNCTION [dbo].[Factorial] ( @iNumber int )
    RETURNS float
    AS
    BEGIN

    Declare @i float
        IF @iNumber <= 1
            SET @i = 1    
        ELSE
            SET @i = @iNumber
            WHILE @iNumber > 1
            BEGIN

            SET @i = @i * (@iNumber - 1)
                Set @iNumber = @iNumber -1 
            END

    RETURN (@i)
    END

ErlangC代码如下:

ALTER FUNCTION [AMS].[ErlangC]
(
    -- Add the parameters for the function here
    @m float  -- Number of Agents
    ,@u float -- Traffic floatensity
)
RETURNS float
AS
BEGIN
--Source http://www.mitan.co.uk/erlang/elgcmath.htm Number 6

    -- Return Variable
    DECLARE @Prob Float -- Probability of Call not being answered immediately and having to wait.

    -- Variables
    Declare @Numerator Float -- Top of Equation
    Declare @Denominator Float -- Bottom of Equation
    Declare @Summation float -- Summation part of Denominator
    Declare @k float    -- increment for summation


    --Calculate Numerator

    SET @Numerator = Power(@u,@m)/dbo.Factorial(@m) 

    -- Start Summation with k starting at 0.
    SET @k = 0
    SET @Summation = 0

    While @k < @m-1
    Begin
        SET @Summation = @Summation + Power(@u,@k)/dbo.Factorial(@k)
        SET @k = @k +1
    End

    --Calculate denominator

    SET @Denominator = Power(@u,@m)/dbo.Factorial(@m) + (1-@u/@m)*@Summation

    SET @Prob = @Numerator/@Denominator

    -- Return the result of the function
    RETURN @Prob

END
4

1 回答 1

1

好吧,我找到了别人的代码并且它可以工作......但我不知道为什么......基本上,他们不是做阶乘,而是使用对数一起做幂和阶乘以获得相同的数字,就好像你以指数方式乘以数字一样.

ALTER FUNCTION [dbo].[PowerFactorial] ( @m float,  @u float)
RETURNS float
AS
BEGIN

Declare @counter float --counter
Declare @total float -- return value

SET @counter = 1
SET @total = 0

WHILE @counter <= @u
BEGIN

SET @total = @total + Log(@m/@counter)
    Set @counter= @counter + 1

END

RETURN Exp(@total)
END

这会将 ErlangC 更改为此。

ALTER FUNCTION [AMS].[ErlangC]
(
    -- Add the parameters for the function here
    @m float  -- Number of Agents
    ,@u float -- Traffic intensity
)
RETURNS float
AS
BEGIN
--Source http://www.mitan.co.uk/erlang/elgcmath.htm Number 6

    -- Return Variable
    DECLARE @Prob Float -- Probability of Call not being answered immediately and having to wait.

    -- Variables
    Declare @Numerator Float -- Top of Equation
    Declare @Denominator Float -- Bottom of Equation
    Declare @Summation float -- Summation part of Denominator
    Declare @k float    -- increment for summation


    --Calculate Numerator

    SET @Numerator = dbo.PowerFactorial(@u,@m)  

    -- Start Summation with k starting at 0.
    SET @k = 0
    SET @Summation = 0

    While @k < @m-1
    Begin
        SET @Summation = @Summation + dbo.PowerFactorial(@u,@k)
        SET @k = @k +1
    End

    --Calculate denominator

    SET @Denominator = dbo.PowerFactorial(@u,@m) + (1-@u/@m)*@Summation

    SET @Prob = @Numerator/@Denominator

    -- Return the result of the function
    RETURN @Prob

END

如果有人对该功能的工作原理有任何见解,请发表评论。谢谢..

于 2013-04-15T15:05:58.280 回答