|
1 |
| package org.sat4j.tools; |
|
2 |
| |
|
3 |
| import org.sat4j.core.VecInt; |
|
4 |
| import org.sat4j.specs.ContradictionException; |
|
5 |
| import org.sat4j.specs.ISolver; |
|
6 |
| import org.sat4j.specs.IVecInt; |
|
7 |
| import org.sat4j.specs.TimeoutException; |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| public class SolutionCounter extends SolverDecorator { |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| private static final long serialVersionUID = 1L; |
|
23 |
| |
|
24 |
0
| public SolutionCounter(ISolver solver) {
|
|
25 |
0
| super(solver);
|
|
26 |
| } |
|
27 |
| |
|
28 |
0
| public long countSolutions() throws TimeoutException {
|
|
29 |
0
| long nbsols = 0;
|
|
30 |
0
| boolean trivialfalsity = false;
|
|
31 |
| |
|
32 |
0
| while (!trivialfalsity && isSatisfiable()) {
|
|
33 |
0
| nbsols++;
|
|
34 |
0
| int[] last = model();
|
|
35 |
0
| IVecInt clause = new VecInt(last.length);
|
|
36 |
0
| for (int i = 0; i < last.length; i++) {
|
|
37 |
0
| clause.push(-last[i]);
|
|
38 |
| } |
|
39 |
0
| try {
|
|
40 |
| |
|
41 |
0
| addClause(clause);
|
|
42 |
| } catch (ContradictionException e) { |
|
43 |
0
| trivialfalsity = true;
|
|
44 |
| } |
|
45 |
| } |
|
46 |
0
| return nbsols;
|
|
47 |
| } |
|
48 |
| } |