|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| package org.sat4j.tools; |
|
8 |
| |
|
9 |
| import java.io.Serializable; |
|
10 |
| |
|
11 |
| import org.sat4j.core.VecInt; |
|
12 |
| import org.sat4j.specs.ContradictionException; |
|
13 |
| import org.sat4j.specs.ISolver; |
|
14 |
| import org.sat4j.specs.IVecInt; |
|
15 |
| import org.sat4j.specs.TimeoutException; |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| public class Minimal4InclusionModel extends SolverDecorator implements |
|
32 |
| Serializable { |
|
33 |
| |
|
34 |
| private static final long serialVersionUID = 1L; |
|
35 |
| |
|
36 |
| |
|
37 |
| |
|
38 |
| |
|
39 |
1
| public Minimal4InclusionModel(ISolver solver) {
|
|
40 |
1
| super(solver);
|
|
41 |
| } |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
10
| @Override
|
|
49 |
| public int[] model() { |
|
50 |
10
| int[] prevmodel = null;
|
|
51 |
10
| IVecInt vec = new VecInt();
|
|
52 |
10
| IVecInt cube = new VecInt();
|
|
53 |
| |
|
54 |
10
| try {
|
|
55 |
10
| do {
|
|
56 |
15
| prevmodel = super.model();
|
|
57 |
15
| vec.clear();
|
|
58 |
15
| cube.clear();
|
|
59 |
15
| for (int i = 0; i < prevmodel.length; i++) {
|
|
60 |
45
| if (prevmodel[i] < 0) {
|
|
61 |
9
| vec.push(-prevmodel[i]);
|
|
62 |
| } else { |
|
63 |
36
| cube.push(prevmodel[i]);
|
|
64 |
| } |
|
65 |
| } |
|
66 |
| |
|
67 |
15
| addClause(vec);
|
|
68 |
5
| } while (isSatisfiable(cube));
|
|
69 |
| } catch (TimeoutException e) { |
|
70 |
| |
|
71 |
| } catch (ContradictionException e) { |
|
72 |
| |
|
73 |
| } |
|
74 |
| |
|
75 |
10
| int[] newmodel = new int[vec.size()];
|
|
76 |
10
| for (int i = 0, j = 0; i < prevmodel.length; i++) {
|
|
77 |
30
| if (prevmodel[i] < 0) {
|
|
78 |
0
| newmodel[j++] = prevmodel[i];
|
|
79 |
| } |
|
80 |
| } |
|
81 |
| |
|
82 |
10
| return newmodel;
|
|
83 |
| } |
|
84 |
| } |