@@ -6,7 +6,7 @@ public void balanceMachines(int machineCount, int[][] jobs){
66
77 // ArrayList<ArrayList<ArrayList<Integer>>> jobsForMachine = new ArrayList<ArrayList<ArrayList<Integer>>>();
88 PriorityQueue <Machine > loads = new PriorityQueue <Machine >();
9- for (int i =0 ; i <machineCount ; i ++){
9+ for (int i =1 ; i <= machineCount ; i ++){
1010 loads .add (new Machine (i ));
1111 // jobsForMachine.add(new ArrayList<ArrayList<Integer>>());
1212 }
@@ -18,32 +18,34 @@ public void balanceMachines(int machineCount, int[][] jobs){
1818 // int i=smallestLoadMachine.getId();
1919 // jobsForMachine.get(i).add(new ArrayList<Integer>(Arrays.asList(jobs[j][0], jobProcessingTime)) );
2020
21- System .out .println (smallestLoadMachine );
21+ // System.out.println(smallestLoadMachine);
2222
2323 smallestLoadMachine .addJob (jobId , jobProcessingTime );
2424
2525 smallestLoadMachine .setCurrentLoad (smallestLoadMachine .getCurrentLoad () + jobProcessingTime );
2626 loads .add (smallestLoadMachine ); //Adding machine back does increaseKey
2727
28- System .out .println (smallestLoadMachine +"\n " );
28+ // System.out.println(smallestLoadMachine+"\n");
2929 }
3030
31- int makespan = 0 ;
31+ int makespan = loads .peek ().getCurrentLoad ();
32+ int makespanMachineId = loads .peek ().getId ();
3233 System .out .println ("Jobs Assignments:" );
33- for ( int i = 0 ; !loads .isEmpty (); i ++ ){
34+ while ( !loads .isEmpty ()){
3435 Machine machine = loads .remove ();
3536 int machineLoad = machine .getCurrentLoad ();
3637 System .out .println ("Machine " +machine .getId ()+" (Load=" +machineLoad +"):" +"\n Jobs in Order Assigned" );
3738 if (machineLoad >makespan ){
3839 makespan =machineLoad ;
40+ makespanMachineId =machine .getId ();
3941 }
4042 ArrayList <ArrayList <Integer >> assignedJobs = machine .getJobs ();
4143 for (ArrayList <Integer > job : assignedJobs ){
4244 System .out .println ("Job " +job .get (0 )+" (Processing Time=" +job .get (1 )+")" );
4345 }
4446 System .out .println ();
4547 }
46- System .out .println ("\n Makespen =" +makespan +"\n " );
48+ System .out .println ("Makespan =" +makespan +" (From Machine " + makespanMachineId + ") \n \n " );
4749
4850 }
4951
@@ -94,11 +96,11 @@ public static void main(String[] args) {
9496 int [][] jobs1 = {
9597 {1 , 2 },
9698 {2 , 2 },
97- {3 , 3 },
98- {4 , 1 },
99- {5 , 4 }
99+ {3 , 2 },
100+ {4 , 2 },
101+ {5 , 5 }
100102 };
101- // loadBalancer.balanceMachines(machineCount1, jobs1);
103+ loadBalancer .balanceMachines (machineCount1 , jobs1 );
102104
103105 int machineCount2 = 3 ;
104106 int [][] jobs2 = {
@@ -109,6 +111,17 @@ public static void main(String[] args) {
109111 {5 , 19 }
110112 };
111113 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 );
112125 }
113126
114127}
0 commit comments