Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2b9945a

Browse files
Create README.md
1 parent a4c1519 commit 2b9945a

File tree

1 file changed

+75
-1
lines changed

1 file changed

+75
-1
lines changed

‎README.md

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,75 @@
1-
# load-balancing-problem-approximation-algorithm
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.
3+
4+
## Problem Statement
5+
- `M` identical machines
6+
- `N` jobs
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
10+
11+
**Makespan** = the maximum of the loads on the machines (the machine with the largest load)
12+
***Goal:* Minimize the Makespan**
13+
14+
## Solution
15+
Assign each job to a machine to minimize makespan
16+
There are m<sup>n</sup> different assignments of n jobs to m machines, which is **exponential**
17+
18+
**The greedy solution runs in polynomial time and gives a solution no more than 1.5 times the optimal makespan**
19+
Proof involves complicated sigma notation and can be found in the references
20+
21+
**Sort jobs by largest processing time 1st & keep assigning jobs to the machine with the smallest load**
22+
![](images/pseudocode.png)
23+
24+
## Runtime
25+
- O(n log n) for sorting jobs by processing time
26+
- O(n log m) for Greedy Balance & assigning jobs to machines
27+
- O(n log n) + O(n log m)
28+
- **⇒ O(n log n)**
29+
30+
## Input Jobs
31+
### Jobs1 Inputs
32+
<img src="images/jobs1.png" >
33+
34+
### Jobs1 Machine Assignments
35+
<img src="images/jobs1-machine-assignments.png" >
36+
37+
### Jobs2 Inputs
38+
<img src="images/jobs2.png" >
39+
40+
### Jobs2 Machine Assignments
41+
<img src="images/jobs2-machine-assignments.png" >
42+
43+
### Jobs3 Inputs
44+
<img src="images/jobs3.png" >
45+
46+
### Jobs3 Machine Assignments
47+
<img src="images/jobs3-machine-assignments.png" >
48+
49+
50+
## Usage
51+
**Machine ID's are meaningless since machines are identical, they're created for readability.
52+
But the algorithm still creates the job assignments on the machines according to the greedy strategy**
53+
- `int machineCount` parameter for `balanceMachines()` is how many machines exist in the problem
54+
- `int[][] jobs` is a 2D array containing the jobs
55+
- `jobs[i]` is an array represents a job
56+
- `jobs[i][0]` is the **Job Id or name**
57+
- `jobs[i][1]` is the **Processing time**
58+
59+
## Code Details
60+
- Unlike the pseudocode, this version keeps the jobs assigned to a machine inside the `Machine` object in the Priority Queue
61+
- 1st Creates `M` machines with unique Id's
62+
- Then loop over the jobs and assign the job with the longest processing time to the smallest load machine
63+
- 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
64+
- `Machine` class represents a machine
65+
- **Some Important Parts of a Machine**
66+
- `id` is the **id or name of the machine**
67+
- `currentLoad` is the sum of the processing times of the jobs currently assigned to the machine
68+
- `jobs` is a 2D ArrayList containing the jobs currently assigned to the machine
69+
- `Machine` class **overrides** `compareTo()` from the `Comparable` interface so that the `PriotityQueue is always has the smallest load machine at the top
70+
71+
## References
72+
- [Load Balancing - Approximation Algorithms - Kevin Wayne](http://www.serc.iisc.ernet.in/~simmhan/SE252-JAN2014/lectures/SE252.Jan2014.Lecture-17.pdf)
73+
- [Load Balancing - Arash Rafiey](https://www.sfu.ca/~arashr/lecture24.pdf)
74+
- [Load Balancing - Hantao Zhang](http://homepage.divms.uiowa.edu/~hzhang/c231/ch11.pdf)
75+
- [Load Balancing - Yogesh Simmhan](https://www.cs.princeton.edu/~wayne/kleinberg-tardos/pdf/11ApproximationAlgorithms.pdf)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /