queuing simulation

Discussion in 'Java' started by justplain.kzn@gmail.com, May 3, 2007.

  1. Guest

    Hi,

    I am new to java and I am trying to implement a simple queuing system
    using the poission spread for arrivals. To keep things simple I am
    initially trying to populate the queue and print.


    Below is a snippet of my code - my values seem out of wack and I have
    since gotten my knickers in a knot. Any assistance/pointers with a
    simple and straightforward implementation will greatly appreciated.


    Thanks in advance


    args[0]=0.2
    args[1]=0.1


    public class MM1Queue {


    public static void main(String[] args) {
    double lambda = Double.parseDouble(args[0]); // arrival rate
    double mu = Double.parseDouble(args[1]); // service rate


    Queue<Double> q = new Queue<Double>(); // arrival
    times of customers
    double nextArrival = Math.exp(lambda); // time of next
    arrival
    double nextDeparture = Double.POSITIVE_INFINITY; // time of
    next departure
    // double nextDeparture = 0.2; // time of next departure
    System.out.println ("nd " + nextDeparture);
    System.out.println ("na " + nextArrival);
    //System.exit(0);


    // simulate an M/M/1 queue
    int counter=0;
    while (true) {
    counter++;


    // it's an arrival
    if (nextArrival <= nextDeparture) {
    if (q.isEmpty()) nextDeparture = nextArrival +
    Math.exp(mu);
    q.enqueue(nextArrival);
    System.out.printf("Queue = %6.2f\n", nextArrival);
    System.out.println ("Size = " + q.size());
    nextArrival += Math.exp(lambda);
    }


    // it's a departure
    else {
    double wait = nextDeparture - q.dequeue();
    System.out.printf("Wait = %6.2f\n", wait);
    if (q.isEmpty()) nextDeparture =
    Double.POSITIVE_INFINITY;
    else nextDeparture += Math.exp(mu);


    }
    if (counter>100) break;


    } // while loop
    }
    , May 3, 2007
    #1
    1. Advertising

  2. On May 4, 7:50 am, wrote:
    > Hi,


    Lo. Please refrain from multi-posting, in future.
    <http://www.physci.org/codes/javafaq.html#xpost>

    (X-post to c.l.j.p./h., w/ f-u to c.l.j.h. only)

    Andrew T.
    Andrew Thompson, May 4, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dave Pink
    Replies:
    1
    Views:
    381
    =?Utf-8?B?VHJldm9yIEJlbmVkaWN0IFI=?=
    Jun 8, 2004
  2. =?Utf-8?B?cmVhd2F5?=

    Message Queuing has not been installed

    =?Utf-8?B?cmVhd2F5?=, Dec 22, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    2,708
    =?Utf-8?B?cmVhd2F5?=
    Dec 22, 2005
  3. pal
    Replies:
    2
    Views:
    334
  4. Sanjeev
    Replies:
    5
    Views:
    1,342
  5. Esben von Buchwald

    Protecting against callbacks queuing up?

    Esben von Buchwald, Aug 24, 2009, in forum: Python
    Replies:
    23
    Views:
    761
    Dennis Lee Bieber
    Aug 29, 2009
Loading...

Share This Page