@@ -6,7 +6,7 @@ public void balanceMachines(int machineCount, int[][] jobs){
6
6
7
7
// ArrayList<ArrayList<ArrayList<Integer>>> jobsForMachine = new ArrayList<ArrayList<ArrayList<Integer>>>();
8
8
PriorityQueue <Machine > loads = new PriorityQueue <Machine >();
9
- for (int i =0 ; i <machineCount ; i ++){
9
+ for (int i =1 ; i <= machineCount ; i ++){
10
10
loads .add (new Machine (i ));
11
11
// jobsForMachine.add(new ArrayList<ArrayList<Integer>>());
12
12
}
@@ -18,32 +18,34 @@ public void balanceMachines(int machineCount, int[][] jobs){
18
18
// int i=smallestLoadMachine.getId();
19
19
// jobsForMachine.get(i).add(new ArrayList<Integer>(Arrays.asList(jobs[j][0], jobProcessingTime)) );
20
20
21
- System .out .println (smallestLoadMachine );
21
+ // System.out.println(smallestLoadMachine);
22
22
23
23
smallestLoadMachine .addJob (jobId , jobProcessingTime );
24
24
25
25
smallestLoadMachine .setCurrentLoad (smallestLoadMachine .getCurrentLoad () + jobProcessingTime );
26
26
loads .add (smallestLoadMachine ); //Adding machine back does increaseKey
27
27
28
- System .out .println (smallestLoadMachine +"\n " );
28
+ // System.out.println(smallestLoadMachine+"\n");
29
29
}
30
30
31
- int makespan = 0 ;
31
+ int makespan = loads .peek ().getCurrentLoad ();
32
+ int makespanMachineId = loads .peek ().getId ();
32
33
System .out .println ("Jobs Assignments:" );
33
- for ( int i = 0 ; !loads .isEmpty (); i ++ ){
34
+ while ( !loads .isEmpty ()){
34
35
Machine machine = loads .remove ();
35
36
int machineLoad = machine .getCurrentLoad ();
36
37
System .out .println ("Machine " +machine .getId ()+" (Load=" +machineLoad +"):" +"\n Jobs in Order Assigned" );
37
38
if (machineLoad >makespan ){
38
39
makespan =machineLoad ;
40
+ makespanMachineId =machine .getId ();
39
41
}
40
42
ArrayList <ArrayList <Integer >> assignedJobs = machine .getJobs ();
41
43
for (ArrayList <Integer > job : assignedJobs ){
42
44
System .out .println ("Job " +job .get (0 )+" (Processing Time=" +job .get (1 )+")" );
43
45
}
44
46
System .out .println ();
45
47
}
46
- System .out .println ("\n Makespen =" +makespan +"\n " );
48
+ System .out .println ("Makespan =" +makespan +" (From Machine " + makespanMachineId + ") \n \n " );
47
49
48
50
}
49
51
@@ -94,11 +96,11 @@ public static void main(String[] args) {
94
96
int [][] jobs1 = {
95
97
{1 , 2 },
96
98
{2 , 2 },
97
- {3 , 3 },
98
- {4 , 1 },
99
- {5 , 4 }
99
+ {3 , 2 },
100
+ {4 , 2 },
101
+ {5 , 5 }
100
102
};
101
- // loadBalancer.balanceMachines(machineCount1, jobs1);
103
+ loadBalancer .balanceMachines (machineCount1 , jobs1 );
102
104
103
105
int machineCount2 = 3 ;
104
106
int [][] jobs2 = {
@@ -109,6 +111,17 @@ public static void main(String[] args) {
109
111
{5 , 19 }
110
112
};
111
113
loadBalancer .balanceMachines (machineCount2 , jobs2 );
114
+
115
+ int machineCount3 = 3 ;
116
+ int [][] jobs3 = {
117
+ {1 , 2 },
118
+ {2 , 2 },
119
+ {3 , 6 },
120
+ {4 , 3 },
121
+ {5 , 4 },
122
+ {6 , 2 }
123
+ };
124
+ loadBalancer .balanceMachines (machineCount3 , jobs3 );
112
125
}
113
126
114
127
}
0 commit comments