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 package org.sat4j;
26
27 import java.io.FileNotFoundException;
28 import java.io.IOException;
29 import java.io.PrintWriter;
30
31 import org.sat4j.minisat.SolverFactory;
32 import org.sat4j.reader.InstanceReader;
33 import org.sat4j.reader.ParseFormatException;
34 import org.sat4j.reader.Reader;
35 import org.sat4j.specs.ContradictionException;
36 import org.sat4j.specs.IProblem;
37 import org.sat4j.specs.ISolver;
38 import org.sat4j.specs.IVecInt;
39 import org.sat4j.specs.TimeoutException;
40 import org.sat4j.tools.RemiUtils;
41 import org.sat4j.tools.SolutionCounter;
42
43
44
45
46
47
48
49
50
51 public class MoreThanSAT {
52
53
54
55
56
57
58 private MoreThanSAT() {
59
60 }
61
62 public static void main(final String[] args) {
63 final ISolver solver = SolverFactory.newMiniLearning();
64 final SolutionCounter sc = new SolutionCounter(solver);
65 solver.setTimeout(3600);
66 Reader reader = new InstanceReader(solver);
67
68
69 try {
70 final IProblem problem = reader.parseInstance(args[0]);
71 if (problem.isSatisfiable()) {
72 System.out.println(Messages.getString("MoreThanSAT.0"));
73 reader.decode(problem.model(), new PrintWriter(System.out));
74 IVecInt backbone = RemiUtils.backbone(solver);
75 System.out
76 .println(Messages.getString("MoreThanSAT.1") + backbone);
77 System.out.println(Messages.getString("MoreThanSAT.2"));
78 System.out.println(Messages.getString("MoreThanSAT.3")
79 + sc.countSolutions());
80 } else {
81 System.out.println(Messages.getString("MoreThanSAT.4"));
82 }
83 } catch (FileNotFoundException e) {
84 e.printStackTrace();
85 } catch (ParseFormatException e) {
86 e.printStackTrace();
87 } catch (IOException e) {
88 e.printStackTrace();
89 } catch (ContradictionException e) {
90 System.out.println(Messages.getString("MoreThanSAT.5"));
91 } catch (TimeoutException e) {
92 System.out.println(Messages.getString("MoreThanSAT.6"));
93 }
94 }
95 }