{"id":20409696,"url":"https://github.com/sleekpanther/load-balancing-problem-approximation-algorithm","last_synced_at":"2025-09-24T04:31:20.422Z","repository":{"id":115108624,"uuid":"94026985","full_name":"SleekPanther/load-balancing-problem-approximation-algorithm","owner":"SleekPanther","description":"Approximation Algorithm for the NP-Complete problem of balancing job loads on machines. Does not guarantee an optimal solution, but instead, a solution is within a factor of 1.5 of the optimal solution","archived":false,"fork":false,"pushed_at":"2017-06-22T21:26:02.000Z","size":397,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-06T08:11:16.406Z","etag":null,"topics":["algorithm-design","algorithms","approximation","approximation-algorithms","balance","cpu","jobs","load","load-balancing","load-balancing-problem","machine","makespan","noah","noah-patullo","pattullo","pattulo","patullo","patulo","priority-queue","processing"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SleekPanther.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-06-11T19:29:35.000Z","updated_at":"2024-03-09T08:06:44.000Z","dependencies_parsed_at":null,"dependency_job_id":"2377d060-31b2-4116-b304-8a53fec821f4","html_url":"https://github.com/SleekPanther/load-balancing-problem-approximation-algorithm","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/SleekPanther/load-balancing-problem-approximation-algorithm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SleekPanther%2Fload-balancing-problem-approximation-algorithm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SleekPanther%2Fload-balancing-problem-approximation-algorithm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SleekPanther%2Fload-balancing-problem-approximation-algorithm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SleekPanther%2Fload-balancing-problem-approximation-algorithm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SleekPanther","download_url":"https://codeload.github.com/SleekPanther/load-balancing-problem-approximation-algorithm/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SleekPanther%2Fload-balancing-problem-approximation-algorithm/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":276694516,"owners_count":25687765,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-24T02:00:09.776Z","response_time":97,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithm-design","algorithms","approximation","approximation-algorithms","balance","cpu","jobs","load","load-balancing","load-balancing-problem","machine","makespan","noah","noah-patullo","pattullo","pattulo","patullo","patulo","priority-queue","processing"],"created_at":"2024-11-15T05:42:59.728Z","updated_at":"2025-09-24T04:31:20.379Z","avatar_url":"https://github.com/SleekPanther.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Load Balancing Problem Approximation Algorithm\nApproximation Algorithm for the NP-Complete problem of 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.\n\n## Problem Statement\n- `M` identical machines\n- `N` jobs\n- Each jobs has processing time **T\u003csub\u003ej\u003c/sub\u003e**\n- `J(i)` is the subset of jobs assigned to machine `i`\n- The load of machine `i` is **L\u003csub\u003ei\u003c/sub\u003e** = sum of the processing times for the jobs on that machine\n\n**Makespan** = the maximum of the loads on the machines (the machine with the largest load)  \n**Goal: Minimize the Makespan**\n\n## Solution\nAssign each job to a machine to minimize makespan  \nThere are m\u003csup\u003en\u003c/sup\u003e different assignments of n jobs to m machines, which is **exponential**\n\n**The greedy solution runs in polynomial time and gives a solution no more than 1.5 times the optimal makespan**  \nProof involves complicated sigma notation and can be found in the references\n\n**Sort jobs by largest processing time 1st \u0026 keep assigning jobs to the machine with the smallest load**  \n![](images/pseudocode.png)\n\n## Runtime\n- O(n log n) for sorting jobs by processing time  \n- O(n log m) for Greedy Balance \u0026 assigning jobs to machines  \n- O(n log n) + O(n log m)  \n- **⇒ O(n log n)**\n\n## Input Jobs\n### Jobs1 Inputs\n\u003cimg src=\"images/jobs1.png\" \u003e\n\n### Jobs1 Machine Assignments\n\u003cimg src=\"images/jobs1-machine-assignments.png\" width=\"400\"\u003e\n\n\n\u003cbr\u003e\n\n### Jobs2 Inputs\n\u003cimg src=\"images/jobs2.png\" \u003e\n\n### Jobs2 Machine Assignments\n\u003cimg src=\"images/jobs2-machine-assignments.png\" \u003e\n\n\n\u003cbr\u003e\n\n### Jobs3 Inputs\n\u003cimg src=\"images/jobs3.png\" \u003e\n\n### Jobs3 Machine Assignments\n\u003cimg src=\"images/jobs3-machine-assignments.png\" width=\"450\"\u003e\n\n\n## Usage\n**Machine ID's are meaningless since machines are identical, they're created for readability.  \nBut the algorithm still creates the job assignments on the machines according to the greedy strategy**  \n- `int machineCount` parameter is how many machines there are\n- `int[][] jobs` is a 2D array containing the jobs\n  - `jobs[i]` is an array represents a job\n  - `jobs[i][0]` is the **Job Id or name**\n  - `jobs[i][1]` is the **Processing time**\n\n## Code Details\n- Unlike the pseudocode, the jobs assigned to a machine are inside the `Machine` object in the Priority Queue\n- 1st Creates `M` machines with unique Id's\n- Then loop over the jobs and assigns the job with the longest processing time to the machine with the smallest current load\n  - 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\n- `Machine` class represents a machine\n  - **Some Important Parts of a Machine**\n  - `id` is the **ID or name of the machine**\n  - `currentLoad` is the sum of the processing times of the jobs currently assigned to the machine\n  - `jobs` is a 2D ArrayList containing the jobs currently assigned to the machine\n  - `Machine` class **overrides** `compareTo()` from the `Comparable` interface so that the `PriotityQueue is always has the smallest load machine at the top\n\n## References\n- [Load Balancing - Approximation Algorithms - Kevin Wayne](http://www.serc.iisc.ernet.in/~simmhan/SE252-JAN2014/lectures/SE252.Jan2014.Lecture-17.pdf)\n- [Load Balancing - Arash Rafiey](https://www.sfu.ca/~arashr/lecture24.pdf)\n- [Load Balancing - Hantao Zhang](http://homepage.divms.uiowa.edu/~hzhang/c231/ch11.pdf)\n- [Load Balancing - Yogesh Simmhan](https://www.cs.princeton.edu/~wayne/kleinberg-tardos/pdf/11ApproximationAlgorithms.pdf)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsleekpanther%2Fload-balancing-problem-approximation-algorithm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsleekpanther%2Fload-balancing-problem-approximation-algorithm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsleekpanther%2Fload-balancing-problem-approximation-algorithm/lists"}