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