|
1 | 1 | # Load Balancing Problem Approximation Algorithm
|
2 | | -Approximation Algorithm for balancing loads on machines. (Could be applied to processes management on a CPU). Does not guarantee an optimal solution, but instead, the algorithm guarantees that its solution is within a factor of 1.5 of the optimal solution. |
| 2 | +Approximation Algorithm for balancing job loads on machines. (Could be applied to processes management on a CPU). Does not guarantee an optimal solution, but instead, a solution is within a factor of 1.5 of the optimal solution. |
3 | 3 |
|
4 | 4 | ## Problem Statement
|
5 | 5 | - `M` identical machines
|
6 | 6 | - `N` jobs
|
7 | 7 | - Each jobs has processing time **T<sub>j</sub>**
|
8 | | -- Let `J(i)` be the subset of jobs assigned to machine `i` |
9 | | -- The load of machine `i` is **L<sub>i</sub>** = sum of the processing times for the jobs |
| 8 | +- `J(i)` is the subset of jobs assigned to machine `i` |
| 9 | +- The load of machine `i` is **L<sub>i</sub>** = sum of the processing times for the jobs on that machine |
10 | 10 |
|
11 | 11 | **Makespan** = the maximum of the loads on the machines (the machine with the largest load)
|
12 | | -***Goal:* Minimize the Makespan** |
| 12 | +**Goal: Minimize the Makespan** |
13 | 13 |
|
14 | 14 | ## Solution
|
15 | 15 | Assign each job to a machine to minimize makespan
|
@@ -56,20 +56,20 @@ Proof involves complicated sigma notation and can be found in the references
|
56 | 56 | ## Usage
|
57 | 57 | **Machine ID's are meaningless since machines are identical, they're created for readability.
|
58 | 58 | But the algorithm still creates the job assignments on the machines according to the greedy strategy**
|
59 | | -- `int machineCount` parameter for `balanceMachines()`is how many machines exist in the problem |
| 59 | +- `int machineCount` parameter is how many machines there are |
60 | 60 | - `int[][] jobs` is a 2D array containing the jobs
|
61 | 61 | - `jobs[i]` is an array represents a job
|
62 | 62 | - `jobs[i][0]` is the **Job Id or name**
|
63 | 63 | - `jobs[i][1]` is the **Processing time**
|
64 | 64 |
|
65 | 65 | ## Code Details
|
66 | | -- Unlike the pseudocode, this version keeps the jobs assigned to a machine inside the `Machine` object in the Priority Queue |
| 66 | +- Unlike the pseudocode, the jobs assigned to a machine are inside the `Machine` object in the Priority Queue |
67 | 67 | - 1st Creates `M` machines with unique Id's
|
68 | | -- Then loop over the jobs and assign the job with the longest processing time to the smallest load machine |
| 68 | +- Then loop over the jobs and assigns the job with the longest processing time to the machine with the smallest current load |
69 | 69 | - Java's Priority Queue doesn't really have an `IncreaseKey()` method so the same effect is achieved by removing the machine from the Queue, updating the Machine's `currentLoad` and then adding the Machine back to the Queue
|
70 | 70 | - `Machine` class represents a machine
|
71 | 71 | - **Some Important Parts of a Machine**
|
72 | | - - `id` is the **id or name of the machine** |
| 72 | + - `id` is the **ID or name of the machine** |
73 | 73 | - `currentLoad` is the sum of the processing times of the jobs currently assigned to the machine
|
74 | 74 | - `jobs` is a 2D ArrayList containing the jobs currently assigned to the machine
|
75 | 75 | - `Machine` class **overrides** `compareTo()` from the `Comparable` interface so that the `PriotityQueue is always has the smallest load machine at the top
|
|
0 commit comments