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