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.CardinalityDataStructure;
23 import org.sat4j.minisat.constraints.ClausalDataStructureCB;
24 import org.sat4j.minisat.constraints.ClausalDataStructureCBHT;
25 import org.sat4j.minisat.constraints.MixedDataStructureDaniel;
26 import org.sat4j.minisat.constraints.MixedDataStructureWithBinary;
27 import org.sat4j.minisat.constraints.MixedDataStructureWithBinaryAndTernary;
28 import org.sat4j.minisat.core.DataStructureFactory;
29 import org.sat4j.minisat.core.ILits;
30 import org.sat4j.minisat.core.ILits2;
31 import org.sat4j.minisat.core.ILits23;
32 import org.sat4j.minisat.core.IOrder;
33 import org.sat4j.minisat.core.SearchParams;
34 import org.sat4j.minisat.core.Solver;
35 import org.sat4j.minisat.learning.ActiveLearning;
36 import org.sat4j.minisat.learning.FixedLengthLearning;
37 import org.sat4j.minisat.learning.LimitedLearning;
38 import org.sat4j.minisat.learning.MiniSATLearning;
39 import org.sat4j.minisat.learning.NoLearningButHeuristics;
40 import org.sat4j.minisat.learning.PercentLengthLearning;
41 import org.sat4j.minisat.orders.JWOrder;
42 import org.sat4j.minisat.orders.MyOrder;
43 import org.sat4j.minisat.orders.PureOrder;
44 import org.sat4j.minisat.orders.RSATPhaseSelectionStrategy;
45 import org.sat4j.minisat.orders.VarOrder;
46 import org.sat4j.minisat.orders.VarOrderHeap;
47 import org.sat4j.minisat.restarts.ArminRestarts;
48 import org.sat4j.minisat.restarts.LubyRestarts;
49 import org.sat4j.minisat.restarts.MiniSATRestarts;
50 import org.sat4j.minisat.uip.DecisionUIP;
51 import org.sat4j.minisat.uip.FirstUIP;
52 import org.sat4j.opt.MinOneDecorator;
53 import org.sat4j.specs.ISolver;
54 import org.sat4j.tools.DimacsOutputSolver;
55 import org.sat4j.tools.OptToSatAdapter;
56
57
58
59
60
61
62 public class SolverFactory extends ASolverFactory<ISolver> {
63
64
65
66
67 private static final long serialVersionUID = 1L;
68
69
70 private static SolverFactory instance;
71
72
73
74
75
76
77 private SolverFactory() {
78 super();
79 }
80
81 private static synchronized void createInstance() {
82 if (instance == null) {
83 instance = new SolverFactory();
84 }
85 }
86
87
88
89
90
91
92 public static SolverFactory instance() {
93 if (instance == null) {
94 createInstance();
95 }
96 return instance;
97 }
98
99
100
101
102
103
104 public static Solver<ILits,DataStructureFactory<ILits>> newMiniLearning() {
105 return newMiniLearning(10);
106 }
107
108
109
110
111
112
113 public static Solver<ILits,DataStructureFactory<ILits>> newMiniLearningHeap() {
114 return newMiniLearningHeap(new MixedDataStructureDaniel());
115 }
116
117 public static Solver<ILits,DataStructureFactory<ILits>> newMiniLearningHeapEZSimp() {
118 Solver<ILits,DataStructureFactory<ILits>> solver = newMiniLearningHeap();
119 solver.setSimplifier(solver.SIMPLE_SIMPLIFICATION);
120 return solver;
121 }
122
123 public static Solver<ILits,DataStructureFactory<ILits>> newMiniLearningHeapExpSimp() {
124 Solver<ILits,DataStructureFactory<ILits>> solver = newMiniLearningHeap();
125 solver.setSimplifier(solver.EXPENSIVE_SIMPLIFICATION);
126 return solver;
127 }
128
129 public static Solver<ILits,DataStructureFactory<ILits>> newMiniLearningHeapRsatExpSimp() {
130 Solver<ILits,DataStructureFactory<ILits>> solver = newMiniLearningHeapExpSimp();
131 solver.setOrder(new VarOrderHeap<ILits>(new RSATPhaseSelectionStrategy()));
132 return solver;
133 }
134
135 public static Solver<ILits,DataStructureFactory<ILits>> newMiniLearningHeapRsatExpSimpBiere() {
136 Solver<ILits,DataStructureFactory<ILits>> solver = newMiniLearningHeapRsatExpSimp();
137 solver.setRestartStrategy(new ArminRestarts());
138 solver.setSearchParams(new SearchParams(1.1, 100));
139 return solver;
140 }
141
142 public static Solver<ILits,DataStructureFactory<ILits>> newMiniSatHeapRsatExpSimpBiere() {
143 Solver<ILits,DataStructureFactory<ILits>> solver = newMiniSATHeapExpSimp();
144 solver.setOrder(new VarOrderHeap<ILits>(new RSATPhaseSelectionStrategy()));
145 solver.setRestartStrategy(new ArminRestarts());
146 solver.setSearchParams(new SearchParams(1.1, 100));
147 return solver;
148 }
149
150 public static Solver<ILits,DataStructureFactory<ILits>> newMiniLearningHeapRsatExpSimpLuby() {
151 Solver<ILits,DataStructureFactory<ILits>> solver = newMiniLearningHeapRsatExpSimp();
152 solver.setRestartStrategy(new LubyRestarts());
153 return solver;
154 }
155
156
157
158
159
160
161
162
163 public static Solver<ILits,DataStructureFactory<ILits>> newMiniLearning(int n) {
164 return newMiniLearning(new MixedDataStructureDaniel(), n);
165 }
166
167
168
169
170
171
172
173
174 public static <L extends ILits> Solver<L,DataStructureFactory<L>> newMiniLearning(
175 DataStructureFactory<L> dsf) {
176 return newMiniLearning(dsf, 10);
177 }
178
179
180
181
182
183
184
185
186 public static <L extends ILits> Solver<L,DataStructureFactory<L>> newMiniLearningHeap(
187 DataStructureFactory<L> dsf) {
188 return newMiniLearning(dsf, new VarOrderHeap<L>());
189 }
190
191
192
193
194
195
196 public static Solver<ILits2,DataStructureFactory<ILits2>> newMiniLearning2() {
197 return newMiniLearning(new MixedDataStructureWithBinary());
198 }
199
200 public static Solver<ILits2,DataStructureFactory<ILits2>> newMiniLearning2Heap() {
201 return newMiniLearningHeap(new MixedDataStructureWithBinary());
202 }
203
204
205
206
207
208
209
210 public static Solver<ILits23,DataStructureFactory<ILits23>> newMiniLearning23() {
211 return newMiniLearning(new MixedDataStructureWithBinaryAndTernary());
212 }
213
214
215
216
217
218 public static Solver<ILits,DataStructureFactory<ILits>> newMiniLearningCB() {
219 return newMiniLearning(new ClausalDataStructureCB());
220 }
221
222
223
224
225
226
227
228 public static Solver<ILits,DataStructureFactory<ILits>> newMiniLearningCBWL() {
229 return newMiniLearning(new ClausalDataStructureCBHT());
230 }
231
232 public static Solver<ILits2,DataStructureFactory<ILits2>> newMiniLearning2NewOrder() {
233 return newMiniLearning(new MixedDataStructureWithBinary(),
234 new MyOrder());
235 }
236
237
238
239
240
241
242
243
244 public static Solver<ILits,DataStructureFactory<ILits>> newMiniLearningPure() {
245 return newMiniLearning(new MixedDataStructureDaniel(), new PureOrder());
246 }
247
248
249
250
251
252 public static Solver<ILits,DataStructureFactory<ILits>> newMiniLearningCBWLPure() {
253 return newMiniLearning(new ClausalDataStructureCBHT(), new PureOrder());
254 }
255
256
257
258
259
260
261
262
263
264
265
266
267 public static <L extends ILits> Solver<L,DataStructureFactory<L>> newMiniLearning(
268 DataStructureFactory<L> dsf, int n) {
269 LimitedLearning<L,DataStructureFactory<L>> learning = new PercentLengthLearning<L,DataStructureFactory<L>>(n);
270 Solver<L,DataStructureFactory<L>> solver = new Solver<L,DataStructureFactory<L>>(new FirstUIP(), learning, dsf,
271 new VarOrder<L>(), new MiniSATRestarts());
272 learning.setSolver(solver);
273 return solver;
274 }
275
276
277
278
279
280
281
282
283
284
285
286
287 public static <L extends ILits> Solver<L,DataStructureFactory<L>> newMiniLearning(
288 DataStructureFactory<L> dsf, IOrder<L> order) {
289 LimitedLearning<L,DataStructureFactory<L>> learning = new PercentLengthLearning<L,DataStructureFactory<L>>(10);
290 Solver<L,DataStructureFactory<L>> solver = new Solver<L,DataStructureFactory<L>>(new FirstUIP(), learning, dsf, order,
291 new MiniSATRestarts());
292 learning.setSolver(solver);
293 return solver;
294 }
295
296 public static Solver<ILits,DataStructureFactory<ILits>> newMiniLearningEZSimp() {
297 return newMiniLearningEZSimp(new MixedDataStructureDaniel());
298 }
299
300
301
302
303
304 public static <L extends ILits> Solver<L,DataStructureFactory<L>> newMiniLearningEZSimp(
305 DataStructureFactory<L> dsf) {
306 LimitedLearning<L,DataStructureFactory<L>> learning = new PercentLengthLearning<L,DataStructureFactory<L>>(10);
307 Solver<L,DataStructureFactory<L>> solver = new Solver<L,DataStructureFactory<L>>(new FirstUIP(), learning, dsf,
308 new VarOrder<L>(), new MiniSATRestarts());
309 learning.setSolver(solver);
310 solver.setSimplifier(solver.SIMPLE_SIMPLIFICATION);
311 return solver;
312 }
313
314
315
316
317 public static Solver<ILits,DataStructureFactory<ILits>> newMiniLearningHeapEZSimpNoRestarts() {
318 LimitedLearning<ILits,DataStructureFactory<ILits>> learning = new PercentLengthLearning<ILits,DataStructureFactory<ILits>>(10);
319 Solver<ILits,DataStructureFactory<ILits>> solver = new Solver<ILits,DataStructureFactory<ILits>>(new FirstUIP(), learning,
320 new MixedDataStructureDaniel(), new SearchParams(
321 Integer.MAX_VALUE), new VarOrderHeap<ILits>(),
322 new MiniSATRestarts());
323 learning.setSolver(solver);
324 solver.setSimplifier(solver.SIMPLE_SIMPLIFICATION);
325 return solver;
326 }
327
328
329
330
331 public static Solver<ILits,DataStructureFactory<ILits>> newMiniLearningHeapEZSimpLongRestarts() {
332 LimitedLearning<ILits,DataStructureFactory<ILits>> learning = new PercentLengthLearning<ILits,DataStructureFactory<ILits>>(10);
333 Solver<ILits,DataStructureFactory<ILits>> solver = new Solver<ILits,DataStructureFactory<ILits>>(new FirstUIP(), learning,
334 new MixedDataStructureDaniel(), new SearchParams(1000),
335 new VarOrderHeap<ILits>(), new MiniSATRestarts());
336 learning.setSolver(solver);
337 solver.setSimplifier(solver.SIMPLE_SIMPLIFICATION);
338 return solver;
339 }
340
341
342
343
344
345
346
347 public static Solver<ILits,DataStructureFactory<ILits>> newActiveLearning() {
348 ActiveLearning<ILits,DataStructureFactory<ILits>> learning = new ActiveLearning<ILits,DataStructureFactory<ILits>>();
349 Solver<ILits,DataStructureFactory<ILits>> s = new Solver<ILits,DataStructureFactory<ILits>>(new FirstUIP(), learning,
350 new MixedDataStructureDaniel(), new VarOrder<ILits>(),
351 new MiniSATRestarts());
352 learning.setOrder(s.getOrder());
353 learning.setSolver(s);
354 return s;
355 }
356
357
358
359
360 public static Solver<ILits,DataStructureFactory<ILits>> newMiniSAT() {
361 return newMiniSAT(new MixedDataStructureDaniel());
362 }
363
364
365
366
367 public static Solver<ILits,DataStructureFactory<ILits>> newMiniSATNoRestarts() {
368 MiniSATLearning<ILits,DataStructureFactory<ILits>> learning = new MiniSATLearning<ILits,DataStructureFactory<ILits>>();
369 Solver<ILits,DataStructureFactory<ILits>> solver = new Solver<ILits,DataStructureFactory<ILits>>(new FirstUIP(), learning,
370 new MixedDataStructureDaniel(), new SearchParams(
371 Integer.MAX_VALUE), new VarOrder<ILits>(),
372 new MiniSATRestarts());
373 learning.setDataStructureFactory(solver.getDSFactory());
374 learning.setVarActivityListener(solver);
375 return solver;
376
377 }
378
379
380
381
382
383 public static Solver<ILits2,DataStructureFactory<ILits2>> newMiniSAT2() {
384 return newMiniSAT(new MixedDataStructureWithBinary());
385 }
386
387
388
389
390
391 public static Solver<ILits23,DataStructureFactory<ILits23>> newMiniSAT23() {
392 return newMiniSAT(new MixedDataStructureWithBinaryAndTernary());
393 }
394
395
396
397
398
399
400 public static <L extends ILits> Solver<L,DataStructureFactory<L>> newMiniSAT(
401 DataStructureFactory<L> dsf) {
402 MiniSATLearning<L,DataStructureFactory<L>> learning = new MiniSATLearning<L,DataStructureFactory<L>>();
403 Solver<L,DataStructureFactory<L>> solver = new Solver<L,DataStructureFactory<L>>(new FirstUIP(), learning, dsf,
404 new VarOrder<L>(), new MiniSATRestarts());
405 learning.setDataStructureFactory(solver.getDSFactory());
406 learning.setVarActivityListener(solver);
407 return solver;
408 }
409
410
411
412
413 public static Solver<ILits,DataStructureFactory<ILits>> newMiniSATHeap() {
414 return newMiniSATHeap(new MixedDataStructureDaniel());
415 }
416
417
418
419
420
421 public static Solver<ILits,DataStructureFactory<ILits>> newMiniSATHeapEZSimp() {
422 Solver<ILits,DataStructureFactory<ILits>> solver = newMiniSATHeap();
423 solver.setSimplifier(solver.SIMPLE_SIMPLIFICATION);
424 return solver;
425 }
426
427 public static Solver<ILits,DataStructureFactory<ILits>> newMiniSATHeapExpSimp() {
428 Solver<ILits,DataStructureFactory<ILits>> solver = newMiniSATHeap();
429 solver.setSimplifier(solver.EXPENSIVE_SIMPLIFICATION);
430 return solver;
431 }
432
433
434
435
436
437 public static Solver<ILits2,DataStructureFactory<ILits2>> newMiniSAT2Heap() {
438 return newMiniSATHeap(new MixedDataStructureWithBinary());
439 }
440
441
442
443
444
445 public static Solver<ILits23,DataStructureFactory<ILits23>> newMiniSAT23Heap() {
446 return newMiniSATHeap(new MixedDataStructureWithBinaryAndTernary());
447 }
448
449 public static <L extends ILits> Solver<L,DataStructureFactory<L>> newMiniSATHeap(
450 DataStructureFactory<L> dsf) {
451 MiniSATLearning<L,DataStructureFactory<L>> learning = new MiniSATLearning<L,DataStructureFactory<L>>();
452 Solver<L,DataStructureFactory<L>> solver = new Solver<L,DataStructureFactory<L>>(new FirstUIP(), learning, dsf,
453 new VarOrderHeap<L>(), new MiniSATRestarts());
454 learning.setDataStructureFactory(solver.getDSFactory());
455 learning.setVarActivityListener(solver);
456 return solver;
457 }
458
459
460
461
462 public static Solver<ILits,DataStructureFactory<ILits>> newMiniCard() {
463 return newMiniSAT(new CardinalityDataStructure());
464 }
465
466
467
468
469
470 public static Solver<ILits,DataStructureFactory<ILits>> newRelsat() {
471 MiniSATLearning<ILits,DataStructureFactory<ILits>> learning = new MiniSATLearning<ILits,DataStructureFactory<ILits>>();
472 Solver<ILits,DataStructureFactory<ILits>> solver = new Solver<ILits,DataStructureFactory<ILits>>(new DecisionUIP(), learning,
473 new MixedDataStructureDaniel(), new VarOrderHeap<ILits>(),
474 new MiniSATRestarts());
475 learning.setDataStructureFactory(solver.getDSFactory());
476 learning.setVarActivityListener(solver);
477 return solver;
478 }
479
480
481
482
483
484 public static Solver<ILits,DataStructureFactory<ILits>> newBackjumping() {
485 NoLearningButHeuristics<ILits,DataStructureFactory<ILits>> learning = new NoLearningButHeuristics<ILits,DataStructureFactory<ILits>>();
486 Solver<ILits,DataStructureFactory<ILits>> solver = new Solver<ILits,DataStructureFactory<ILits>>(new FirstUIP(), learning,
487 new MixedDataStructureDaniel(), new VarOrderHeap<ILits>(),
488 new MiniSATRestarts());
489 learning.setVarActivityListener(solver);
490 return solver;
491 }
492
493
494
495
496
497
498
499 public static Solver<ILits23,DataStructureFactory<ILits23>> newMini3SAT() {
500 LimitedLearning<ILits23,DataStructureFactory<ILits23>> learning = new FixedLengthLearning<ILits23,DataStructureFactory<ILits23>>(3);
501 Solver<ILits23,DataStructureFactory<ILits23>> solver = new Solver<ILits23,DataStructureFactory<ILits23>>(new FirstUIP(), learning,
502 new MixedDataStructureWithBinaryAndTernary(), new SearchParams(
503 Integer.MAX_VALUE), new JWOrder(),
504 new MiniSATRestarts());
505 learning.setSolver(solver);
506 return solver;
507 }
508
509
510
511
512
513 public static Solver<ILits23,DataStructureFactory<ILits23>> newMini3SATb() {
514 MiniSATLearning<ILits23,DataStructureFactory<ILits23>> learning = new MiniSATLearning<ILits23,DataStructureFactory<ILits23>>();
515 Solver<ILits23,DataStructureFactory<ILits23>> solver = new Solver<ILits23,DataStructureFactory<ILits23>>(new FirstUIP(), learning,
516 new MixedDataStructureWithBinaryAndTernary(), new SearchParams(
517 Integer.MAX_VALUE), new JWOrder(),
518 new MiniSATRestarts());
519 learning.setDataStructureFactory(solver.getDSFactory());
520 learning.setVarActivityListener(solver);
521 return solver;
522 }
523
524
525
526
527 public static ISolver newMinOneSolver() {
528 return new OptToSatAdapter(new MinOneDecorator(newDefault()));
529 }
530
531
532
533
534
535
536
537
538
539 public static ISolver newDefault() {
540 return newMiniLearningHeapRsatExpSimpBiere();
541 }
542
543 @Override
544 public ISolver defaultSolver() {
545 return newDefault();
546 }
547
548
549
550
551
552
553
554
555 public static ISolver newLight() {
556 return newMini3SAT();
557 }
558
559 @Override
560 public ISolver lightSolver() {
561 return newLight();
562 }
563
564 public static ISolver newDimacsOutput() {
565 return new DimacsOutputSolver();
566 }
567
568 }