import java.io.*; import java.util.*; import PED_NumberIO; //****************************************************** // CNF_Formula class used in SAT_TPI Game Implementation //**************************************************** // Paul E. Dunne // Dept. of Computer Science // Univ. of Liverpool //**************************************************** // Version 1: 22/05/2002 // Version 2: 27/05/2002 Additional Constructors for random data // generation; // Version 3: 29/05/2002 Random sequences implemented via // java.util.Random class. //**************************************************** // CNF Formula specified in the form // // n +ve integer giving number of variables // m +ve integer giving number of clauses; // m lines of form // C-len y_1 y_2 ... y_clen // C_len +ve integer <= n // y_i integers indicating literal in clause // (+/- according to whether related variable is // positive or negated). //****************************************************** class CNF_Formula { //********************************************************************** private int n; // Number of variables in this instance. private int m; // Number of clauses in this instance. private int[][] PHI; // The CNF formula m clauses of (at most) n literals // PHI[k][] the k'th clause PHI[k][0] // always give clause length //********************************************************************** // Constructor which Reads CNF defined in form // above from input file or Standard input. //********************************************************************** public CNF_Formula(BufferedReader istream) throws IOException { n = PED_NumberIO.get_int(istream); // Variables m = PED_NumberIO.get_int(istream); // Clauses PHI = new int[m+1][n+1]; // So that can index from 1..m,1..n for (int i=1; i0.5) { PHI[i][ct] = j; } else { PHI[i][ct] = -j; }; }; }; PHI[i][0]=ct; }; }; //********************************************************************** // Constructor to generate v variable 3-CNF: // Each of the possible 8(v choose 3) clauses is included u.a.r. // with probability p. Thus expected number of clauses is ~ 8pv^3 //********************************************************************** public CNF_Formula(int v, double p, long sv) { Random seq; int ctr=0; int[][] temp = new int[1+(4*v*(v-1)*(v-2))/3][4]; if (sv==0) seq=new Random(); else seq = new Random(sv); n=v; for (int pol=0; pol<8; pol++) { for (int i=1; i<=n-2; i++) { for (int j=i+1; j<=n-1; j++) { for (int k=j+1; k<=n; k++) { if (seq.nextDouble()