一个算法来找到最小尺寸设定盖为集覆盖问题算法、最小、尺寸、问题

2023-09-11 00:14:42 作者:待我称帝便封你为后i

在集合覆盖问题,我们都给予了宇宙U,使得| U | U. A的= N,并设置S1,......,SK的子集设置盖一些成套从集合ç S1,......,SK的结合是整个宇宙U.

In the Set Covering problem, we are given a universe U, such that |U|=n, and sets S1,……,Sk are subsets of U. A set cover is a collection C of some of the sets from S1,……,Sk whose union is the entire universe U.

我试图想出一种算法,会发现集合覆盖的最小数,这样我可以表明,贪心算法集合覆盖有时会发现多台套。

I'm trying to come up with an algorithm that will find the minimum number of set cover so that I can show that the greedy algorithm for set covering sometimes finds more sets.

下面是我想出了:

重复每个组。 1.封面< -Seti(I = 1 ,,, N) 2.如果一套不属于任何其他集的子集,然后采取采取集中成盖。

repeat for each set. 1. Cover<-Seti (i=1,,,n) 2. if a set is not a subset of any other sets, then take take that set into cover.

但它不工作的一些情况。 请帮我找出一个算法来找到最小集合覆盖。

but it's not working for some instances. Please help me figure out an algorithm to find the minimum set cover.

我仍然有问题,找到该算法在网上。任何人有什么建议?

I'm still having problem find this algorithm online. Anyone has any suggestion?

推荐答案

设置封面是NP难,因此它不太可能就会有一个算法远远超过看着都套可能的组合有效的,如果每个检查组合是一个盖。

Set cover is NP-hard, so it's unlikely that there'll be an algorithm much more efficient than looking at all possible combinations of sets, and checking if each combination is a cover.

基本上看1集,然后2套等所有组合,直到它们形成一个盖子。

Basically, look at all combinations of 1 set, then 2 sets, etc. until they form a cover.

修改

这是一个例子伪code。请注意,我并​​不认为这是有效的。我只是声称,有没有一个更有效的算法(算法会比多项式时间内,除非一些非常酷的发现更糟)

This is an example pseudocode. Note that I do not claim that this is efficient. I simply claim that there isn't a much more efficient algorithm (algorithms will be worse than polynomial time unless something really cool is discovered)

for size in 1..|S|:
    for C in combination(S, size):
          if (union(C) == U) return C

其中,组合(K,N)返回尺寸的所有可能的集 N 的元素来自 K

where combination(K, n) returns all possible sets of size n whose elements come from K.

修改

不过,我也不太清楚为什么你需要一个算法来找到最小。在这个问题你的状态,你想证明贪婪算法集合覆盖有时会发现多台套。但是,这是很容易通过反例来实现(和一个反例示为集合覆盖的维基百科条目)。所以,我很疑惑。

However, I'm not too sure why you need an algorithm to find the minimum. In the question you state that you want to show that the greedy algorithm for set covering sometimes finds more sets. But this is easily achieved via a counterexample (and a counterexample is shown in the wikipedia entry for set cover). So I am quite puzzled.

修改

一个可能的实施组合(K,N)是:

if n == 0: return [{}] //a list containing an empty set
r = []
for k in K:
    K = K \ {k} // remove k from K.
    for s in combination(K, n-1):
        r.append(union({k}, s))
return r

不过,与覆盖问题相结合,人们可能希望从基本情况ñ== 0 ,而不是执行的覆盖测试。好了。

But in combination with the cover problem, one probably wants to perform the test of coverage from the base case n == 0 instead. Well.

 
精彩推荐