{"id":20409659,"url":"https://github.com/sleekpanther/minimum-weighted-vertex-cover-approximation-algorithm","last_synced_at":"2025-07-27T19:41:10.338Z","repository":{"id":115108621,"uuid":"94906879","full_name":"SleekPanther/minimum-weighted-vertex-cover-approximation-algorithm","owner":"SleekPanther","description":"Approximation Algorithm for the NP-Complete problem of finding a vertex cover of minimum weight in a graph with weighted vertices. Guarantees an answers at most 2 times the optimal minimum weighted vertex cover","archived":false,"fork":false,"pushed_at":"2019-01-12T21:08:26.000Z","size":896,"stargazers_count":8,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-26T10:21:20.498Z","etag":null,"topics":["algorithm","algorithm-design","approximation","approximation-algorithms","edge-cost","graph","minimum-weighted-vertex-cover","noah","noah-patullo","noahpatullo","np-complete","pattullo","pattulo","patullo","patulo","pricing-method","vertex","vertex-cover","vertices","weighted-vertex-cover"],"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}},"created_at":"2017-06-20T15:30:25.000Z","updated_at":"2023-11-28T22:00:47.000Z","dependencies_parsed_at":null,"dependency_job_id":"c8dbe13c-a907-4ce8-a51d-006ffc293a75","html_url":"https://github.com/SleekPanther/minimum-weighted-vertex-cover-approximation-algorithm","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SleekPanther%2Fminimum-weighted-vertex-cover-approximation-algorithm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SleekPanther%2Fminimum-weighted-vertex-cover-approximation-algorithm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SleekPanther%2Fminimum-weighted-vertex-cover-approximation-algorithm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SleekPanther%2Fminimum-weighted-vertex-cover-approximation-algorithm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SleekPanther","download_url":"https://codeload.github.com/SleekPanther/minimum-weighted-vertex-cover-approximation-algorithm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248592018,"owners_count":21130163,"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","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","algorithm-design","approximation","approximation-algorithms","edge-cost","graph","minimum-weighted-vertex-cover","noah","noah-patullo","noahpatullo","np-complete","pattullo","pattulo","patullo","patulo","pricing-method","vertex","vertex-cover","vertices","weighted-vertex-cover"],"created_at":"2024-11-15T05:42:51.809Z","updated_at":"2025-04-12T15:52:07.846Z","avatar_url":"https://github.com/SleekPanther.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Minimum Weighted Vertex Cover - Pricing Method (Approximation Algorithm)\nApproximation Algorithm for the NP-Complete problem of finding a **vertex cover of minimum weight** in a graph with weighted vertices. Guarantees an answers at most **2 times** the optimal minimum weighted vertex cover (2-approximation algorithm, [see references for the proof](#references)).\n\n## Problem Statement\n- Given an **undirected graph** with each vertex weighted \u003e 0\n- Find a vertex cover **S ⊆ V** (where each edge has at least 1 edge in **S**)\n- And the vertex cover has the **minimum total weight** (when adding weights of the selected vertices)\n#### Graph1\n\u003cimg src=\"images/graph1.png\" width=\"400\"\u003e\n\n#### Graph 1 Optimal Minimum Weighted Vertex Cover\n\u003cimg src=\"images/graph1-optimal-vertex-cover.png\" width=\"400\"\u003e\n\n\u003ch4\u003eVertex Cover = a, c \u003cbr\u003e\nTotal Weight = 4+5 = 9\n\u003c/h4\u003e\n\n#### Graph 1 Algorithm's Weighted Vertex Cover (sub-optimal)\n\u003cimg src=\"images/graph1-algorithm-vertex-cover.png\" width=\"400\"\u003e\n\n\u003ch4\u003eVertex Cover = a, b, d \u003cbr\u003e\nTotal Weight = 3+4+3 = 10\n\u003c/h4\u003e\n\nThe algorithm **does not find the optimal solution**, but the answer given is **10**, which is less than **twice the optimal value** which would be **2 * 9 = 18**  \n\n\n## Algorithm Solution\nThe problem is **NP-Complete** but this algorithm is a polynomial-time 2-approximation algorithm.  \nThe answer found is at most **2 times** the weight of the **Optimal** Minimum Weighted Vertex Cover.\n\n### Pricing Strategy (Fairness)\n- Each edge ***e=(i, j)*** must pay a price P\u003csub\u003ee\u003c/sub\u003e \u003e 0 to the vertices **i** and **j**\n- **Fairness:** an edge cannot pay more than the remaining weight of either vertex\n- **Tight:** a vertex is tight when it has no remaining weight  \n![](images/pseudocode.png)  \n\n## Input Graphs\n#### Graph 2\n\u003cimg src=\"images/graph2.png\" width=\"230\"\u003e\n\n#### Graph2 Algorithm's Weighted Vertex Cover (optimal)\n\u003cimg src=\"images/graph2-algorithm-vertex-cover.png\" width=\"230\"\u003e\n\n\u003ch4\u003eVertex Cover = a, d, b \u003cbr\u003e\nTotal Weight = 2+2+4 = 8\n\u003c/h4\u003e\n\n\n#### Graph 3\n\u003cimg src=\"images/graph3.png\" width=\"530\"\u003e\n\n#### Graph 3 Optimal Minimum Weighted Vertex Cover\n\u003cimg src=\"images/graph3-optimal-vertex-cover.png\" width=\"530\"\u003e\n\n\u003ch4\u003eVertex Cover = a, c, f \u003cbr\u003e\nTotal Weight = 2+4+9 = 15\n\u003c/h4\u003e\n\n#### Graph 3 Algorithm's Weighted Vertex Cover (sub-optimal)\n\u003cimg src=\"images/graph3-algorithm-vertex-cover.png\" width=\"530\"\u003e\n\n\u003ch4\u003eVertex Cover = a, b, c, e \u003cbr\u003e\nTotal Weight = 2+3+4+7 = 16\n\u003c/h4\u003e\n\n#### Graph 4\n\u003cimg src=\"images/graph4.png\" width=\"230\"\u003e\n\n#### Graph 4 Algorithm's Weighted Vertex Cover (optimal)\n\u003cimg src=\"images/graph4-algorithm-vertex-cover.png\" width=\"230\"\u003e\n\n\u003ch4\u003eVertex Cover = d, c, b \u003cbr\u003e\nTotal Weight = 1+1+1 = 3\n\u003c/h4\u003e\n\n## Usage\n- Create a `int[] weights` array  \n`weights[0]` is the weight of **vertex `0`**, `weights[1]` is the weight of **vertex `1`**, etc.\n- *(Optional)* Create `String` array for vertex names (0=a, 1=b, 2=c etc. in the example but this is arbitrary \u0026 it works as long as the underlyng graph created with integers is valid)\n- Create the graph by adding undirected edges (**only add each edge once**)  \n*e.g.*  \n`graph1.add(new Edge(0,1, vertexNames1));;`  \n`graph1.add(new Edge(0,3, vertexNames1));`  \n*etc.*\n- Vertex names can be left out (A names array is created automatically if none is provided using the String representation of the integer). There's an example for `graph4` which doesn't pass a names array\n- **The order of edges added and the names of the vertices can result in a different vertex cover**\n- Call `MinimumWeightedVertexCover.findMinimumWeightedVertexCoverApprox(graph1, weights1, vertexNames1);`\n\n## References\n- [Approximation Algorithms - Kevin Wayne](https://www.cs.princeton.edu/~wayne/kleinberg-tardos/pdf/11ApproximationAlgorithms.pdf#page=25)\n- BAD [Vertex Cover Problem - GeeksForGeeks](http://www.geeksforgeeks.org/vertex-cover-problem-set-1-introduction-approximate-algorithm-2/)  \n**This was a terrible mistake! This algorithm is very different from the approximation algorithm and had me confused on my initial attempt**\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsleekpanther%2Fminimum-weighted-vertex-cover-approximation-algorithm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsleekpanther%2Fminimum-weighted-vertex-cover-approximation-algorithm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsleekpanther%2Fminimum-weighted-vertex-cover-approximation-algorithm/lists"}