1 package org.sat4j.minisat.restarts;
2
3 import org.sat4j.minisat.core.RestartStrategy;
4 import org.sat4j.minisat.core.SearchParams;
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 public class LubyRestarts implements RestartStrategy {
34
35
36
37
38 private static final long serialVersionUID = 1L;
39
40 static final long luby_super(long i) {
41 long power;
42 long k;
43
44 assert i > 0;
45
46 k = 1;
47 power = 2;
48 while (power < (i + 1)) {
49 k += 1;
50 power *= 2;
51 }
52 if (power == (i + 1))
53 return (power / 2);
54 return (luby_super(i - (power / 2) + 1));
55 }
56
57 private int factor;
58 private int count;
59
60 public LubyRestarts() {
61 setFactor(32);
62 }
63
64 public void setFactor(int factor) {
65 this.factor = factor;
66 }
67
68 public int getFactor() {
69 return factor;
70 }
71
72 public void init(SearchParams params) {
73 count = 1;
74 }
75
76 public long nextRestartNumberOfConflict() {
77 return luby_super(count)*factor;
78 }
79
80 public void onRestart() {
81 count++;
82 }
83
84 @Override
85 public String toString() {
86 return "luby style (SATZ_rand, TiniSAT) restarts strategy with factor "+factor;
87 }
88
89 }