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 package org.sat4j.minisat.learning;
27
28 import org.sat4j.minisat.core.Constr;
29 import org.sat4j.minisat.core.ILits;
30 import org.sat4j.minisat.core.LearningStrategy;
31 import org.sat4j.minisat.core.Solver;
32 import org.sat4j.minisat.core.VarActivityListener;
33
34
35
36
37
38
39
40 public abstract class LimitedLearning<L extends ILits> implements LearningStrategy<L> {
41
42 private static final long serialVersionUID = 1L;
43
44 private final NoLearningButHeuristics<L> none;
45
46 private final MiniSATLearning<L> all;
47
48 protected L lits;
49
50 public LimitedLearning() {
51 none = new NoLearningButHeuristics<L>();
52 all = new MiniSATLearning<L>();
53 }
54
55 public void setSolver(Solver<L> s) {
56 this.lits = s.getVocabulary();
57 setVarActivityListener(s);
58 all.setDataStructureFactory(s.getDSFactory());
59 }
60
61 public void learns(Constr constr) {
62 if (learningCondition(constr)) {
63 all.learns(constr);
64 } else {
65 none.learns(constr);
66 }
67 }
68
69 abstract protected boolean learningCondition(Constr constr);
70
71 public void init() {
72 all.init();
73 none.init();
74 }
75
76 public void setVarActivityListener(VarActivityListener s) {
77 none.setVarActivityListener(s);
78 all.setVarActivityListener(s);
79 }
80 }