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