SAT_to_CLIQUE

# SAT_to_CLIQUE - Arup Guha Example for COT 4210 written in...

This preview shows pages 1–2. Sign up to view the full content.

// Arup Guha // 7/25/2011 // Example for COT 4210 written in class. / import java.io.*; import java.util.*; i // Stores an instance of 3-SAT class sat { c public int numClauses; public int numVariables; public int[][] clauses; p // Assumes fin is reading from a file that describes // a 3-sat instance. public sat(Scanner fin) { p // Read in the number of clauses and variables. numClauses = fin.nextInt(); numVariables = fin.nextInt(); n // Read through each variable in each clause. clauses = new int[numClauses][3]; for (int i=0; i<numClauses; i++) for (int j=0; j<3; j++) clauses[i][j] = fin.nextInt(); c } // Returns true iff x and y have equal magnitude and have // opposite signs. public static boolean oppose(int x, int y) { return x+y == 0; } public clique reduce() { p // Make the graph the correct size. boolean[][] graph = new boolean[3*numClauses][3*numClauses]; b for (int i=0; i<graph.length; i++) { for (int j=i+1; j<graph.length; j++) { f // These two variables are in the same clause. if (i/3 == j/3) continue; i // These two variables are direct opposites. if (oppose(clauses[i/3][i%3], clauses[j/3][j%3]))

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern