Reza10101 Posted June 1, 2018 Share Posted June 1, 2018 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 Link to comment Share on other sites More sharing options...
TheXman Posted June 1, 2018 Share Posted June 1, 2018 (edited) @RezaGRD Post your efforts so we can see where your problems exists and help you correct them. Edited June 1, 2018 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted June 1, 2018 Moderators Share Posted June 1, 2018 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 More sharing options...
Reza10101 Posted June 2, 2018 Author Share Posted June 2, 2018 @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 More sharing options...
Moderators JLogan3o13 Posted June 2, 2018 Moderators Share Posted June 2, 2018 My question is if you have it working in C++, why shoehorn it into a slower language? Earthshine 1 "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 More sharing options...
TheXman Posted June 2, 2018 Share Posted June 2, 2018 (edited) @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 June 2, 2018 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
RTFC Posted June 2, 2018 Share Posted June 2, 2018 (edited) Here's one possible way, in this case to obtain a sigmoid curve. Edited June 2, 2018 by RTFC My Contributions and Wrappers Spoiler BitMaskSudokuSolver BuildPartitionTable CodeCrypter CodeScanner DigitalDisplay Eigen4AutoIt FAT Suite HighMem MetaCodeFileLibrary OSgrid Pool RdRand SecondDesktop SimulatedAnnealing Xbase I/O Link to comment Share on other sites More sharing options...
Reza10101 Posted June 2, 2018 Author Share Posted June 2, 2018 @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%. expandcollapse popup#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 More sharing options...
TheXman Posted June 2, 2018 Share Posted June 2, 2018 (edited) @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. 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 June 2, 2018 by TheXman Fixed a typo CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
Reza10101 Posted June 2, 2018 Author Share Posted June 2, 2018 @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 Link to comment Share on other sites More sharing options...
TheXman Posted June 2, 2018 Share Posted June 2, 2018 @RezaGRD You're welcome. If you ever want help converting your "working" C++ (or Java) example into AutoIt, we'll be here. CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now