//Implementation of the rules to build level-(k+1) generators from level-k generators //Based on the code by Steven Kelk http://homepages.cwi.nl/~kelk/lev3gen/ //Philippe Gambette - http://www.lirmm.fr/~gambette/ProgramGenerators import java.io.*; import java.util.*; import java.lang.*; import java.math.BigInteger; public class Generators { public static final boolean DEBUG = false; public static Vector currentLevel; public static Vector previousLevel; public static int perm[][][]; public static int mycount; public static int countTested; public static int countPrev; public static int l; public static FileWriter output; public static int myfac(int f) { if( f <= 2 ) return f; else return f * myfac(f-1); } public static void makePerms() { int top = 8; perm = new int [top+1][][]; for( int x=1; x<=top; x++ ){ PermutationGenerator pg = new PermutationGenerator(x); int t = myfac(x); perm[x] = new int[t][x]; int at = 0; while( pg.hasMore() ){ int v[] = pg.getNext(); for( int l=0; l < x; l++ ) perm[x][at][l] = v[l]; at++; } } /* for(int s=1; s<=top; s++ ){ System.out.println("Permutations on "+s+" elements:"); int todo = perm[s].length; for( int k=0; k < todo; k++ ){ for( int t=0; t0) { for(int e2i=0;e2i0)) { if ((e2i==e1i) && (e2j==e1j) && (prevGraph.adj[e1i][e1j]==2)){ //Create a copy of prevGraph with three more nodes Graph newGraph=prevGraph.augment(3); newGraph.v20=prevGraph.v20+1; String theName="R1m(G_"+(countPrev+nbPreviousLevel)+",("+e1i+","+e1j+"),("+e2i+","+e2j+"))"; if (DEBUG) System.out.println(mycount+"/"+countTested+":"+theName); newGraph.ruleR1multi(e1i,e1j,e2i,e2j); countTested++; if( !newGraph.containedIn(currentLevel) ){ currentLevel.addElement(newGraph); newGraph.dumpGraph(mycount++,theName); } //Create a copy of prevGraph with two more nodes newGraph=prevGraph.augment(2); newGraph.v21=prevGraph.v21+1; theName="R2m(G_"+(countPrev+nbPreviousLevel)+",("+e1i+","+e1j+"),("+e2i+","+e2j+"))"; if (DEBUG) System.out.println(mycount+"/"+countTested+":"+theName); newGraph.ruleR2multi(e1i,e1j,e2i,e2j); countTested++; if( !newGraph.containedIn(currentLevel) ){ currentLevel.addElement(newGraph); newGraph.dumpGraph(mycount++,theName); } } if ((e2i*prevGraph.v+e2j)<=(e1i*prevGraph.v+e1j)) { etape++; //Create a copy of prevGraph with three more nodes Graph newGraph=prevGraph.augment(3); newGraph.v20=prevGraph.v20+1; String theName="R1(G_"+(countPrev+nbPreviousLevel)+",("+e1i+","+e1j+"),("+e2i+","+e2j+"))"; if (DEBUG) System.out.println(mycount+"/"+countTested+":"+theName); newGraph.ruleR1(e1i,e1j,e2i,e2j); countTested++; if( !newGraph.containedIn(currentLevel) ) { currentLevel.addElement(newGraph); newGraph.dumpGraph(mycount++,theName); } } //Apply R2 if you can if (!prevGraph.directedPath(e2j,e1i)){ //Create a copy of prevGraph with one more node Graph newGraph=prevGraph.augment(2); newGraph.v21=prevGraph.v21+1; String theName="R2(G_"+(countPrev+nbPreviousLevel)+",("+e1i+","+e1j+"),("+e2i+","+e2j+"))"; if (DEBUG) System.out.println(mycount+"/"+countTested+":"+theName); newGraph.ruleR2(e1i,e1j,e2i,e2j); countTested++; if( !newGraph.containedIn(currentLevel)){ currentLevel.addElement(newGraph); newGraph.dumpGraph(mycount++,theName); } } } } } } } } //For any couple (hybrid node,arc) apply R1 & R2: for(int i=0;i1) && (prevGraph.getOutDegree(i)==0)){ for(int e1i=0;e1i0) { //Create a copy of prevGraph with two more nodes Graph newGraph=prevGraph.augment(2); newGraph.v21=prevGraph.v21+1; String theName="R1(G_"+(countPrev+nbPreviousLevel)+","+i+",("+e1i+","+e1j+"))"; if (DEBUG) System.out.println(mycount+"/"+countTested+":"+theName); newGraph.ruleR1(i,e1i,e1j); countTested++; if( !newGraph.containedIn(currentLevel) ){ currentLevel.addElement(newGraph); newGraph.dumpGraph(mycount++,theName); } //Apply R2 if you can if (!prevGraph.directedPath(e1j,i)){ //Create a copy of prevGraph with one more node newGraph=prevGraph.augment(1); newGraph.v20=prevGraph.v20-1; newGraph.v21=prevGraph.v21+2; theName="R2(G_"+(countPrev+nbPreviousLevel)+","+i+",("+e1i+","+e1j+"))"; if (DEBUG) System.out.println(mycount+"/"+countTested+":"+theName); newGraph.ruleR2(i,e1i,e1j); countTested++; if( !newGraph.containedIn(currentLevel) ){ currentLevel.addElement(newGraph); newGraph.dumpGraph(mycount++,theName); } } } } } } } //For any couple (hybrid node,hybrid node) apply R1: for(int i=0;i1) && (prevGraph.getOutDegree(i)==0)){ for(int j=i+1;j1) && (prevGraph.getOutDegree(j)==0)){ //Create a copy of prevGraph with one more node Graph newGraph=prevGraph.augment(1); newGraph.v20=prevGraph.v20-1; newGraph.v21=prevGraph.v21+2; String theName="R1(G_"+(countPrev+nbPreviousLevel)+","+i+","+j+")"; if (DEBUG) System.out.println(mycount+"/"+countTested+":"+theName); newGraph.ruleR1(i,j); countTested++; if( !newGraph.containedIn(currentLevel) ){ currentLevel.addElement(newGraph); newGraph.dumpGraph(mycount++,theName); } } } } } } nbPreviousLevel++; } countPrev+=nbPreviousLevel; System.out.println("Nb:"+countTested); return currentLevel; } } }