exponential distribution M/M/1 queue

Recommended Posts

hello

I want convert this C++ code to autoit code but I encounter with some problems. this code is a simulation of M/M/1 queue and I need use an exponential distribution formula in that. Can anyone help me?

MM1.txt

Share on other sites
Posted (edited)

Edited by TheXman

Whoever said that there's no such thing as a dumb question, probably asked a lot of DUMB questions.  Dumb questions are ones that you can easily find the answer to on your own.

Share on other sites

This would be an instance of "trying to use the wrong tool for the job". Why on earth would you want to convert that? Do you even understand the code?

√-1 2^3 ∑ π, and it was delicious!

Share on other sites

@TheXman  Done! I think that my problem is in exponential distribution formula implementation! at C++ code loss packets that I want to see that in autoit output... is 40%... and that is correct output.

@JLogan3o13 I just want implement that code in autoit . I know what that code is. there is a server and a queue with 9 capacity... and 1000 client as input to this M/M/1 system. we need calculate all of loss pacekts (clients who cant gets service and loss!)

MM1.au3

Share on other sites

My question is if you have it working in C++, why shoehorn it into a slower language?

• 1

√-1 2^3 ∑ π, and it was delicious!

Share on other sites
Posted (edited)

First, how are you ever supposed to exit this loop when \$AEC is never incremented?

```While (\$AEC < 1000) ;number of inputs!
if (\$Next_Arr < \$Next_Dep) Then
if (\$SS = 0) Then
\$SS = 1 ;server status
\$Next_Arr = \$Next_Arr + rand_exp(6)
Else
If (\$QL = 9) Then ;queue lenth is 9
\$LEC += 1 ;number of loss pockets!
\$Next_Arr = \$Next_Arr + rand_exp(6)
Else
\$QL += 1
\$NextArr = \$Next_Arr + rand_exp(6)
EndIf

if (\$QL = 0) Then
\$SS = 0
\$Next_Dep = \$Next_Arr + rand_exp(10)
Else
\$QL -= 1
\$Next_Dep = \$Next_Dep + rand_exp(10)
EndIf
EndIf
EndIf
WEnd```

It appears to me that the code you are working from, MM1.txt. is flawed.

Edited by TheXman

Whoever said that there's no such thing as a dumb question, probably asked a lot of DUMB questions.  Dumb questions are ones that you can easily find the answer to on your own.

Share on other sites
Posted (edited)

Here's one possible way, in this case to obtain a sigmoid curve.

Edited by RTFC

My Contributions and Wrappers

Spoiler

Share on other sites

@TheXman I fix it... but I could 't get any result that I expect.

I run it with a "for" loop and 10000 repeat... but I still get the wrong result! 0% packet loss! it 's Impossible! It should be about 40%.

```#include <Math.au3>

Global \$QL =0, \$LEC = 0, \$AEC = 0, \$SS = 0, \$Next_Arr, \$Next_Dep
Global \$div, \$percent
Global \$a, \$b

for \$i = 1 to 10000
\$Next_Arr = rand_exp(6)
\$Next_Dep = \$Next_Arr + rand_exp(10) ;next arrival (enter to system) and next departure (output)

;~ While (\$AEC < 100) ;number of inputs!
if (\$Next_Arr < \$Next_Dep) Then
if (\$SS = 0) Then
\$SS = 1 ;server status
\$Next_Arr = \$Next_Arr + rand_exp(6)
Else
If (\$QL = 9) Then ;queue lenth is 9
\$LEC += 1 ;number of loss packets!
\$Next_Arr = \$Next_Arr + rand_exp(6)
Else
\$QL += 1
\$NextArr = \$Next_Arr + rand_exp(6)
EndIf

if (\$QL = 0) Then
\$SS = 0
\$Next_Dep = \$Netxt_Arr + rand_exp(10)
Else
\$QL -= 1
\$Next_Dep = \$Next_Dep + rand_exp(10)
EndIf
EndIf
EndIf
;~ WEnd
Next

test()
Func test()
\$div = \$LEC / 10000
\$percent = \$div * 100 ;calculate loss packets
ConsoleWrite ("Loss Packets percent: " & \$percent & "%" &@CRLF)
ConsoleWrite ("Number of loss packets: " & \$LEC & @CRLF)

EndFunc
;--------------------- exponential distribution formula (where I have problem)----------------------
Func rand_exp(\$lambda)
\$a = Random(0,1,0)
\$b = (Log(1-\$a)) / -(\$lambda)
\$AEC += 1
EndFunc```

Share on other sites
Posted (edited)

As I said before, the C++ code that you are using as a guide (MM1.txt) is NOT a working example.  You can try to convert that code into AutoIt all you want and it will never give you the results you are looking for.     Find a working example of M/M/1 queue code, in any language, and start from there.

This is a prime example of G.I.G.O (Garbage In = Garbage Out).

Edited by TheXman
Fixed a typo

Whoever said that there's no such thing as a dumb question, probably asked a lot of DUMB questions.  Dumb questions are ones that you can easily find the answer to on your own.

Share on other sites

@TheXman ok ok  just calm down! I wrote it by java and C++ too and I got correct resault! I think I 'd better give up! so... thank you

Share on other sites

You're welcome.

If you ever want help converting your "working" C++ (or Java) example into AutoIt, we'll be here.

Whoever said that there's no such thing as a dumb question, probably asked a lot of DUMB questions.  Dumb questions are ones that you can easily find the answer to on your own.

Create an account

Register a new account