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.SearchParams; |
20 |
| import org.sat4j.minisat.core.Solver; |
21 |
| import org.sat4j.specs.IVec; |
22 |
| import org.sat4j.specs.IVecInt; |
23 |
| |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| public class PBSolver extends Solver { |
29 |
| |
30 |
| private static final long serialVersionUID = 1L; |
31 |
| |
32 |
| |
33 |
| |
34 |
| |
35 |
| |
36 |
| |
37 |
696
| public PBSolver(AssertingClauseGenerator acg, LearningStrategy learner,
|
38 |
| DataStructureFactory dsf, IOrder order) { |
39 |
696
| super(acg, learner, dsf, new SearchParams(10000.0, 100), order);
|
40 |
| } |
41 |
| |
42 |
519135
| @Override
|
43 |
| public int analyze(Constr myconfl, Handle<Constr> outLearntRef) { |
44 |
| |
45 |
| |
46 |
519135
| IConflict confl = chooseConflict(myconfl);
|
47 |
519135
| BigInteger resDegree = confl.getDegree();
|
48 |
| |
49 |
| |
50 |
| |
51 |
| |
52 |
| |
53 |
519135
| int litImplied = trail.last();
|
54 |
519135
| int currentLevel = voc.getLevel(litImplied);
|
55 |
| assert confl.slackConflict().signum() < 0; |
56 |
| |
57 |
519135
| while (!confl.isAssertive(currentLevel)) {
|
58 |
| |
59 |
| |
60 |
| |
61 |
| |
62 |
10293008
| PBConstr constraint = (PBConstr) voc.getReason(litImplied);
|
63 |
10293008
| if (constraint != null) {
|
64 |
| |
65 |
| |
66 |
| |
67 |
| |
68 |
| |
69 |
10170753
| resDegree = confl.resolve(constraint, litImplied);
|
70 |
| assert confl.slackConflict().signum() <= 0; |
71 |
| |
72 |
| |
73 |
| |
74 |
| } |
75 |
| |
76 |
10293008
| if (trail.size() == 1)
|
77 |
126
| break;
|
78 |
10292882
| undoOne();
|
79 |
10292882
| if (decisionLevel() > 0) {
|
80 |
10292882
| litImplied = trail.last();
|
81 |
10292882
| if (voc.getLevel(litImplied) != currentLevel)
|
82 |
122129
| trailLim.pop();
|
83 |
10292882
| currentLevel = voc.getLevel(litImplied);
|
84 |
| } else |
85 |
0
| break;
|
86 |
| assert currentLevel == decisionLevel(); |
87 |
| assert litImplied > 1; |
88 |
| } |
89 |
| |
90 |
| assert currentLevel == decisionLevel(); |
91 |
519135
| if (decisionLevel() == 0) {
|
92 |
0
| outLearntRef.obj = null;
|
93 |
0
| return -1;
|
94 |
| } |
95 |
| |
96 |
519135
| undoOne();
|
97 |
| |
98 |
| |
99 |
| |
100 |
| |
101 |
519135
| IVecInt resLits = new VecInt();
|
102 |
519135
| IVec<BigInteger> resCoefs = new Vec<BigInteger>();
|
103 |
519135
| confl.buildConstraintFromConflict(resLits, resCoefs);
|
104 |
| |
105 |
| assert resLits.size() == resCoefs.size(); |
106 |
| |
107 |
519135
| if (resLits.size() == 0) {
|
108 |
126
| outLearntRef.obj = null;
|
109 |
126
| return -1;
|
110 |
| } |
111 |
| |
112 |
| |
113 |
519009
| PBConstr resConstr = (PBConstr) dsfactory
|
114 |
| .createUnregisteredPseudoBooleanConstraint(resLits, resCoefs, |
115 |
| resDegree); |
116 |
| |
117 |
519009
| outLearntRef.obj = resConstr;
|
118 |
| |
119 |
| |
120 |
| assert confl.isAssertive(currentLevel); |
121 |
519009
| return confl.getBacktrackLevel(currentLevel);
|
122 |
| } |
123 |
| |
124 |
464657
| IConflict chooseConflict(Constr myconfl) {
|
125 |
464657
| return ConflictArray.createConflict((PBConstr) myconfl);
|
126 |
| } |
127 |
| |
128 |
0
| @Override
|
129 |
| public String toString(String prefix) { |
130 |
0
| return prefix+"Cutting planes based inference\n"+super.toString(prefix);
|
131 |
| } |
132 |
| |
133 |
| |
134 |
| } |