简体   繁体   中英

How to find weighted minimum vertex cover of graph

So, I have a graph of vertices which have certain weights and edges. I'm trying to find the minimum weighted vertex cover. For example if I have a vertex cover of size 10 but each node has a weight of 10, then the weight of the total cover is 100. But if I have a vertex cover of size 99 with each node of weight 1, then I would pick this cover over the previous one.

This is NP-Complete I believe, so there's no efficient algorithm, but I think even an exhaustive search would work for me because the number of nodes will be relatively small. The only way I can think to do this then would be to generate the power set of the set [1 ... n] (where each integer corresponds to a node on the graph), then test every individual set to see if it is 1) a valid vertex cover, and 2) keep track of the vertex cover of lowest weight.

But this seems horribly inefficient. Is this the best way to go about it?

Minimum weight vertex cover is NP-Complete so you couldn't expect better than exhaustive search in general, but you could use backtracking to find a minimum weight vertex cover, something like this :

MinCover(Graph G, List<Vertex> selectedVertices, int min)
{
   var coveredAll = covered(G,selectedVertices);
   if ( coveredAll && weight(selectedVertices) < min)
   {
       cover = selectedVertices.ToList();
       min = weight(cover);
   }
   else if (!coveredAll && weight(selectedVertices) < min)
   {
      select another unvisited vertex and add it to selectedVertices
      call MinCover
      remove the previously selected vertex from the list
   }

   return;

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM