GithubHelp home page GithubHelp logo

sleekpanther / minimum-weighted-vertex-cover-approximation-algorithm Goto Github PK

View Code? Open in Web Editor NEW
8.0 3.0 2.0 896 KB

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

Java 100.00%
noah patullo noah-patullo noahpatullo patulo pattullo pattulo vertex-cover vertex graph

minimum-weighted-vertex-cover-approximation-algorithm's Introduction

Minimum Weighted Vertex Cover - Pricing Method (Approximation Algorithm)

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 (2-approximation algorithm, see references for the proof).

Problem Statement

  • Given an undirected graph with each vertex weighted > 0
  • Find a vertex cover S βŠ† V (where each edge has at least 1 edge in S)
  • And the vertex cover has the minimum total weight (when adding weights of the selected vertices)

Graph1

Graph 1 Optimal Minimum Weighted Vertex Cover

Vertex Cover = a, c
Total Weight = 4+5 = 9

Graph 1 Algorithm's Weighted Vertex Cover (sub-optimal)

Vertex Cover = a, b, d
Total Weight = 3+4+3 = 10

The 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

Algorithm Solution

The problem is NP-Complete but this algorithm is a polynomial-time 2-approximation algorithm.
The answer found is at most 2 times the weight of the Optimal Minimum Weighted Vertex Cover.

Pricing Strategy (Fairness)

  • Each edge e=(i, j) must pay a price Pe > 0 to the vertices i and j
  • Fairness: an edge cannot pay more than the remaining weight of either vertex
  • Tight: a vertex is tight when it has no remaining weight

Input Graphs

Graph 2

Graph2 Algorithm's Weighted Vertex Cover (optimal)

Vertex Cover = a, d, b
Total Weight = 2+2+4 = 8

Graph 3

Graph 3 Optimal Minimum Weighted Vertex Cover

Vertex Cover = a, c, f
Total Weight = 2+4+9 = 15

Graph 3 Algorithm's Weighted Vertex Cover (sub-optimal)

Vertex Cover = a, b, c, e
Total Weight = 2+3+4+7 = 16

Graph 4

Graph 4 Algorithm's Weighted Vertex Cover (optimal)

Vertex Cover = d, c, b
Total Weight = 1+1+1 = 3

Usage

  • Create a int[] weights array
    weights[0] is the weight of vertex 0, weights[1] is the weight of vertex 1, etc.
  • (Optional) Create String array for vertex names (0=a, 1=b, 2=c etc. in the example but this is arbitrary & it works as long as the underlyng graph created with integers is valid)
  • Create the graph by adding undirected edges (only add each edge once)
    e.g.
    graph1.add(new Edge(0,1, vertexNames1));;
    graph1.add(new Edge(0,3, vertexNames1));
    etc.
  • 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
  • The order of edges added and the names of the vertices can result in a different vertex cover
  • Call MinimumWeightedVertexCover.findMinimumWeightedVertexCoverApprox(graph1, weights1, vertexNames1);

References

minimum-weighted-vertex-cover-approximation-algorithm's People

Contributors

sleekpanther avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

yohy nickskyyy

minimum-weighted-vertex-cover-approximation-algorithm's Issues

Try this :)

int vertexCount = 4;
graph1.addEdge(0,1);
graph1.addEdge(0,2);
graph1.addEdge(0,3);
int[] weights = {100, 1, 1, 1};

Common interest

Hi,
I came across your GitHub and it's quite impressive the amount of work you've put in it. I'm too am interested in Algorithms among other things like Programming Languages, Functional Programming, and Reactive Programming.
It’ll be a pleasure to connect with you on LinkedIn, but why stop there? From time to time, I'd love to compare notes and/or discuss about programming. I recently completed two algorithms courses offered by Stanford, mostly for fun, but also to jog my memory for programming interviews; what are you up to?

If you're interested, I'll be happy to talk more. I've a Gitter room https://gitter.im/sia/Lobby

https://www.linkedin.com/in/abhijit-sarkar-53161330/
https://github.com/asarkar
https://blog.asarkar.org/ (infrequent)

Regards,
Abhijit

P.S.: I assume the reason that you made these solutions public is for others to benefit from your work, but having a dozen or so repos, one for each problem, requires a lot of jumping around even for problems that are related (like approximation algorithms for NP-Complete problems). You may want to consider consolidating the various solutions into one repo for easier reference.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.