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 package org.sat4j.pb;
29
30 import org.sat4j.core.ASolverFactory;
31 import org.sat4j.minisat.core.IOrder;
32 import org.sat4j.minisat.core.IPhaseSelectionStrategy;
33 import org.sat4j.minisat.learning.ClauseOnlyLearning;
34 import org.sat4j.minisat.learning.MiniSATLearning;
35 import org.sat4j.minisat.learning.NoLearningButHeuristics;
36 import org.sat4j.minisat.orders.PhaseInLastLearnedClauseSelectionStrategy;
37 import org.sat4j.minisat.orders.RSATPhaseSelectionStrategy;
38 import org.sat4j.minisat.orders.UserFixedPhaseSelectionStrategy;
39 import org.sat4j.minisat.orders.VarOrderHeap;
40 import org.sat4j.minisat.restarts.MiniSATRestarts;
41 import org.sat4j.minisat.uip.FirstUIP;
42 import org.sat4j.pb.constraints.AbstractPBDataStructureFactory;
43 import org.sat4j.pb.constraints.CompetMinHTmixedClauseCardConstrDataStructureFactory;
44 import org.sat4j.pb.constraints.CompetResolutionPBMixedHTClauseCardConstrDataStructure;
45 import org.sat4j.pb.constraints.PBMaxCBClauseCardConstrDataStructure;
46 import org.sat4j.pb.constraints.PBMaxClauseAtLeastConstrDataStructure;
47 import org.sat4j.pb.constraints.PBMaxClauseCardConstrDataStructure;
48 import org.sat4j.pb.constraints.PBMaxDataStructure;
49 import org.sat4j.pb.constraints.PBMinClauseCardConstrDataStructure;
50 import org.sat4j.pb.constraints.PBMinDataStructure;
51 import org.sat4j.pb.constraints.PuebloPBMinClauseAtLeastConstrDataStructure;
52 import org.sat4j.pb.constraints.PuebloPBMinClauseCardConstrDataStructure;
53 import org.sat4j.pb.constraints.PuebloPBMinDataStructure;
54 import org.sat4j.pb.core.PBDataStructureFactory;
55 import org.sat4j.pb.core.PBSolverCP;
56 import org.sat4j.pb.core.PBSolverClause;
57 import org.sat4j.pb.core.PBSolverResolution;
58 import org.sat4j.pb.core.PBSolverWithImpliedClause;
59 import org.sat4j.pb.orders.VarOrderHeapObjective;
60 import org.sat4j.specs.ISolver;
61 import org.sat4j.tools.DimacsOutputSolver;
62
63
64
65
66
67
68 public class SolverFactory extends ASolverFactory<IPBSolver> {
69
70
71
72
73 private static final long serialVersionUID = 1L;
74
75
76 private static SolverFactory instance;
77
78
79
80
81
82
83 private SolverFactory() {
84
85 }
86
87 private static synchronized void createInstance() {
88 if (instance == null) {
89 instance = new SolverFactory();
90 }
91 }
92
93
94
95
96
97
98 public static SolverFactory instance() {
99 if (instance == null) {
100 createInstance();
101 }
102 return instance;
103 }
104
105
106
107
108
109 public static PBSolverResolution newPBResAllPB() {
110 return newPBRes(new PBMaxDataStructure());
111 }
112
113
114
115
116
117 public static PBSolverCP newPBCPAllPB() {
118 return newPBCP(new PBMaxDataStructure());
119 }
120
121
122
123
124 public static IPBSolver newOPBStringSolver() {
125 return new OPBStringSolver();
126 }
127
128
129
130
131
132
133 public static PBSolverCP newPBCPMixedConstraints() {
134 return newPBCP(new PBMaxClauseCardConstrDataStructure());
135 }
136
137
138
139
140
141
142
143 public static PBSolverCP newPBCPMixedConstraintsObjective() {
144 return newPBCP(new PBMaxClauseCardConstrDataStructure(),
145 new VarOrderHeapObjective());
146 }
147
148 public static PBSolverCP newCompetPBCPMixedConstraintsObjective() {
149 return newPBCP(new PBMaxClauseCardConstrDataStructure(),
150 new VarOrderHeapObjective());
151 }
152
153
154
155
156
157
158
159
160
161 public static PBSolverCP newPBCPMixedConstraintsObjectiveLearnJustClauses() {
162 ClauseOnlyLearning<PBDataStructureFactory> learning = new ClauseOnlyLearning<PBDataStructureFactory>();
163 PBSolverCP solver = new PBSolverCP(new FirstUIP(), learning,
164 new PBMaxClauseCardConstrDataStructure(),
165 new VarOrderHeapObjective());
166 learning.setSolver(solver);
167 return solver;
168 }
169
170 public static PBSolverCP newCompetPBCPMixedConstraintsObjectiveLearnJustClauses() {
171 ClauseOnlyLearning<PBDataStructureFactory> learning = new ClauseOnlyLearning<PBDataStructureFactory>();
172 PBSolverCP solver = new PBSolverCP(new FirstUIP(), learning,
173 new PBMaxClauseCardConstrDataStructure(),
174 new VarOrderHeapObjective());
175 learning.setSolver(solver);
176 return solver;
177 }
178
179 private static PBSolverCP newPBKiller(IPhaseSelectionStrategy phase) {
180 ClauseOnlyLearning<PBDataStructureFactory> learning = new ClauseOnlyLearning<PBDataStructureFactory>();
181 PBSolverCP solver = new PBSolverCP(new FirstUIP(), learning,
182 new PBMaxClauseCardConstrDataStructure(),
183 new VarOrderHeapObjective(phase));
184 learning.setSolver(solver);
185 return solver;
186 }
187
188 public static PBSolverCP newPBKillerRSAT() {
189 return newPBKiller(new RSATPhaseSelectionStrategy());
190 }
191
192 public static PBSolverCP newPBKillerClassic() {
193 return newPBKiller(new PhaseInLastLearnedClauseSelectionStrategy());
194 }
195
196 public static PBSolverCP newPBKillerFixed() {
197 return newPBKiller(new UserFixedPhaseSelectionStrategy());
198 }
199
200 private static PBSolverCP newCompetPBKiller(IPhaseSelectionStrategy phase) {
201 ClauseOnlyLearning<PBDataStructureFactory> learning = new ClauseOnlyLearning<PBDataStructureFactory>();
202 PBSolverCP solver = new PBSolverCP(new FirstUIP(), learning,
203 new PBMaxClauseCardConstrDataStructure(),
204 new VarOrderHeapObjective(phase));
205 learning.setSolver(solver);
206 return solver;
207 }
208
209 public static PBSolverCP newCompetPBKillerRSAT() {
210 return newCompetPBKiller(new RSATPhaseSelectionStrategy());
211 }
212
213 public static PBSolverCP newCompetPBKillerClassic() {
214 return newCompetPBKiller(new PhaseInLastLearnedClauseSelectionStrategy());
215 }
216
217 public static PBSolverCP newCompetPBKillerFixed() {
218 return newCompetPBKiller(new UserFixedPhaseSelectionStrategy());
219 }
220
221
222
223
224
225
226
227
228 public static PBSolverCP newMiniLearningOPBClauseCardConstrMaxSpecificOrderIncrementalReductionToClause() {
229
230 MiniSATLearning<PBDataStructureFactory> learning = new MiniSATLearning<PBDataStructureFactory>();
231
232 PBSolverCP solver = new PBSolverClause(new FirstUIP(), learning,
233 new PBMaxClauseCardConstrDataStructure(),
234 new VarOrderHeapObjective());
235 learning.setDataStructureFactory(solver.getDSFactory());
236 learning.setVarActivityListener(solver);
237 return solver;
238 }
239
240
241
242
243
244
245
246
247 public static PBSolverCP newPBCPMixedConstraintsObjectiveNoLearning() {
248 NoLearningButHeuristics<PBDataStructureFactory> learning = new NoLearningButHeuristics<PBDataStructureFactory>();
249
250 PBSolverCP solver = new PBSolverCP(new FirstUIP(), learning,
251 new PBMaxClauseCardConstrDataStructure(),
252 new VarOrderHeapObjective());
253 learning.setSolver(solver);
254 learning.setVarActivityListener(solver);
255 return solver;
256 }
257
258 public static PBSolverResolution newPBResMixedConstraintsObjective() {
259 MiniSATLearning<PBDataStructureFactory> learning = new MiniSATLearning<PBDataStructureFactory>();
260 PBSolverResolution solver = new PBSolverResolution(new FirstUIP(),
261 learning, new PBMaxClauseCardConstrDataStructure(),
262 new VarOrderHeapObjective(), new MiniSATRestarts());
263 learning.setDataStructureFactory(solver.getDSFactory());
264 learning.setVarActivityListener(solver);
265 return solver;
266 }
267
268 public static PBSolverResolution newCompetPBResHTMixedConstraintsObjective() {
269 MiniSATLearning<PBDataStructureFactory> learning = new MiniSATLearning<PBDataStructureFactory>();
270 PBSolverResolution solver = new PBSolverResolution(new FirstUIP(),
271 learning,
272 new CompetResolutionPBMixedHTClauseCardConstrDataStructure(),
273 new VarOrderHeapObjective(), new MiniSATRestarts());
274 learning.setDataStructureFactory(solver.getDSFactory());
275 learning.setVarActivityListener(solver);
276 return solver;
277 }
278
279 public static PBSolverResolution newPBResHTMixedConstraintsObjective() {
280 MiniSATLearning<PBDataStructureFactory> learning = new MiniSATLearning<PBDataStructureFactory>();
281 AbstractPBDataStructureFactory ds = new CompetResolutionPBMixedHTClauseCardConstrDataStructure();
282 ds.setNormalizer(AbstractPBDataStructureFactory.NO_COMPETITION);
283 PBSolverResolution solver = new PBSolverResolution(new FirstUIP(),
284 learning, ds, new VarOrderHeapObjective(),
285 new MiniSATRestarts());
286 learning.setDataStructureFactory(solver.getDSFactory());
287 learning.setVarActivityListener(solver);
288 return solver;
289 }
290
291 public static PBSolverResolution newCompetPBResMinHTMixedConstraintsObjective() {
292 MiniSATLearning<PBDataStructureFactory> learning = new MiniSATLearning<PBDataStructureFactory>();
293 PBSolverResolution solver = new PBSolverResolution(new FirstUIP(),
294 learning,
295 new CompetMinHTmixedClauseCardConstrDataStructureFactory(),
296 new VarOrderHeapObjective(), new MiniSATRestarts());
297 learning.setDataStructureFactory(solver.getDSFactory());
298 learning.setVarActivityListener(solver);
299 return solver;
300 }
301
302 public static PBSolverResolution newPBResMinHTMixedConstraintsObjective() {
303 MiniSATLearning<PBDataStructureFactory> learning = new MiniSATLearning<PBDataStructureFactory>();
304 AbstractPBDataStructureFactory ds = new CompetMinHTmixedClauseCardConstrDataStructureFactory();
305 ds.setNormalizer(AbstractPBDataStructureFactory.NO_COMPETITION);
306 PBSolverResolution solver = new PBSolverResolution(new FirstUIP(),
307 learning, ds, new VarOrderHeapObjective(),
308 new MiniSATRestarts());
309 learning.setDataStructureFactory(solver.getDSFactory());
310 learning.setVarActivityListener(solver);
311 return solver;
312 }
313
314 public static PBSolverResolution newCompetPBResMixedConstraintsObjectiveExpSimp() {
315 PBSolverResolution solver = newPBResMixedConstraintsObjective();
316 solver.setSimplifier(solver.EXPENSIVE_SIMPLIFICATION);
317 return solver;
318 }
319
320 public static PBSolverResolution newCompetPBResHTMixedConstraintsObjectiveExpSimp() {
321 PBSolverResolution solver = newCompetPBResHTMixedConstraintsObjective();
322 solver.setSimplifier(solver.EXPENSIVE_SIMPLIFICATION);
323 return solver;
324 }
325
326 public static PBSolverResolution newPBResHTMixedConstraintsObjectiveExpSimp() {
327 PBSolverResolution solver = newPBResHTMixedConstraintsObjective();
328 solver.setSimplifier(solver.EXPENSIVE_SIMPLIFICATION);
329 return solver;
330 }
331
332 public static PBSolverResolution newCompetPBResMinHTMixedConstraintsObjectiveExpSimp() {
333 PBSolverResolution solver = newCompetPBResMinHTMixedConstraintsObjective();
334 solver.setSimplifier(solver.EXPENSIVE_SIMPLIFICATION);
335 return solver;
336 }
337
338
339
340
341
342
343
344
345 public static PBSolverClause newPBCPMixedConstraintsReduceToClause() {
346 MiniSATLearning<PBDataStructureFactory> learning = new MiniSATLearning<PBDataStructureFactory>();
347 PBSolverClause solver = new PBSolverClause(new FirstUIP(), learning,
348 new PBMaxClauseCardConstrDataStructure(), new VarOrderHeap());
349 learning.setDataStructureFactory(solver.getDSFactory());
350 learning.setVarActivityListener(solver);
351 return solver;
352 }
353
354
355
356
357
358
359
360 public static PBSolverWithImpliedClause newPBCPMixedConstrainsImplied() {
361 MiniSATLearning<PBDataStructureFactory> learning = new MiniSATLearning<PBDataStructureFactory>();
362 PBSolverWithImpliedClause solver = new PBSolverWithImpliedClause(
363 new FirstUIP(), learning,
364 new PBMaxClauseCardConstrDataStructure(), new VarOrderHeap());
365 learning.setDataStructureFactory(solver.getDSFactory());
366 learning.setVarActivityListener(solver);
367 return solver;
368 }
369
370
371
372
373
374
375
376
377 public static PBSolverCP newMiniOPBClauseAtLeastConstrMax() {
378 return newPBCP(new PBMaxClauseAtLeastConstrDataStructure());
379 }
380
381
382
383
384
385 public static PBSolverCP newMiniOPBCounterBasedClauseCardConstrMax() {
386 return newPBCP(new PBMaxCBClauseCardConstrDataStructure());
387 }
388
389
390
391
392
393 public static PBSolverResolution newPBResAllPBWL() {
394 return newPBRes(new PBMinDataStructure());
395 }
396
397
398
399
400
401 public static PBSolverCP newPBCPAllPBWL() {
402 return newPBCP(new PBMinDataStructure());
403 }
404
405
406
407
408
409 public static PBSolverResolution newPBResAllPBWLPueblo() {
410 return newPBRes(new PuebloPBMinDataStructure());
411 }
412
413 private static PBSolverResolution newPBRes(PBDataStructureFactory dsf) {
414 MiniSATLearning<PBDataStructureFactory> learning = new MiniSATLearning<PBDataStructureFactory>();
415 PBSolverResolution solver = new PBSolverResolution(new FirstUIP(),
416 learning, dsf, new VarOrderHeap(), new MiniSATRestarts());
417 learning.setDataStructureFactory(solver.getDSFactory());
418 learning.setVarActivityListener(solver);
419 return solver;
420 }
421
422
423
424
425
426 public static PBSolverCP newPBCPAllPBWLPueblo() {
427 return newPBCP(new PuebloPBMinDataStructure());
428 }
429
430
431
432
433
434 public static PBSolverCP newMiniOPBClauseCardMinPueblo() {
435 return newPBCP(new PuebloPBMinClauseCardConstrDataStructure());
436 }
437
438
439
440
441
442 public static PBSolverCP newMiniOPBClauseCardMin() {
443 return newPBCP(new PBMinClauseCardConstrDataStructure());
444 }
445
446
447
448
449
450 public static PBSolverCP newMiniOPBClauseAtLeastMinPueblo() {
451 return newPBCP(new PuebloPBMinClauseAtLeastConstrDataStructure());
452 }
453
454 private static PBSolverCP newPBCP(PBDataStructureFactory dsf, IOrder order) {
455 MiniSATLearning<PBDataStructureFactory> learning = new MiniSATLearning<PBDataStructureFactory>();
456 PBSolverCP solver = new PBSolverCP(new FirstUIP(), learning, dsf, order);
457 learning.setDataStructureFactory(solver.getDSFactory());
458 learning.setVarActivityListener(solver);
459 return solver;
460 }
461
462 private static PBSolverCP newPBCP(PBDataStructureFactory dsf) {
463 return newPBCP(dsf, new VarOrderHeap());
464 }
465
466
467
468
469
470
471
472 public static IPBSolver newCuttingPlanes() {
473 return newCompetPBCPMixedConstraintsObjective();
474 }
475
476
477
478
479
480
481
482 public static IPBSolver newResolution() {
483 return newCompetPBResMixedConstraintsObjectiveExpSimp();
484 }
485
486
487
488
489
490
491
492
493
494 public static IPBSolver newDefault() {
495 return newCompetPBResHTMixedConstraintsObjectiveExpSimp();
496 }
497
498
499
500
501
502
503
504
505
506 public static IPBSolver newDefaultNonNormalized() {
507 return newPBResHTMixedConstraintsObjectiveExpSimp();
508 }
509
510 @Override
511 public IPBSolver defaultSolver() {
512 return newDefault();
513 }
514
515
516
517
518
519
520
521
522 public static IPBSolver newLight() {
523 return newCompetPBResMixedConstraintsObjectiveExpSimp();
524 }
525
526 @Override
527 public IPBSolver lightSolver() {
528 return newLight();
529 }
530
531 public static ISolver newDimacsOutput() {
532 return new DimacsOutputSolver();
533 }
534
535 public static IPBSolver newEclipseP2() {
536 PBSolverResolution solver = newCompetPBResHTMixedConstraintsObjective();
537 solver.setTimeoutOnConflicts(300);
538 return new OptToPBSATAdapter(new PseudoOptDecorator(solver));
539 }
540
541 }