Results 1 to 6 of 6
  1. #1
    dewitrydan is offline Member
    Join Date
    Aug 2010
    Posts
    67
    Rep Power
    0

    Default 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. #2
    m00nchile is offline Senior Member
    Join Date
    Feb 2010
    Location
    Ljubljana, Slovenia
    Posts
    470
    Rep Power
    5

    Default

    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.
    Ever seen a dog chase its tail? Now that's an infinite loop.

  3. #3
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,663
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by m00nchile View Post
    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
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    dewitrydan is offline Member
    Join Date
    Aug 2010
    Posts
    67
    Rep Power
    0

    Default

    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. #5
    Hibernate's Avatar
    Hibernate is offline Senior Member
    Join Date
    Dec 2010
    Location
    Stockholm, Sweden
    Posts
    222
    Blog Entries
    9
    Rep Power
    4

    Default

    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(α);
                }
            }
        }
    }
    Ex animo! Hibernate
    Java, Arch Linux, C, GPL v3, Bash, Eclipse, Linux VT, GNOME 2 and many buttons on windows.

  6. #6
    JavaHater is offline Senior Member
    Join Date
    Dec 2010
    Posts
    165
    Rep Power
    4

    Default

    Quote Originally Posted by dewitrydan View Post
    [code]

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

Similar Threads

  1. Algorithm help? :)
    By Mirix in forum New To Java
    Replies: 6
    Last Post: 05-24-2010, 03:08 AM
  2. Need some help in an algorithm
    By ea09530 in forum New To Java
    Replies: 3
    Last Post: 04-04-2010, 02:13 PM
  3. Help with an Algorithm
    By Manfizy in forum New To Java
    Replies: 22
    Last Post: 07-03-2009, 08:16 AM
  4. Java Algorithm problems?
    By JavaInLove in forum New To Java
    Replies: 8
    Last Post: 07-02-2008, 09:50 AM
  5. Help with algorithm
    By susan in forum New To Java
    Replies: 1
    Last Post: 07-13-2007, 11:26 PM

Posting Permissions

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