1
2
3
4
5
6
7 package org.sat4j.minisat.learning;
8
9 import org.sat4j.minisat.core.Constr;
10 import org.sat4j.minisat.core.ILits;
11
12 public class PercentLengthLearning<L extends ILits> extends LimitedLearning<L>{
13
14
15
16
17 private static final long serialVersionUID = 1L;
18 private int maxpercent;
19 private int bound;
20
21 public PercentLengthLearning() {
22 this(10);
23 }
24
25 public PercentLengthLearning(int percent) {
26 maxpercent = percent;
27 }
28
29 public void setLimit(int percent) {
30 maxpercent = percent;
31 }
32
33 public int getLimit() {
34 return maxpercent;
35 }
36
37 @Override
38 public void init() {
39 super.init();
40 setBound(lits.realnVars() * maxpercent / 100);
41 }
42
43 @Override
44 public String toString() {
45 return "Limit learning to clauses of size smaller or equal to "
46 + maxpercent + "% of the number of variables";
47 }
48
49 protected void setBound(int newbound) {
50 bound = newbound;
51 }
52
53 @Override
54 protected boolean learningCondition(Constr constr) {
55 return constr.size() <= bound;
56 }
57
58 }