Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By JosAH

Thread: help me to simulate single queue in java

  1. #1
    anita is offline Member
    Join Date
    Jan 2013
    Posts
    2
    Rep Power
    0

    Default help me to simulate single queue in java

    hello my friends, i have a problem in java, i have a programm and it runs successfully, but it doesnt make any outputs!
    can u help me please?
    its necessary.

    this is my project, please tell me what can i do?

    public class Sim {
    // Class Sim variables
    static double Clock, MeanInterArrivalTime, MeanServiceTime, SIGMA,
    LastEventTime,
    TotalBusy, MaxQueueLength, SumResponseTime;
    static long NumberOfCustomers, QueueLength, NumberInService,
    TotalCustomers, NumberOfDepartures, LongService;
    final static int arrival = 1;
    final static int departure = 2;
    static EventList FutureEventList;
    static Queue Customers;
    static Random stream;
    static void main(String argv[]) {
    MeanInterArrivalTime = 4.5; MeanServiceTime = 3.2;
    SIGMA = 0.6; TotalCustomers = 1000;
    long seed =1000; //Long.parseLong(argv[0]);
    stream = new Random(seed); // initialize rng stream
    FutureEventList = new EventList();
    Customers = new Queue();
    Initialization();
    // Loop until first "TotalCustomers" have departed
    while(NumberOfDepartures < TotalCustomers ) {
    Event evt = (Event)FutureEventList.getMin(); // get imminent event
    FutureEventList.dequeue(); // be rid of it
    Clock = evt.get_time(); // advance simulation time
    if( evt.gettype() ==arrival ) ProcessArrival(evt);
    else ProcessDeparture(evt);
    }
    ReportGeneration();
    }
    // seed the event list with TotalCustomers arrivals
    static void Initialization() {
    Clock = 0.0;
    QueueLength = 0;
    NumberInService = 0;
    LastEventTime = 0.0;
    TotalBusy = 0 ;
    MaxQueueLength = 0;
    SumResponseTime = 0;
    NumberOfDepartures = 0;
    LongService = 0;
    // create first arrival event
    Event evt = new Event(arrival, exponential(stream, MeanInterArrivalTime));
    FutureEventList.enqueue( evt );
    }
    static void ProcessArrival(Event evt) {
    Customers.enqueue(evt);
    QueueLength++;
    // if the server is idle, fetch the event, do statistics
    // and put into service
    if( NumberInService == 0) ScheduleDeparture();
    else TotalBusy += (Clock - LastEventTime); // server is busy
    // adjust max queue length statistics
    if (MaxQueueLength < QueueLength) MaxQueueLength =
    QueueLength;
    // schedule the next arrival
    Event next_arrival = new Event(arrival,
    Clock+exponential(stream, MeanInterArrivalTime));
    FutureEventList.enqueue( next arrival );
    LastEventTime = Clock;
    }
    static void ScheduleDeparture() {
    double ServiceTime;
    // get the job at the head of the queue
    while (( ServiceTime = normal(stream, MeanServiceTime, SIGMA)) < 0 );
    Event depart = new Event(departure,Clock+ServiceTime);
    FutureEventList.enqueue( depart );
    NumberInService = 1;
    QueueLength--;
    }
    static void ProcessDeparture(Event e) {
    // get the customer description
    Event finished = (Event) Customers.dequeue();
    // if there are customers in the queue then schedule
    // the departure of the next one
    if( QueueLength > 0 ) ScheduleDeparture();
    else NumberInService = 0;
    // measure the response time and add to the sum
    double response = (Clock - finished.get_time());
    SumResponseTime += response;
    if( response > 4.0 ) LongService++; // record long service
    TotalBusy += (Clock -LastEventTime );
    NumberOfDepartures++;
    LastEventTime = Clock;
    }
    static void ReportGeneration() {
    double RHO = TotalBusy/Clock;
    double AVGR = SumResponseTime/TotalCustomers;
    double PC4 = ((double)LongService)/TotalCustomers;
    System.out.println( "SINGLE SERVER QUEUE SIMULATION -GROCERY STORE CHECKOUT COUNTER ");
    System.out.println( "\tMEAN INTERARRIVAL TIME "+ MeanInterArrivalTime );
    System.out.println( "\tMEAN SERVICE TIME "+ MeanServiceTime );
    System.out.println( "\tSTANDARD DEVIATION OF SERVICE TIMES+ SIGMA );
    System.out.println( "\tNUMBER OF CUSTOMERS SERVED"+ TotalCustomers );
    System.out.println();
    System.out.println( "\tSERVER UTILIZATION+ RHO );
    System.out.println( "\tMAXIMUM LINE LENGTH" + MaxQueueLength );
    System.out.println( "\tAVERAGE RESPONSE TIME" + AVGR + " MINUTES" );
    System.out.println( "\tPROPORTION WHO SPEND FOUR ");
    System.out.println( "\t MINUTES OR MORE IN SYSTEM" + PC4 );
    System.out.println( "\tSIMULATION RUNLENGTH" + Clock + " MINUTES" );
    System.out.println( "\tNUMBER OF DEPARTURES" + TotalCustomers );

    }
    static double exponential(Random rng, double mean) {
    return -mean*Math.log( rng.nextDouble() );
    }
    static double SaveNormal;
    static int NumNormals = 0;
    static final double PI = 3.1415927 ;
    static double normal(Random rng, double mean, double sigma) {
    double ReturnNormal; // should we generate two normals?
    if(NumNormals == 0 ) {
    double r1 = rng.nextDouble();
    double r2 = rng.nextDouble();
    ReturnNormal = Math.sqrt(-2*Math.log(r1))*Math.cos(2*PI*r2);
    SaveNormal = Math.sqrt(-2*Math.log(r1))*Math.sin(2*PI*r2);
    NumNormals = 1;
    } else {
    NumNormals = 0;
    ReturnNormal = SaveNormal;
    }
    return ReturnNormal*sigma + mean ;


    }

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,691
    Rep Power
    8

    Default Re: help me to simulate single queue in java

    Please do not privately message users asking them to help you.

    If you want help, you'll have to do a few things first: use code tags, tell us what you've done and where the code breaks, and ask a more specific technical question. You're going to have to do some debugging, by stepping through this with a debugger or at least adding some print statements. When does the program's execution differ from what you expect?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: help me to simulate single queue in java

    Quote Originally Posted by KevinWorkman View Post
    Please do not privately message users asking them to help you.
    Agreed. The forum is where you ask for help.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: help me to simulate single queue in java

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    anita is offline Member
    Join Date
    Jan 2013
    Posts
    2
    Rep Power
    0

    Default Re: help me to simulate single queue in java

    excuse me , this is a project that i wanna work on it, ok?
    and i wanted help, what are u doing is not helping me!
    it doesnt work, and i want it to print outputs, can any body help?

  6. #6
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    12,999
    Blog Entries
    7
    Rep Power
    19

    Default Re: help me to simulate single queue in java

    The last link supplied by Darryl (the one from France) contains exacly the same Java code (incorrect capitalization and all); can't you contact the author for an explanation of the code; reverse engineering is not my hobby.

    kind regards,

    Jos
    DarrylBurke likes this.
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. How to Simulate Deadlock Prevention in Java?
    By phaulyne08 in forum Threads and Synchronization
    Replies: 1
    Last Post: 03-10-2012, 02:32 PM
  2. Replies: 0
    Last Post: 05-27-2011, 08:46 AM
  3. Single thread to handle queue based logging
    By impacted in forum Threads and Synchronization
    Replies: 5
    Last Post: 04-28-2011, 10:28 PM
  4. Single thread to handle queue based logging
    By impacted in forum New To Java
    Replies: 4
    Last Post: 04-28-2011, 10:25 PM
  5. Simulate a Network using Java
    By fung1223 in forum New To Java
    Replies: 0
    Last Post: 01-13-2010, 10:46 AM

Posting Permissions

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