Car Workshop(Multi Server Queuing) Simulation Using Java

In real world Car workshop is one of best example of Multi Server Queuing System. Here i’m trying to solve this kind of simulation using 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 " + 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 Random random;
static int direct_out = 0;

public static void main(String[] args)throws IOException
{
server1 = new Server();
server2 = new Server();
server1.mean_interarrival=Double.valueOf(JOptionPane.showInputDialog("Enter Mean Interarrival time:"));

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:"));

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("Number of customer  "+ total_customer + "\n\n");

random = new Random(total_customer);

server1.initialize();
server2.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(server1.num_custs_delayed < total_customer)
server1_activity();
while(server2.num_in_q > 0)
server2.depart();
}
else if(option==0)
{
double sim_time = Double.valueOf(JOptionPane.showInputDialog("Enter simulation time:"));
while(server2.sim_time < sim_time)
server1_activity();
}
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\nTime simulation ended "+ (server2.sim_time) +"\n");
System.out.println("Avarage waiting time in system "+ (server2.sim_time / server1.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();
if(random.nextDouble() <= 0.3)
server2_activity(server1.sim_time);
}
}

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

server2.update_time_avg_stats();

switch (server2.next_event_type)
{
case 1: server2.arrive(time);
break;
case 2: server2.depart();
server2_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
15 comments on “Car Workshop(Multi Server Queuing) Simulation Using Java
  1. Otman says:

    Hello sir could you please send me the full project of this program i shall learn from it a lot thanks

  2. Sofia A. says:

    Hello,can you please send me the full project?

  3. Radha C says:

    Hello Sir, can you please send me the full project copy of this program to my email radha.chakka235@gmail,com. That helps me to learn from it for my simulation class project.
    Thanks.

  4. fathi says:

    Hello sir could you please send me the full project of this program. i shall learn from it . thanks before. 😀

  5. Ruby Y. says:

    Hi, thanks for sharing. Could you please send me the complete project?

  6. Edwin T says:

    Hi, thanks for sharing. Could you please send me the complete project (waindtim@gmail.com)?

  7. could you please send the whole project? thank you
    nabile.eli@gmail.com

  8. hello could you please send the complete project? nabile.eli@gmail.com

  9. hello could you please send the complete project? thanmanolis@gmail.com

  10. Varsha says:

    please could u mail me the entire project on vrshrcks@gmail.com

  11. Lee Yong Hong says:

    Hi!
    could you please send this project to me too?
    thanks mate
    zzyonghongzz@gmail.com

  12. shaheema beegum p.v says:

    sir, can you send me the full code??

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: