Advertisement
Dlrowniatrec_2110

Untitled

Jun 22nd, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.81 KB | None | 0 0
  1.  
  2. public class Process_PSP {
  3.    
  4.     public static int K;//no.of solutions
  5.     public static int X[][];//each one corresponding to (x1, x2, x3, x4)
  6.     public static int Obj[];
  7.     private static int Point_k;//The best one among K
  8.     public int []getBest_Sol(){
  9.        
  10.         return X[Point_k];
  11.     }
  12.     public int getBest_Obj(){
  13.        
  14.         return Obj[Point_k];
  15.        
  16.     }
  17.     public static void Process(int no_s, int ite){
  18.         K = no_s;
  19.         X = new int [K][4];
  20.         Obj = new int[K];
  21.         for(int k = 0; k < K; k++){
  22.             while(X[k][0]+X[k][1]+X[k][2]+X[k][3]!=25 ||
  23.                     5*X[k][0]+2*X[k][1]+X[k][2]+6*X[k][3]<10){
  24.                 X[k][0] = (int)(Math.random() * 51);
  25.                 X[k][1] = (int)(Math.random() * 51);
  26.                 X[k][2] = (int)(Math.random() * 51);
  27.                 X[k][3] = (int)(Math.random() * 51);
  28.                
  29.             }
  30.         }
  31.         for(int k = 0; k < K; k++){
  32.             Obj[k] = 3*X[k][0]+12*X[k][1]+9*X[k][2]+5*X[k][3]+
  33.                     3*X[k][0]*X[k][1]-10*X[k][0]*X[k][2]+
  34.                     6*X[k][0]*X[k][3]+1*X[k][1]*X[k][2]-
  35.                     5*X[k][1]*X[k][3]-2*X[k][2]*X[k][3];
  36.            
  37.         }
  38.         Point_k = 0;
  39.         for(int k = 1; k < K; k++){
  40.             if(Obj[k] < Obj[Point_k])Point_k = k;        
  41.         }
  42.         System.out.println("\nIncumbent Solution:");
  43.         System.out.println("x_1="+X[Point_k][0]+
  44.                          "\tx_2="+X[Point_k][1]+
  45.                          "\tx_3="+X[Point_k][2]+
  46.                          "\tx_4="+X[Point_k][3]+
  47.                          "\tObj="+Obj[Point_k]);
  48.         for(int iteration = 1; iteration < ite; iteration++){
  49.             for(int k = 0; k < K; k++){
  50.                 if(k != Point_k){
  51.                     while(X[k][0]+X[k][1]+X[k][2]+X[k][3]!=25 ||
  52.                             5*X[k][0]+2*X[k][1]+X[k][2]+6*X[k][3]<10){
  53.                         X[k][0] = (int)(Math.random() * 51);
  54.                         X[k][1] = (int)(Math.random() * 51);
  55.                         X[k][2] = (int)(Math.random() * 51);
  56.                         X[k][3] = (int)(Math.random() * 51);
  57.                        
  58.                     }
  59.                     Obj[k] = 3*X[k][0]+12*X[k][1]+9*X[k][2]+5*X[k][3]+
  60.                             3*X[k][0]*X[k][1]-10*X[k][0]*X[k][2]+
  61.                             6*X[k][0]*X[k][3]+1*X[k][1]*X[k][2]-
  62.                             5*X[k][1]*X[k][3]-2*X[k][2]*X[k][3];
  63.                 }
  64.             }
  65.            
  66.             for(int i = 1; i < K; i++){
  67.                 if(Obj[i] < Obj[Point_k]){
  68.                     Point_k = i;
  69.                 }
  70.             }
  71.             System.out.println("\nIncumbent Solution:");
  72.             System.out.println("x_1="+X[Point_k][0]+
  73.                              "\tx_2="+X[Point_k][1]+
  74.                              "\tx_3="+X[Point_k][2]+
  75.                              "\tx_4="+X[Point_k][3]+
  76.                              "\tObj="+Obj[Point_k]);
  77.             System.out.println("Obj = "+ Obj[Point_k]);
  78.            
  79.            
  80.            
  81.            
  82.         }
  83.     }
  84.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement