Jump to content

exponential distribution M/M/1 queue


Recommended Posts

@RezaGRD

Post your efforts so we can see where your problems exists and help you correct them.

Edited by TheXman
Link to comment
Share on other sites

  • Moderators

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?

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
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

Link to comment
Share on other sites

  • Moderators

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

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

@RezaGRD

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
Link to comment
Share on other sites

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

Edited by RTFC
Link to comment
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

 

Link to comment
Share on other sites

@RezaGRD

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.  :mad2:   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
Link to comment
Share on other sites

@RezaGRD

:D  You're welcome.

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

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...