import java.io.IOException; import java.util.TreeSet; import java.util.ArrayList; public class WPtrRefClique { // // Produce the ith combination of superset, of a given size. // public static TreeSet choose(TreeSet superset, int size, int index) { if (size==0) return new TreeSet(); TreeSet superb = new TreeSet(superset); int chosen = superb.pollFirst(), target = nCr(superb.size(), size-1), lastTarget = 0; while (index >= target) { chosen = superb.pollFirst(); lastTarget = target; target += nCr(superb.size(), size-1); } TreeSet out = new TreeSet(); out.add(chosen); out.addAll(choose(superb, size-1, index-lastTarget)); return out; } public static int nCr (int n, int r) { if (n==0 || r==0 || r==n) return 1; return nCr(n-1, r) + nCr(n-1, r-1); } public static void main(String[] args) { if (args.length < 1) { System.out.println("PARAMS: ref-file"); return; } try { Instance inst = Instance.fromDir(args[0]); int num_authors = inst.getNumAuthors(); //System.out.println("c max-clique formulation of "+args[0]); System.out.println("p edge " + (15*num_authors) + " 0"); ArrayList>> combinations = new ArrayList<>(num_authors); // Calculate all combinations size 4 from each person's allowed papers. // Every time we calculate a set, compare it against all existing sets from previous authors. // This is probably very memory heavy -- I don't much feel like optimisation today. for (int i=0; i allowedPapers = inst.getAuthorPapers(i); ArrayList> allCombos = new ArrayList<>(15); combinations.add(allCombos); for (int j=0; j<15; j++) { TreeSet subset = choose(allowedPapers, 4, j); allCombos.add(subset); // Now compare against vertices for past authors. int myNum = 15*i + j + 1; int score = 0; for (Integer p : subset){ score += inst.getScore(p); } System.out.println("n " + myNum + " " + score); for (int x=0; x isect = new TreeSet(subset); isect.retainAll(combinations.get(x).get(y)); if (isect.size()==0) System.out.println("e "+theirNum+" "+myNum); } } } } } catch (IOException e) { System.err.println("Bad file!"); System.err.println(e); } } }