问题
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