1. Member
Join Date
Aug 2010
Posts
67
Rep Power
0

## 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

2. Senior Member
Join Date
Feb 2010
Location
Ljubljana, Slovenia
Posts
470
Rep Power
8
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.

3. 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

4. Member
Join Date
Aug 2010
Posts
67
Rep Power
0
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?
Java 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"```

5. 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):

Java 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(α);
}
}
}
}```

6. Senior Member
Join Date
Dec 2010
Posts
165
Rep Power
7
Originally Posted by dewitrydan
[code]

while(c<=480):
[code]
with Python, there is no need to use brackets
Java Code:
`while c<=480:`

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•