import java.util.*; import java.io.*; public class Tomita22Stats extends TomitaBitSet { static BitSet D; // used at will private int[] cliqueSizeCount; // the number of cliques of a given size Tomita22Stats (String fname) throws IOException {super(fname);} void search(){ D = new BitSet(n); BitSet C = new BitSet(n); BitSet P = new BitSet(n); BitSet X = new BitSet(n); cliqueSizeCount = new int[n+1]; C.set(0,n,false); P.set(0,n,true); X.set(0,n,false); searchTime = System.currentTimeMillis(); try{expand(C,P,X);} catch (TimeOutException e){cliques = -cliques;} searchTime = System.currentTimeMillis() - searchTime; for (int i=0;i<=n;i++) if (cliqueSizeCount[i] > 0) System.out.print("("+ cliqueSizeCount[i] +","+ i +") "); System.out.println(); } void expand(BitSet C,BitSet P,BitSet X){ if (timeLimit > 0 && System.currentTimeMillis() - cpuTime >= timeLimit) throw new TimeOutException(); nodes++; if (P.isEmpty() && X.isEmpty()){cliques++; cliqueSizeCount[C.cardinality()]++; return;} if (P.isEmpty()) return; int u = selectMax(P,X); BitSet newP = new BitSet(n); BitSet newX = new BitSet(n); for (int v=P.nextSetBit(0);v>=0;v=P.nextSetBit(v+1)){ if (!N[u].get(v)){ // not adjacent copy(newP,P); copy(newX,X); newP.and(N[v]); newX.and(N[v]); C.set(v,true); expand(C,newP,newX); C.set(v,false); P.set(v,false); X.set(v,true); } } } void copy(BitSet A,BitSet B){A.clear();A.or(B);} // // A := B // int getDegree(int v,BitSet V){copy(D,V);D.and(N[v]);return D.cardinality();} int selectMax(BitSet P,BitSet X){ int maxDegree = -1, maxVertex = -1, degree = -1; for (int u=P.nextSetBit(0);u>=0;u=P.nextSetBit(u+1)){ degree = getDegree(u,P); if (degree > maxDegree || degree == maxDegree && u > maxVertex){maxDegree = degree; maxVertex = u;} } for (int u=X.nextSetBit(0);u>=0;u=X.nextSetBit(u+1)){ degree = getDegree(u,P); if (degree > maxDegree || degree == maxDegree && u > maxVertex){maxDegree = degree; maxVertex = u;} } return maxVertex; } }