⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mmsassignment.java

📁 排队的MMS模型
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
import java.lang.*;


class MMsAssignment {
		
     //Method to calculate the value of factorial 
     
     public static int factorial(int n){
       if (n == 0){
       	return 1;
        }
       else{
         return n * factorial (n-1);
       }
    }
    
    //Method to calculate the sum which will be used in Method P0 
     
     public static double sum(double l, double m, int s){
        double Q = 0;
    //Use "for" and the formulate calculate the sum
        for(int n = 0; n<= s-1; n++){
        double R=Math.pow(l/m,n)/factorial(n);
     	Q = Q + R;
       }
        return Q;
        
      }
      


	//Method to calculate the value of P0 which is the probability of 
    //there is no customer in the system
	 
	 public static double P0(double l, double m, int s){
	    double b,c,P;
	    
	    b = Math.pow(l/m,s)/factorial(s);
	    
	    c = 1/(1-l/(s*m));
	    
	    P = 1/(sum(l,m,s) + b*c);
	    return P;
	    }
	
	
	
	
	 //Method to calculate the value of Pn which is probability of exactly
	 // n customers in queuing system
     
     public static double Pn(double l, double m, int s, int i){
	
       	double Qn=0;
	
	    if (i>=0 && i<=s && s!=1){
		
		Qn=  Math.pow(l/m,i)/factorial(i)*P0(l,m,s);
		return Qn;
       }
       
	    else{
	    Qn=Math.pow(l/m,i)/factorial(s)/Math.pow(s,i-s)*P0(l,m,s);
        return Qn;  
       }
	
     }


      //Method to calculate pwq which is the probabilty of average waiting
      //time in the queue Wq
	 
	 public static double pwq(double l, double m, double pwq_0, int s, double t){
		double x = (-1) * s * m * (1 - l / (s * m)) * t;
		double pwq=(1 - pwq_0)*Math.exp(x)  ;	
	    return pwq;
	
	  }
	  
	  
	  
	  
   //use the method above in the main method
	public static void main(String args[]) {
	     
		double l = Double.parseDouble(args[0]);
		double m = Double.parseDouble(args[1]);
		int s = Integer.parseInt(args[2]);
		double t = Double.parseDouble(args[3]);
		
		//the values of l/(s*m) should less than 1
		if (l/(s*m)>1){
	System.out.println("The value input could not be execute in this programe");
	System.out.println("Because lambda bigger than mu*s, the queue would explode and grow without bound");
	System.out.println("Please try again to input the values");
		}
		
		
		else{
			
		//calculate the L_p which is the number of customers in the queue
	    double a = Math.pow((1 - (l / (s * m))),2);
	    double L_q= P0(l,m,s)*Math.pow(l/m,s)*(l/s / m)/(factorial(s)*a);
		
		//calculate the average waiting time in the queue
    	double W_q = L_q / l;
    	double pwq_0 = 0;
    	
    	//output the values lambda,mu,s, and Wq
    	//if we want output the interger value of the double type value,use(int)
    	
	  System.out.println ("Number of arrivals per bour (lambda) : " + (int)l );
      System.out.println ("Number served by 1 server per hour (mu) : " + (int)m);
      System.out.println ("Number of servers : " + s );
      System.out.println ("----------------------------------------------");
      
      System.out.println ("Average queuing time for "+ s + " servers " +W_q+ " hours");
      
      
	  System.out.println ("----------------------------------------------");
	  	
		//define an array for P
		double[] P =new double[s+1];
		P[0] = P0(l,m,s);
		
		System.out.println("P[0] = " + P[0]);
	
       //use the for mothed to output the Pn
		for (int i=1; i<s+1; i++){
			P[i] = Pn(l,m,s,i); 
			System.out.println("P["+ i +"] = " + P[i]);
			}
		
	 System.out.println ("----------------------------------------------");	
   
	//use the pwq method to obtain the P{Wq>t}
   	for(int j=0; j<s; j++){
			pwq_0 = pwq_0 + P[j];
			
		}
		//output the Pwq_0 and Pwq>3;
		System.out.println("P {Wq = 0} =" + pwq_0);
		System.out.println("P {Wq > 3} =" + pwq(l, m, pwq_0, s, t));
       
       }	
      }
       }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -