# Algorithm problems..

• 01-01-2011, 02:39 PM
dewitrydan
Algorithm problems..
Hey there
I have to implement this flowchart into code.
But I am really confused, and I am not sure how to do it.
Could you please outline the algorithm or something for me? Thanks
http://i143.photobucket.com/albums/r.../flowchart.png
• 01-01-2011, 07:56 PM
m00nchile
I don't know about the random service/arrival times, but other that that I don't see how much clearer it can get. The rectangles are code to be executed and the tilted squares are if/else statements.
• 01-01-2011, 08:24 PM
JosAH
Quote:

Originally Posted by m00nchile
I don't know about the random service/arrival times, but other that that I don't see how much clearer it can get. The rectangles are code to be executed and the tilted squares are if/else statements.

Yup, and the arrows are goto statements and just because Java doesn't have gotos the entire thing can be solved using one big switch as the body of a big(ger) while statement.

kind regards,

Jos
• 01-01-2011, 09:02 PM
dewitrydan
I think I've done it.
But I've done it in python.
But I'm not sure if it is correct.
Can you have a quick look over this please?
Code:

```import math import random def simulator(alpha, beta):     ta = 0     ts = 0     c = 0     Q = 1         while(c<=480):         if ta<ts:             ts = ts - ta             c = c + ta             Q = Q + 1             random_number = random.random()             print "Random number is: "             print random_number             ta = -alpha*math.log(1-random_number)             while(Q == 0):                 c = c + ta                 Q = Q + 1                 random_number = random.random()                 ta = -alpha*math.log(1-random_number)         else:             ta = ta -ts             c = c + ts             Q = Q - 1             random_number = random.random()             ts = -beta*math.log(1-random_number)             while(Q == 0):                 c = c + ta                 Q = Q + 1                 random_number = random.random()                 ta = -alpha*math.log(1-random_number)                     print "Q equals: "         print Q         print "C equals: "         print c         print"\n"```
• 01-03-2011, 12:50 PM
Hibernate
Ahhh, sub-pixel rendering (Method C, Clear Type, &c)!

Seems to be correct, assume you have a reason for while(c<=480).
Java version (from diagram, not implementation):

Code:

```{     public static void simulator(final double α, final double β)     {         double ta, ts, c;         int Q = 1;         ta = ts = c = 0;                 for (;;) //Change to while (c <= 480) if you wish.         {             if (ta < ts)             {                 ts -= ta;                 c += ta;                 Q++;                 ta = random(α); //Implement your random method.             }             else             {                 ta -= ts;                 c += ts;                 Q--;                 ts = random(β);             }             while (Q == 0)             {                 c += ta;                 Q++;                 ta = random(α);             }         }     } }```
• 01-03-2011, 01:17 PM
JavaHater
Quote:

Originally Posted by dewitrydan
[code]

while(c<=480):
[code]

with Python, there is no need to use brackets
Code:

`while c<=480:`