Set cover algorithms tend to provide just one solution for finding a minimum number of sets to cover. How to go about finding all such solutions?
Asked
Active
Viewed 420 times
0
-
http://cs.stackexchange.com/questions/35475/how-to-enumerate-minimal-covers-of-a-set – v78 Oct 06 '16 at 05:11
-
Thanks, though it just converts into another problem and I am not familiar with that. – Harold Oct 06 '16 at 07:30
1 Answers
0
It depends on what you mean by "minimal" as this will vary the number of set covers you get. For example if you had the target set of ABC
and the sets AB
,AC
,C
to choose from you could cover with either (AB
,C
) or (AB
,AC
) or all 3 (AB
,AC
,C
) and if you're defining "minimal" as for example the 2 lowest choices i.e. with the fewest overlaps or fewest repeated elements then you would choose the 1st 2 ((AB
,C
) and (AB
,AC
)). "Minimal" could also be defined in terms number of sets chosen so for the above example the lowest number would be 2 and either (AB
,C
) or (AB
,AC
) would work. But if you wanted all possible set covers you could start with just brute force going through each combo so
import java.util.*;
public class f {
// abcd
static int target = 0b1111;
// ab,ac,acd,cd
static int[] groups = {0b1100,0b1010,0b1011,0b0011};
// check if sets cover target
// for example 1100 and 0011 would cover 1111
static boolean covers(boolean[] A){
int or = 0;
for(int i=0;i<A.length;i++){
if(A[i]) or = or | groups[i];
}
int t = target;
while (t>0){
if(t%2!=1 || or%2!=1)
return false;
t = t>>1;
or = or>>1;
}
return true;
}
// go through all choices
static void combos(boolean A[],int i,int j){
if(i>j){
if(covers(A)) System.out.println(Arrays.toString(A));
return;
}
combos(A,i+1,j);
A[i]=!A[i];
combos(A,i+1,j);
}
public static void main(String args[]){
boolean[] A = new boolean[groups.length];
combos(A,0,groups.length-1);
}
}

Bobas_Pett
- 591
- 5
- 10