1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.sat4j.minisat;
20
21 import org.sat4j.core.ASolverFactory;
22 import org.sat4j.minisat.constraints.ClausalDataStructureCBWL;
23 import org.sat4j.minisat.constraints.MixedDataStructureDanielHT;
24 import org.sat4j.minisat.constraints.MixedDataStructureDanielWL;
25 import org.sat4j.minisat.core.DataStructureFactory;
26 import org.sat4j.minisat.core.IOrder;
27 import org.sat4j.minisat.core.SearchParams;
28 import org.sat4j.minisat.core.Solver;
29 import org.sat4j.minisat.learning.LimitedLearning;
30 import org.sat4j.minisat.learning.MiniSATLearning;
31 import org.sat4j.minisat.learning.NoLearningButHeuristics;
32 import org.sat4j.minisat.learning.PercentLengthLearning;
33 import org.sat4j.minisat.orders.PhaseCachingAutoEraseStrategy;
34 import org.sat4j.minisat.orders.PureOrder;
35 import org.sat4j.minisat.orders.RSATPhaseSelectionStrategy;
36 import org.sat4j.minisat.orders.RandomWalkDecorator;
37 import org.sat4j.minisat.orders.VarOrderHeap;
38 import org.sat4j.minisat.restarts.ArminRestarts;
39 import org.sat4j.minisat.restarts.LubyRestarts;
40 import org.sat4j.minisat.restarts.MiniSATRestarts;
41 import org.sat4j.minisat.restarts.NoRestarts;
42 import org.sat4j.minisat.uip.DecisionUIP;
43 import org.sat4j.minisat.uip.FirstUIP;
44 import org.sat4j.opt.MinOneDecorator;
45 import org.sat4j.specs.ISolver;
46 import org.sat4j.tools.DimacsOutputSolver;
47 import org.sat4j.tools.OptToSatAdapter;
48
49
50
51
52
53
54 public final class SolverFactory extends ASolverFactory<ISolver> {
55
56
57
58
59 private static final long serialVersionUID = 1L;
60
61
62 private static SolverFactory instance;
63
64
65
66
67
68
69 private SolverFactory() {
70 super();
71 }
72
73 private static synchronized void createInstance() {
74 if (instance == null) {
75 instance = new SolverFactory();
76 }
77 }
78
79
80
81
82
83
84 public static SolverFactory instance() {
85 if (instance == null) {
86 createInstance();
87 }
88 return instance;
89 }
90
91
92
93
94
95
96 public static Solver<DataStructureFactory> newMiniLearningHeap() {
97 return newMiniLearningHeap(new MixedDataStructureDanielWL());
98 }
99
100 public static Solver<DataStructureFactory> newMiniLearningHeapEZSimp() {
101 Solver<DataStructureFactory> solver = newMiniLearningHeap();
102 solver.setSimplifier(solver.SIMPLE_SIMPLIFICATION);
103 return solver;
104 }
105
106 public static Solver<DataStructureFactory> newMiniLearningHeapExpSimp() {
107 Solver<DataStructureFactory> solver = newMiniLearningHeap();
108 solver.setSimplifier(solver.EXPENSIVE_SIMPLIFICATION);
109 return solver;
110 }
111
112 public static Solver<DataStructureFactory> newMiniLearningHeapRsatExpSimp() {
113 Solver<DataStructureFactory> solver = newMiniLearningHeapExpSimp();
114 solver.setOrder(new VarOrderHeap(new RSATPhaseSelectionStrategy()));
115 return solver;
116 }
117
118 public static Solver<DataStructureFactory> newMiniLearningHeapRsatExpSimpBiere() {
119 Solver<DataStructureFactory> solver = newMiniLearningHeapRsatExpSimp();
120 solver.setRestartStrategy(new ArminRestarts());
121 solver.setSearchParams(new SearchParams(1.1, 100));
122 return solver;
123 }
124
125 public static Solver<DataStructureFactory> newMiniLearningHeapRsatExpSimpLuby() {
126 Solver<DataStructureFactory> solver = newMiniLearningHeapRsatExpSimp();
127 solver.setRestartStrategy(new LubyRestarts());
128 return solver;
129 }
130
131 private static Solver<DataStructureFactory> newBestCurrentSolverConfiguration(
132 DataStructureFactory dsf) {
133 MiniSATLearning<DataStructureFactory> learning = new MiniSATLearning<DataStructureFactory>();
134 Solver<DataStructureFactory> solver = new Solver<DataStructureFactory>(
135 new FirstUIP(), learning, dsf, new VarOrderHeap(
136 new RSATPhaseSelectionStrategy()), new ArminRestarts());
137 solver.setSearchParams(new SearchParams(1.1, 100));
138 learning.setSolver(solver);
139 solver.setSimplifier(solver.EXPENSIVE_SIMPLIFICATION);
140 return solver;
141 }
142
143
144
145
146
147 public static Solver<DataStructureFactory> newGreedySolver() {
148 MiniSATLearning<DataStructureFactory> learning = new MiniSATLearning<DataStructureFactory>();
149 Solver<DataStructureFactory> solver = new Solver<DataStructureFactory>(
150 new FirstUIP(), learning, new MixedDataStructureDanielWL(),
151 new RandomWalkDecorator(new VarOrderHeap(
152 new RSATPhaseSelectionStrategy())), new NoRestarts());
153
154 learning.setSolver(solver);
155 solver.setSimplifier(solver.EXPENSIVE_SIMPLIFICATION);
156 return solver;
157 }
158
159
160
161
162 public static Solver<DataStructureFactory> newDefaultAutoErasePhaseSaving() {
163 Solver<DataStructureFactory> solver = newBestWL();
164 solver.setOrder(new VarOrderHeap(new PhaseCachingAutoEraseStrategy()));
165 return solver;
166 }
167
168
169
170
171 public static Solver<DataStructureFactory> newBestWL() {
172 return newBestCurrentSolverConfiguration(new MixedDataStructureDanielWL());
173 }
174
175
176
177
178
179 public static Solver<DataStructureFactory> newBestHT() {
180 return newBestCurrentSolverConfiguration(new MixedDataStructureDanielHT());
181 }
182
183
184
185
186 public static Solver<DataStructureFactory> newGlucose() {
187 Solver<DataStructureFactory> solver = newBestWL();
188 solver.setLearnedConstraintsDeletionStrategy(solver.glucose);
189 solver.setRestartStrategy(new LubyRestarts(512));
190 return solver;
191 }
192
193
194
195
196
197
198
199
200 public static Solver<DataStructureFactory> newMiniLearningHeap(
201 DataStructureFactory dsf) {
202 return newMiniLearning(dsf, new VarOrderHeap());
203 }
204
205
206
207
208
209
210
211
212 public static Solver<DataStructureFactory> newMiniLearningPure() {
213 return newMiniLearning(new MixedDataStructureDanielWL(),
214 new PureOrder());
215 }
216
217
218
219
220
221 public static Solver<DataStructureFactory> newMiniLearningCBWLPure() {
222 return newMiniLearning(new ClausalDataStructureCBWL(), new PureOrder());
223 }
224
225
226
227
228
229
230
231
232
233
234
235
236 public static Solver<DataStructureFactory> newMiniLearning(
237 DataStructureFactory dsf, IOrder order) {
238
239
240 MiniSATLearning<DataStructureFactory> learning = new MiniSATLearning<DataStructureFactory>();
241 Solver<DataStructureFactory> solver = new Solver<DataStructureFactory>(
242 new FirstUIP(), learning, dsf, order, new MiniSATRestarts());
243 learning.setSolver(solver);
244 return solver;
245 }
246
247
248
249
250 public static Solver<DataStructureFactory> newMiniLearningHeapEZSimpNoRestarts() {
251 LimitedLearning<DataStructureFactory> learning = new PercentLengthLearning<DataStructureFactory>(
252 10);
253 Solver<DataStructureFactory> solver = new Solver<DataStructureFactory>(
254 new FirstUIP(), learning, new MixedDataStructureDanielWL(),
255 new SearchParams(Integer.MAX_VALUE), new VarOrderHeap(),
256 new MiniSATRestarts());
257 learning.setSolver(solver);
258 solver.setSimplifier(solver.SIMPLE_SIMPLIFICATION);
259 return solver;
260 }
261
262
263
264
265 public static Solver<DataStructureFactory> newMiniLearningHeapEZSimpLongRestarts() {
266 LimitedLearning<DataStructureFactory> learning = new PercentLengthLearning<DataStructureFactory>(
267 10);
268 Solver<DataStructureFactory> solver = new Solver<DataStructureFactory>(
269 new FirstUIP(), learning, new MixedDataStructureDanielWL(),
270 new SearchParams(1000), new VarOrderHeap(),
271 new MiniSATRestarts());
272 learning.setSolver(solver);
273 solver.setSimplifier(solver.SIMPLE_SIMPLIFICATION);
274 return solver;
275 }
276
277
278
279
280 public static Solver<DataStructureFactory> newMiniSATHeap() {
281 return newMiniSATHeap(new MixedDataStructureDanielWL());
282 }
283
284
285
286
287
288 public static Solver<DataStructureFactory> newMiniSATHeapEZSimp() {
289 Solver<DataStructureFactory> solver = newMiniSATHeap();
290 solver.setSimplifier(solver.SIMPLE_SIMPLIFICATION);
291 return solver;
292 }
293
294 public static Solver<DataStructureFactory> newMiniSATHeapExpSimp() {
295 Solver<DataStructureFactory> solver = newMiniSATHeap();
296 solver.setSimplifier(solver.EXPENSIVE_SIMPLIFICATION);
297 return solver;
298 }
299
300 public static Solver<DataStructureFactory> newMiniSATHeap(
301 DataStructureFactory dsf) {
302 MiniSATLearning<DataStructureFactory> learning = new MiniSATLearning<DataStructureFactory>();
303 Solver<DataStructureFactory> solver = new Solver<DataStructureFactory>(
304 new FirstUIP(), learning, dsf, new VarOrderHeap(),
305 new MiniSATRestarts());
306 learning.setDataStructureFactory(solver.getDSFactory());
307 learning.setVarActivityListener(solver);
308 return solver;
309 }
310
311
312
313
314 public static Solver<MixedDataStructureDanielWL> newRelsat() {
315 MiniSATLearning<MixedDataStructureDanielWL> learning = new MiniSATLearning<MixedDataStructureDanielWL>();
316 Solver<MixedDataStructureDanielWL> solver = new Solver<MixedDataStructureDanielWL>(
317 new DecisionUIP(), learning, new MixedDataStructureDanielWL(),
318 new VarOrderHeap(), new MiniSATRestarts());
319 learning.setDataStructureFactory(solver.getDSFactory());
320 learning.setVarActivityListener(solver);
321 return solver;
322 }
323
324
325
326
327
328 public static Solver<MixedDataStructureDanielWL> newBackjumping() {
329 NoLearningButHeuristics<MixedDataStructureDanielWL> learning = new NoLearningButHeuristics<MixedDataStructureDanielWL>();
330 Solver<MixedDataStructureDanielWL> solver = new Solver<MixedDataStructureDanielWL>(
331 new FirstUIP(), learning, new MixedDataStructureDanielWL(),
332 new VarOrderHeap(), new MiniSATRestarts());
333 learning.setVarActivityListener(solver);
334 return solver;
335 }
336
337
338
339
340
341 public static ISolver newMinOneSolver() {
342 return new OptToSatAdapter(new MinOneDecorator(newDefault()));
343 }
344
345
346
347
348
349
350
351
352
353 public static ISolver newDefault() {
354 return newMiniLearningHeapRsatExpSimpBiere();
355 }
356
357 @Override
358 public ISolver defaultSolver() {
359 return newDefault();
360 }
361
362
363
364
365
366
367
368
369 public static ISolver newLight() {
370 return newMiniLearningHeap();
371 }
372
373 @Override
374 public ISolver lightSolver() {
375 return newLight();
376 }
377
378 public static ISolver newDimacsOutput() {
379 return new DimacsOutputSolver();
380 }
381
382 }