Graph “Vertex cover” brute algorithm

风流意气都作罢 提交于 2021-02-11 17:44:49

问题


Given an electrical network, which is a set of electric generators, between which wires are stretched. A wire has current if at least one generator is operating at one end of the wire. Find the set with minimum count of generators that need to be turned on to provide current to the entire network.

I found some extra information that can help. It is "Vertex cover problem".

Now we know that it hasn't special algorithm. Let's bruteforce?


回答1:


As you note in the question, this is an instance of the vertex cover problem. It is a classic NP-hard problem, meaning no known algorithm gives exact results while scaling efficiently to larger inputs. The associated decision problem, of testing whether a vertex cover with k or fewer vertices exists, is NP-complete.

So, if you need the true minimum number, then you are not going to be able to do much better than some kind of backtracking search. If that's what you mean by "brute force" then unfortunately you're out of luck. Otherwise, if an approximation within a factor of 2 is good enough (i.e. a vertex cover with at most twice as many vertices as the true minimum), then one simple heuristic is to find a maximal matching and then choose both vertices for each edge in the matching.



来源:https://stackoverflow.com/questions/59201501/graph-vertex-cover-brute-algorithm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!