-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolve3CNF.java
More file actions
35 lines (31 loc) · 1016 Bytes
/
solve3CNF.java
File metadata and controls
35 lines (31 loc) · 1016 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package npc;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
public class solve3CNF {
public static void main (String[] args) {
String filename = args[0];
List<CNF> cnfs = CNF.makeAllCNFsFromFile(filename);
System.out.println("* Solve 3CNF in "+filename+": (reduced to K-Clique) *");
int num = 0;
for (CNF cnf: cnfs) {
//CNF cnf = cnfs.get(12);
long start = System.currentTimeMillis();
boolean[] assignments = cnf.getSolution();
System.out.print("3CNF No."+(++num)+"[n="+cnf.getN()+" k="+cnf.getK()+"] ");
if(assignments != null){
StringBuilder sb = new StringBuilder();
sb.append("[ ");
for(int i =0;i<assignments.length;i++){
sb.append("A"+(i+1)+"="+(assignments[i]?"T":"F")+" ");
}
sb.append("]");
System.out.print(sb.toString());
}
else
System.out.print("No "+cnf.getK()+"-clique; no solution ");
System.out.println("("+(System.currentTimeMillis() - start) + " ms)");
}
System.out.println("***");
}
}