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 package org.sat4j.minisat.core;
31
32 import static org.junit.Assert.assertEquals;
33 import static org.junit.Assert.assertTrue;
34
35 import org.junit.Before;
36 import org.junit.Test;
37 import org.sat4j.core.VecInt;
38 import org.sat4j.minisat.SolverFactory;
39 import org.sat4j.minisat.orders.PositiveLiteralSelectionStrategy;
40 import org.sat4j.specs.ContradictionException;
41 import org.sat4j.specs.IVecInt;
42 import org.sat4j.specs.TimeoutException;
43
44 public class TestPrimeComputation {
45
46 private Solver<DataStructureFactory> solver;
47
48 @Before
49 public void setUp() {
50 this.solver = SolverFactory.newBestWL();
51 this.solver.getOrder().setPhaseSelectionStrategy(
52 new PositiveLiteralSelectionStrategy());
53 }
54
55 @Test
56 public void testBasicImplicant() throws ContradictionException,
57 TimeoutException {
58 IVecInt clause = new VecInt();
59 clause.push(1).push(-2).push(3);
60 this.solver.addClause(clause);
61 clause.clear();
62 clause.push(-1).push(2).push(3);
63 this.solver.addClause(clause);
64 clause.clear();
65 clause.push(1).push(2).push(-3);
66 this.solver.addClause(clause);
67 clause.clear();
68 assertTrue(this.solver.isSatisfiable());
69 int[] model = this.solver.model();
70 assertEquals(3, model.length);
71 int[] implicant = this.solver.primeImplicant();
72 assertEquals(2, implicant.length);
73 }
74
75 @Test
76 public void testImplicantPascal() throws ContradictionException,
77 TimeoutException {
78 IVecInt clause = new VecInt();
79 clause.push(1).push(-2).push(3).push(-4);
80 this.solver.addClause(clause);
81 assertTrue(this.solver.isSatisfiable());
82 int[] model = this.solver.model();
83 assertEquals(4, model.length);
84 int[] implicant = this.solver.primeImplicant();
85 assertEquals(1, implicant.length);
86 }
87
88 @Test
89 public void testOtherImplicant() throws ContradictionException,
90 TimeoutException {
91 IVecInt clause = new VecInt();
92 clause.push(1).push(-2).push(3);
93 this.solver.addClause(clause);
94 clause.clear();
95 clause.push(1).push(2).push(3);
96 this.solver.addClause(clause);
97 clause.clear();
98 clause.push(1).push(2).push(-3);
99 this.solver.addClause(clause);
100 clause.clear();
101 assertTrue(this.solver.isSatisfiable());
102 int[] model = this.solver.model();
103 assertEquals(3, model.length);
104 int[] implicant = this.solver.primeImplicant();
105 assertEquals(2, implicant.length);
106 clause.push(1).push(-2).push(-3);
107 this.solver.addBlockingClause(clause);
108 assertTrue(this.solver.isSatisfiable());
109 clause.clear();
110 model = this.solver.model();
111 assertEquals(3, model.length);
112 implicant = this.solver.primeImplicant();
113 assertEquals(1, implicant.length);
114 }
115
116 @Test
117 public void testFolletExample() throws ContradictionException,
118 TimeoutException {
119 IVecInt clause = new VecInt();
120 clause.push(1);
121 this.solver.addClause(clause);
122 clause.clear();
123 clause.push(2).push(3);
124 this.solver.addClause(clause);
125 clause.clear();
126 clause.push(3);
127 this.solver.addClause(clause);
128 clause.clear();
129 assertTrue(this.solver.isSatisfiable());
130 int[] model = this.solver.model();
131 assertEquals(3, model.length);
132 int[] implicant = this.solver.primeImplicant();
133 assertEquals(2, implicant.length);
134 }
135 }