Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class win2 {
- public static int k;//k個suoltion
- public static int x[][];//(x1, x2, x3, x4)
- public static int obj[];
- private static int point_k;
- public int[] getBest_sol(){
- return x[point_k];
- }
- public int getBest_obj(){
- return obj[point_k];
- }
- public static void process(int no_s, int ite){
- k = no_s;
- x = new int[k][4];
- obj = new int[k];
- for(int i = 0; i < k; i++)
- {
- while(x[i][0] + x[i][1] + x[i][2] + x[i][3] != 25 || 5 * x[i][0] +
- 2 * x[i][1] + x[i][2] + 6 * x[i][3] < 10)
- {
- x[i][0] = (int)(Math.random() * 51);
- x[i][1] = (int)(Math.random() * 51);
- x[i][2] = (int)(Math.random() * 51);
- x[i][3] = (int)(Math.random() * 51);
- }
- }
- for(int i = 0; i < k; i++)
- {
- obj[i] = 3 * x[i][0] + 12 * x[i][1] + 9 * x[i][2] + 5 * x[i][3] +
- 3 * x[i][0] * x[i][1] - 10 * x[i][0] * x[i][2] +
- 6 * x[i][0] * x[i][3] + x[i][1] * x[i][2] -
- 5 * x[i][1] * x[i][3] - 2 * x[i][2] * x[i][3];
- }
- point_k = 0;
- for(int i = 1; i < k; i++)
- {
- if(obj[i] < obj[point_k])
- point_k = i;
- }
- System.out.println("\nIncumbent Solution: ");
- System.out.println("x_1 = " + x[point_k][0] + "\tx_2 = " + x[point_k][1] + "\tx_3 = " + x[point_k][2] + "\tx_4 = " + x[point_k][3]);
- System.out.println("obj = " + obj[point_k]);
- for(int iteration = 1; iteration < ite; iteration++)
- {
- for(int i = 0; i < k; i++)
- {
- if(i != point_k)
- {
- while(x[i][0] + x[i][1] + x[i][2] + x[i][3] != 25 || 5 * x[i][0] + 2 * x[i][1] + x[i][2] + 6 * x[i][3] < 10)
- {
- x[i][0] = (int)(Math.random() * 51);
- x[i][1] = (int)(Math.random() * 51);
- x[i][2] = (int)(Math.random() * 51);
- x[i][3] = (int)(Math.random() * 51);
- }
- obj[i] = 3 * x[i][0] + 12 * x[i][1] + 9 * x[i][2] + 5 * x[i][3] +
- 3 * x[i][0] * x[i][1] - 10 * x[i][0] * x[i][2] +
- 6 * x[i][0] * x[i][3] + x[i][1] * x[i][2] -
- 5 * x[i][1] * x[i][3] - 2 * x[i][2] * x[i][3];
- }
- }
- for(int i = 1; i < k; i++)
- {
- if(obj[i] < obj[point_k])
- point_k = i;
- }
- System.out.println("\nIncumbent Solution: ");
- System.out.println("x_1 = " + x[point_k][0] + "\tx_2 = " + x[point_k][1] + "\tx_3 = " + x[point_k][2] + "\tx_4 = " + x[point_k][3]);
- System.out.println("obj = " + obj[point_k]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement