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.pb;
31
32 import static org.junit.Assert.assertEquals;
33 import static org.junit.Assert.assertTrue;
34
35 import java.util.HashSet;
36 import java.util.Set;
37
38 import org.junit.Test;
39 import org.sat4j.pb.tools.DependencyHelper;
40 import org.sat4j.specs.ContradictionException;
41 import org.sat4j.specs.IVec;
42 import org.sat4j.specs.TimeoutException;
43
44 public class BugSAT22 {
45 @Test
46 public void testSimpleResolverUnitFirst() throws ContradictionException,
47 TimeoutException {
48 IPBSolver solver = SolverFactory.newEclipseP2();
49 DependencyHelper<Named, String> helper = new DependencyHelper<Named, String>(
50 solver, false);
51 Set<Named> slice = new HashSet<Named>();
52 Named A1 = new Named("A1");
53 slice.add(A1);
54 Named A2 = new Named("A2");
55 slice.add(A2);
56 Named B = new Named("B");
57 slice.add(B);
58 Named X = new Named("X");
59
60 helper.setTrue(X, "Build");
61
62 helper.addToObjectiveFunction(A2, 1);
63 helper.addToObjectiveFunction(A1, 2);
64 helper.addToObjectiveFunction(B, 1);
65
66 helper.or("a", X, new Named[] { A1, A2 });
67 helper.or("b", X, new Named[] { B });
68
69 assertTrue(helper.hasASolution());
70 IVec<Named> solution = helper.getSolution();
71 assertEquals(3, solution.size());
72 assertTrue(solution.contains(B));
73 assertTrue(solution.contains(X));
74 assertTrue(solution.contains(A2));
75 }
76
77 @Test
78 public void testSimpleResolverUnitLast() throws ContradictionException,
79 TimeoutException {
80 IPBSolver solver = SolverFactory.newEclipseP2();
81 DependencyHelper<Named, String> helper = new DependencyHelper<Named, String>(
82 solver, false);
83 Set<Named> slice = new HashSet<Named>();
84 Named A1 = new Named("A1");
85 slice.add(A1);
86 Named A2 = new Named("A2");
87 slice.add(A2);
88 Named B = new Named("B");
89 slice.add(B);
90 Named X = new Named("X");
91
92 helper.addToObjectiveFunction(A2, 1);
93 helper.addToObjectiveFunction(A1, 2);
94 helper.addToObjectiveFunction(B, 1);
95
96 helper.or("a", X, new Named[] { A1, A2 });
97 helper.or("b", X, new Named[] { B });
98
99 helper.setTrue(X, "Build");
100
101 assertTrue(helper.hasASolution());
102 IVec<Named> solution = helper.getSolution();
103 assertEquals(3, solution.size());
104 assertTrue(solution.contains(B));
105 assertTrue(solution.contains(X));
106 assertTrue(solution.contains(A2));
107 }
108
109 public class Named {
110 public String name;
111
112 public Named(String name) {
113 this.name = name;
114 }
115 }
116 }