Simulation of Multi Server Queuing System

Multi server means real world   system such as car workshop, Barger Shop etc.

Code is bellow for Server class(Server.java):


/******************************
*                            *
* @author Hizbul Bahar *
*                            *
******************************/
class Server
{
int Queue_size = 32000;
int next_event_type;
int num_custs_delayed;
int num_events=2;
int num_in_q;
int server_status;
int num_delays_required;
double area_num_in_q;
double area_server_status;
double sim_time;
double time_last_event;
double total_of_delays;
double mean_interarrival;
double mean_service;

double[] time_arrival = new double[Queue_size];;
double[] time_next_event=new double[3];

void initialize()
{
sim_time = 0;

server_status = 0;
num_in_q = 0;
time_last_event = 0;

num_custs_delayed = 0;
total_of_delays = 0;
area_num_in_q = 0;
area_server_status = 0;

time_next_event[1] = sim_time + MultiServerQueueingSystem.expon(mean_interarrival) ;
time_next_event[2] = 1.0e+30;
}

void timing()
{
int   i;
double min_time_next_event = 1.0e+29;

next_event_type = 0;

for (i = 1; i <= num_events; ++i)
{
if (time_next_event[i] < min_time_next_event)
{
min_time_next_event = time_next_event[i];
next_event_type = i;
}
}


if (next_event_type == 0)
{
System.out.println("\nEvent list empty at time"+ sim_time);
}

sim_time = min_time_next_event;
}

void arrive(double time)
{
double delay;

time_next_event[1] = time;

if (server_status == 1)
{
num_in_q++;
time_arrival[num_in_q] = sim_time;
}

else
{
delay = 0;
total_of_delays += delay;

num_custs_delayed++;
server_status = 1;

time_next_event[2] = sim_time + MultiServerQueueingSystem.expon(mean_service);
}
}

void depart()
{
int   i;
double delay;

if (num_in_q == 0)
{
server_status = 0;
time_next_event[2] = 1.0e+30;
}

else
{
num_in_q--;

delay = sim_time - time_arrival[1];
total_of_delays += delay;

num_custs_delayed++;
time_next_event[2] = sim_time + MultiServerQueueingSystem.expon(mean_service);

for (i = 1; i <= num_in_q; i++)
time_arrival[i] = time_arrival[i + 1];
}
}

void report()
{
System.out.println( "TOtal customer uses this server " + num_custs_delayed + "\n");
System.out.println( "Average delay in queue minutes  " + total_of_delays / num_custs_delayed + "\n");
System.out.println( "Average number in queue  " + area_num_in_q / sim_time + "\n");
System.out.println( "Server utilization  " + area_server_status / sim_time + "\n");
}

void update_time_avg_stats()
{
double time_since_last_event;

time_since_last_event = sim_time - time_last_event;
time_last_event = sim_time;

area_num_in_q += num_in_q * time_since_last_event;

area_server_status += server_status * time_since_last_event;
}
}

Save this code as Server.java and then…


import java.io.*;
import java.util.Random;
import javax.swing.*;

/******************************
*                            *
* @author Hizbul Bahar *
*                            *
******************************/

public class MultiServerQueueingSystem
{
static Server server1;
static Server server2;
static Server server3;
static Server server4;
static Server server5;
static Random random;
static int is_server4 = 0;

public static void main(String[] args)throws IOException
{
server1 = new Server();
server2 = new Server();
server3 = new Server();
server4 = new Server();
server5 = new Server();

server1.mean_interarrival=Double.valueOf(JOptionPane.showInputDialog("Enter Mean Interarrival time:"));
server2.mean_interarrival=server1.mean_interarrival;
server3.mean_interarrival=server1.mean_interarrival;

server1.mean_service=Double.valueOf(JOptionPane.showInputDialog("Enter Mean Service time of server1:"));
server2.mean_service=Double.valueOf(JOptionPane.showInputDialog("Enter Mean Service time of server2:"));
server3.mean_service=Double.valueOf(JOptionPane.showInputDialog("Enter Mean Service time of server3:"));
server4.mean_service=Double.valueOf(JOptionPane.showInputDialog("Enter Mean Service time of server4:"));
server5.mean_service=Double.valueOf(JOptionPane.showInputDialog("Enter Mean Service time of server5:"));

int total_customer = Integer.parseInt(JOptionPane.showInputDialog("Enter Number of Customer:"));

System.out.println("Single-server queueing system\n");
System.out.println("Mean interarrival time  "+server1.mean_interarrival+" minutes\n");
System.out.println("Mean service time of server1 "+server1.mean_service+" minutes\n");
System.out.println("Mean service time of server2 "+server2.mean_service+" minutes\n");
System.out.println("Mean service time of server3 "+server3.mean_service+" minutes\n");
System.out.println("Mean service time of server4 "+server4.mean_service+" minutes\n");
System.out.println("Mean service time of server5 "+server5.mean_service+" minutes\n");
System.out.println("Number of customer  "+ total_customer + "\n\n");

random = new Random(total_customer);

server1.initialize();
server2.initialize();
server3.initialize();
server4.initialize();
server5.initialize();

int option = JOptionPane.showConfirmDialog(null, "Are you want to end by simulation time?\nIf No it simulated by total customer.");

if(option==1)
{
while(server3.num_custs_delayed < total_customer)
{
double choice = random.nextDouble();
if(choice <= 0.8)
{
server1_activity();
}
else if(choice <= 0.95)
{
server2_activity();
}
else
{
server3_activity(server3.sim_time + expon(server3.mean_interarrival));
}
}
}
else if(option==0)
{
double sim_time = Double.valueOf(JOptionPane.showInputDialog("Enter simulation time:"));
while(server3.sim_time < sim_time)
{
double choice = random.nextDouble();
if(choice <= 0.8)
{
server1_activity();
}
else if(choice <= 0.95)
{
server2_activity();
}
else
{
server3_activity(server3.sim_time + expon(server3.mean_interarrival));
}
}
}
else
{
System.exit(0);
}

System.out.println("\n\nReport for server 1:\n--------------------\n");
server1.report();
System.out.println("\n\nReport for server 2:\n--------------------\n");
server2.report();
System.out.println("\n\nReport for server 3:\n--------------------\n");
server3.report();
System.out.println("\n\nReport for server 4:\n--------------------\n");
server4.report();
System.out.println("\n\nReport for server 5:\n--------------------\n");
server5.report();
System.out.println("\n\nTime simulation ended minutes  "+ (server1.sim_time+server2.sim_time+server3.sim_time+server4.sim_time+server5.sim_time) +"\n");
System.out.println("Avarage waiting time in system "+ (server3.sim_time / server3.num_custs_delayed) +"\n");
}

private static void server1_activity()
{
server1.timing();

server1.update_time_avg_stats();

switch (server1.next_event_type)
{
case 1: server1.arrive(server1.sim_time+expon(server1.mean_interarrival));
break;
case 2: server1.depart();
server3_activity(server1.sim_time);
server1_activity();
}
}

private static void server2_activity()
{
server2.timing();

server2.update_time_avg_stats();

switch (server2.next_event_type)
{
case 1: server2.arrive(server2.sim_time+expon(server2.mean_interarrival));
break;
case 2: server2.depart();
server3_activity(server2.sim_time);
server2_activity();
}
}

private static void server3_activity(double time)
{
server3.timing();

server3.update_time_avg_stats();

switch (server3.next_event_type)
{
case 1: server3.arrive(time);
break;
case 2: server3.depart();
if(server4.num_in_q < server5.num_in_q)
{
server4_activity(server3.sim_time);
is_server4 = 1;
}
else if(server5.num_in_q < server4.num_in_q)
{
server5_activity(server3.sim_time);
is_server4 = 0;
}
else
{
if(is_server4 == 1)
{
server5_activity(server3.sim_time);
is_server4 = 0;
}
else
{
server4_activity(server3.sim_time);
is_server4 = 1;
}
}
server3_activity(time);
}
}

private static void server4_activity(double time)
{
server4.timing();

server4.update_time_avg_stats();

switch (server4.next_event_type)
{
case 1: server4.arrive(time);
break;
case 2: server4.depart();
server4_activity(time);
}
}

private static void server5_activity(double time)
{
server5.timing();

server5.update_time_avg_stats();

switch (server5.next_event_type)
{
case 1: server5.arrive(time);
break;
case 2: server5.depart();
server5_activity(time);
}
}

static double expon(double  mean)
{
return -mean * Math.log(random.nextDouble());
}
}

Save this file as MultiServerQueueingSystem.java

 

To get complete project knock me through email, mobile or commented bellow as your requirement.

Advertisements

Software Engineer at The Jaxara IT Ltd , Dhaka , Bangladesh

Tagged with: ,
Posted in JAVA
27 comments on “Simulation of Multi Server Queuing System
  1. Mohammed Alkaff says:

    Very Nice, Thanks.
    Could you please send me the complete project?
    Email : myk2000@gmail.com

  2. Ron webb says:

    Can you please email me the code
    Email: Ronwebb_55@hotmail.com

  3. Nikos Giannakis says:

    Could you please send me the complete code?

  4. nanu jindal says:

    may u send me the whole project??

  5. may u send me the whole project?
    on harethfareed78@gmail.com
    with many thanks bro

  6. mayuri says:

    Please send me whole project on wavhal.mayuri@gmail.com …Thank you

  7. Lu Zou says:

    Could you please email me the complete code, thanks a lot!
    Email: zoulu1990330@gmail.com

  8. www.hoanghiem.org says:

    Hello, thanks for sharing the solution. Can you help email me the complete code – thanks again. email: nguyentuc@hoanghiem.org

  9. james says:

    pls this will help me if you will send me the project file thanks

  10. neha says:

    what if i want to this code by linked list

  11. samah kamal says:

    please send me complete project

  12. please send me complete project

  13. […] Simulation of Multi Server Queuing System | … – 19/05/2013  · 15 comments on “ Simulation of Multi Server Queuing System ” Mohammed Alkaff says: July 15, … You are commenting using your WordPress.com … […]

  14. maria says:

    please send me this complete project

  15. Proaye says:

    Hi, I’d really appreciate if you send me the entire code as I really need your help. Thank you very much !
    Email : proayeassymessi@gmail.com

  16. mazzzzzzh@gmail.com says:

    Hi,Can you please send me your complete project?Thank you .
    mazzzzzzh@gmail.com

  17. mazzzzzzh@gmail.com says:

    Could you please email me the complete code, thanks a lot!

    mazzzzzzh@gmail.com

  18. Hi sir, can you send me the complete project? Much appreciate
    Email: 0109572@kdu-online.com

  19. limlim says:

    Hi, can i have the complete codes please. I need some help and guidance with my project.

  20. limlim says:

    Hi can you send me the complete code for this project? liml13112@gmail.com

  21. limlim says:

    Hi, can you send me the complete code? liml13112@gmail.com Thanks.

  22. Please can you send me the complete project to anyaehiestanley@gmail.com

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: