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 |
| package org.sat4j.minisat.learning; |
29 |
| |
30 |
| import org.sat4j.minisat.core.Constr; |
31 |
| import org.sat4j.minisat.core.ILits; |
32 |
| import org.sat4j.minisat.core.LearningStrategy; |
33 |
| import org.sat4j.minisat.core.Solver; |
34 |
| import org.sat4j.minisat.core.VarActivityListener; |
35 |
| |
36 |
| |
37 |
| |
38 |
| |
39 |
| |
40 |
| |
41 |
| |
42 |
| public class LimitedLearning implements LearningStrategy { |
43 |
| |
44 |
| private static final long serialVersionUID = 1L; |
45 |
| |
46 |
| private final NoLearningButHeuristics none; |
47 |
| |
48 |
| private final MiniSATLearning all; |
49 |
| |
50 |
| private final int maxpercent; |
51 |
| |
52 |
| private ILits lits; |
53 |
| |
54 |
| private int bound; |
55 |
| |
56 |
205
| public LimitedLearning() {
|
57 |
205
| this(10);
|
58 |
| } |
59 |
| |
60 |
1125
| public LimitedLearning(int percent) {
|
61 |
1125
| maxpercent = percent;
|
62 |
1125
| none = new NoLearningButHeuristics();
|
63 |
1125
| all = new MiniSATLearning();
|
64 |
| } |
65 |
| |
66 |
1125
| public void setSolver(Solver s) {
|
67 |
1125
| this.lits = s.getVocabulary();
|
68 |
1125
| setVarActivityListener(s);
|
69 |
1125
| all.setDataStructureFactory(s.getDSFactory());
|
70 |
| } |
71 |
| |
72 |
125758595
| public void learns(Constr constr) {
|
73 |
125758595
| if (learningCondition(constr)) {
|
74 |
104248
| all.learns(constr);
|
75 |
| } else { |
76 |
125654347
| none.learns(constr);
|
77 |
| } |
78 |
| } |
79 |
| |
80 |
125672486
| protected boolean learningCondition(Constr constr) {
|
81 |
125672486
| return constr.size() <= bound;
|
82 |
| } |
83 |
| |
84 |
969
| public void init() {
|
85 |
969
| setBound(lits.realnVars() * maxpercent / 100);
|
86 |
969
| all.init();
|
87 |
969
| none.init();
|
88 |
| } |
89 |
| |
90 |
1072
| protected void setBound(int newbound) {
|
91 |
1072
| bound = newbound;
|
92 |
| } |
93 |
| |
94 |
0
| @Override
|
95 |
| public String toString() { |
96 |
0
| return "Limit learning to clauses of size smaller or equal to "
|
97 |
| + maxpercent + "% of the number of variables"; |
98 |
| } |
99 |
| |
100 |
1125
| public void setVarActivityListener(VarActivityListener s) {
|
101 |
1125
| none.setVarActivityListener(s);
|
102 |
1125
| all.setVarActivityListener(s);
|
103 |
| } |
104 |
| } |