1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| package org.sat4j.minisat.constraints.pb; |
8 |
| |
9 |
| import java.math.BigInteger; |
10 |
| |
11 |
| import org.sat4j.core.Vec; |
12 |
| import org.sat4j.core.VecInt; |
13 |
| import org.sat4j.minisat.core.AssertingClauseGenerator; |
14 |
| import org.sat4j.minisat.core.Constr; |
15 |
| import org.sat4j.minisat.core.DataStructureFactory; |
16 |
| import org.sat4j.minisat.core.Handle; |
17 |
| import org.sat4j.minisat.core.IOrder; |
18 |
| import org.sat4j.minisat.core.LearningStrategy; |
19 |
| import org.sat4j.minisat.core.Solver; |
20 |
| import org.sat4j.specs.IVec; |
21 |
| import org.sat4j.specs.IVecInt; |
22 |
| |
23 |
| |
24 |
| |
25 |
| |
26 |
| |
27 |
| public class PBSolver extends Solver { |
28 |
| |
29 |
| private static final long serialVersionUID = 1L; |
30 |
| |
31 |
| |
32 |
| |
33 |
| |
34 |
| |
35 |
| |
36 |
314
| public PBSolver(AssertingClauseGenerator acg, LearningStrategy learner,
|
37 |
| DataStructureFactory dsf,IOrder order) { |
38 |
314
| super(acg, learner, dsf,order);
|
39 |
| } |
40 |
| |
41 |
62490
| @Override
|
42 |
| public int analyze(Constr myconfl, Handle<Constr> outLearntRef) { |
43 |
| |
44 |
| |
45 |
62490
| Conflict confl = ((WatchPb) myconfl).createConflict();
|
46 |
62490
| BigInteger resDegree = confl.getDegree();
|
47 |
| |
48 |
| |
49 |
| |
50 |
| |
51 |
| |
52 |
62490
| int litImplied = trail.last();
|
53 |
62490
| int currentLevel = voc.getLevel(litImplied);
|
54 |
62490
| int originalLevel = currentLevel;
|
55 |
| assert confl.slackConflict().signum() < 0; |
56 |
| |
57 |
62490
| while (!confl.isAssertive(currentLevel)) {
|
58 |
| |
59 |
| |
60 |
| |
61 |
| |
62 |
2611561
| WatchPb constraint = (WatchPb) voc.getReason(litImplied);
|
63 |
2611561
| if (constraint != null) {
|
64 |
| |
65 |
| |
66 |
| |
67 |
| |
68 |
| |
69 |
2584713
| resDegree = confl.resolve(constraint, litImplied);
|
70 |
| assert confl.slackConflict().signum() <= 0; |
71 |
| |
72 |
| |
73 |
| |
74 |
| } |
75 |
| |
76 |
2611561
| if (trail.size() == 1)
|
77 |
28
| break;
|
78 |
2611533
| undoOne();
|
79 |
2611533
| if (decisionLevel() > 0) {
|
80 |
2611533
| litImplied = trail.last();
|
81 |
2611533
| if (voc.getLevel(litImplied) != currentLevel)
|
82 |
26820
| trailLim.pop();
|
83 |
2611533
| currentLevel = voc.getLevel(litImplied);
|
84 |
| } else |
85 |
0
| break;
|
86 |
| assert currentLevel == decisionLevel(); |
87 |
| assert litImplied > 1; |
88 |
| } |
89 |
| assert currentLevel == decisionLevel(); |
90 |
62490
| if (decisionLevel() == 0) {
|
91 |
0
| outLearntRef.obj = null;
|
92 |
0
| return -1;
|
93 |
| } |
94 |
| |
95 |
62490
| undoOne();
|
96 |
| |
97 |
| |
98 |
| |
99 |
| |
100 |
62490
| IVecInt resLits = new VecInt();
|
101 |
62490
| IVec<BigInteger> resCoefs = new Vec<BigInteger>();
|
102 |
62490
| confl.buildConstraintFromConflict(resLits, resCoefs);
|
103 |
| |
104 |
| assert resLits.size() == resCoefs.size(); |
105 |
| |
106 |
62490
| if (resLits.size() == 0) {
|
107 |
28
| outLearntRef.obj = null;
|
108 |
28
| return -1;
|
109 |
| } |
110 |
| |
111 |
| |
112 |
62462
| WatchPb resConstr = (WatchPb) dsfactory
|
113 |
| .createUnregisteredPseudoBooleanConstraint(resLits, resCoefs, |
114 |
| resDegree); |
115 |
| |
116 |
62462
| outLearntRef.obj = resConstr;
|
117 |
| |
118 |
| |
119 |
| |
120 |
| assert confl.isAssertive(currentLevel); |
121 |
62462
| int bl = resConstr.getBacktrackLevel(currentLevel);
|
122 |
| |
123 |
62462
| return bl;
|
124 |
| } |
125 |
| |
126 |
| } |