View Javadoc

1   /*******************************************************************************
2    * SAT4J: a SATisfiability library for Java Copyright (C) 2004, 2012 Artois University and CNRS
3    *
4    * All rights reserved. This program and the accompanying materials
5    * are made available under the terms of the Eclipse Public License v1.0
6    * which accompanies this distribution, and is available at
7    *  http://www.eclipse.org/legal/epl-v10.html
8    *
9    * Alternatively, the contents of this file may be used under the terms of
10   * either the GNU Lesser General Public License Version 2.1 or later (the
11   * "LGPL"), in which case the provisions of the LGPL are applicable instead
12   * of those above. If you wish to allow use of your version of this file only
13   * under the terms of the LGPL, and not to allow others to use your version of
14   * this file under the terms of the EPL, indicate your decision by deleting
15   * the provisions above and replace them with the notice and other provisions
16   * required by the LGPL. If you do not delete the provisions above, a recipient
17   * may use your version of this file under the terms of the EPL or the LGPL.
18   *
19   * Based on the original MiniSat specification from:
20   *
21   * An extensible SAT solver. Niklas Een and Niklas Sorensson. Proceedings of the
22   * Sixth International Conference on Theory and Applications of Satisfiability
23   * Testing, LNCS 2919, pp 502-518, 2003.
24   *
25   * See www.minisat.se for the original solver in C++.
26   *
27   * Contributors:
28   *   CRIL - initial API and implementation
29   *******************************************************************************/
30  package org.sat4j.pb;
31  
32  import org.sat4j.core.ASolverFactory;
33  import org.sat4j.minisat.core.IOrder;
34  import org.sat4j.minisat.core.IPhaseSelectionStrategy;
35  import org.sat4j.minisat.core.Solver;
36  import org.sat4j.minisat.learning.ClauseOnlyLearning;
37  import org.sat4j.minisat.learning.MiniSATLearning;
38  import org.sat4j.minisat.learning.NoLearningButHeuristics;
39  import org.sat4j.minisat.orders.PhaseInLastLearnedClauseSelectionStrategy;
40  import org.sat4j.minisat.orders.RSATPhaseSelectionStrategy;
41  import org.sat4j.minisat.orders.UserFixedPhaseSelectionStrategy;
42  import org.sat4j.minisat.orders.VarOrderHeap;
43  import org.sat4j.minisat.restarts.ArminRestarts;
44  import org.sat4j.minisat.restarts.LubyRestarts;
45  import org.sat4j.minisat.restarts.MiniSATRestarts;
46  import org.sat4j.pb.constraints.AbstractPBDataStructureFactory;
47  import org.sat4j.pb.constraints.CompetMinHTmixedClauseCardConstrDataStructureFactory;
48  import org.sat4j.pb.constraints.CompetResolutionMinPBLongMixedWLClauseCardConstrDataStructure;
49  import org.sat4j.pb.constraints.CompetResolutionPBLongMixedHTClauseCardConstrDataStructure;
50  import org.sat4j.pb.constraints.CompetResolutionPBLongMixedWLClauseCardConstrDataStructure;
51  import org.sat4j.pb.constraints.CompetResolutionPBMixedHTClauseCardConstrDataStructure;
52  import org.sat4j.pb.constraints.CompetResolutionPBMixedWLClauseCardConstrDataStructure;
53  import org.sat4j.pb.constraints.PBLongMaxClauseCardConstrDataStructure;
54  import org.sat4j.pb.constraints.PBLongMinClauseCardConstrDataStructure;
55  import org.sat4j.pb.constraints.PBMaxClauseAtLeastConstrDataStructure;
56  import org.sat4j.pb.constraints.PBMaxClauseCardConstrDataStructure;
57  import org.sat4j.pb.constraints.PBMaxDataStructure;
58  import org.sat4j.pb.constraints.PBMinClauseCardConstrDataStructure;
59  import org.sat4j.pb.constraints.PBMinDataStructure;
60  import org.sat4j.pb.constraints.PuebloPBMinClauseAtLeastConstrDataStructure;
61  import org.sat4j.pb.constraints.PuebloPBMinClauseCardConstrDataStructure;
62  import org.sat4j.pb.constraints.PuebloPBMinDataStructure;
63  import org.sat4j.pb.core.PBDataStructureFactory;
64  import org.sat4j.pb.core.PBSolver;
65  import org.sat4j.pb.core.PBSolverCP;
66  import org.sat4j.pb.core.PBSolverCautious;
67  import org.sat4j.pb.core.PBSolverClause;
68  import org.sat4j.pb.core.PBSolverResCP;
69  import org.sat4j.pb.core.PBSolverResolution;
70  import org.sat4j.pb.core.PBSolverWithImpliedClause;
71  import org.sat4j.pb.orders.VarOrderHeapObjective;
72  import org.sat4j.pb.tools.ClausalConstraintsDecorator;
73  import org.sat4j.pb.tools.ManyCorePB;
74  import org.sat4j.specs.ISolver;
75  import org.sat4j.tools.DimacsOutputSolver;
76  
77  /**
78   * User friendly access to pre-constructed solvers.
79   * 
80   * @author leberre
81   * @since 2.0
82   */
83  public class SolverFactory extends ASolverFactory<IPBSolver> {
84  
85      /**
86       * 
87       */
88      private static final long serialVersionUID = 1L;
89  
90      // thread safe implementation of the singleton design pattern
91      private static SolverFactory instance;
92  
93      /**
94       * Private contructor. Use singleton method instance() instead.
95       * 
96       * @see #instance()
97       */
98      private SolverFactory() {
99  
100     }
101 
102     private static synchronized void createInstance() {
103         if (instance == null) {
104             instance = new SolverFactory();
105         }
106     }
107 
108     /**
109      * Access to the single instance of the factory.
110      * 
111      * @return the singleton of that class.
112      */
113     public static SolverFactory instance() {
114         if (instance == null) {
115             createInstance();
116         }
117         return instance;
118     }
119 
120     /**
121      * @return MiniSAT with Counter-based pseudo boolean constraints and clause
122      *         learning.
123      */
124     public static PBSolverResolution newPBResAllPB() {
125         return newPBRes(new PBMaxDataStructure());
126     }
127 
128     /**
129      * @return MiniSAT with Counter-based pseudo boolean constraints and
130      *         constraint learning.
131      */
132     public static PBSolverCP newPBCPAllPB() {
133         return newPBCP(new PBMaxDataStructure());
134     }
135 
136     /**
137      * @return Solver used to display in a string the pb-instance in OPB format.
138      */
139     public static IPBSolver newOPBStringSolver() {
140         return new OPBStringSolver();
141     }
142 
143     /**
144      * @return MiniSAT with Counter-based pseudo boolean constraints and
145      *         constraint learning. Clauses and cardinalities with watched
146      *         literals are also handled (and learnt).
147      */
148     public static PBSolverCP newPBCPMixedConstraints() {
149         return newPBCP(new PBMaxClauseCardConstrDataStructure());
150     }
151 
152     /**
153      * @return MiniSAT with Counter-based pseudo boolean constraints and
154      *         constraint learning. Clauses and cardinalities with watched
155      *         literals are also handled (and learnt). A specific heuristics
156      *         taking into account the objective value is used.
157      */
158     public static PBSolverCP newPBCPMixedConstraintsObjective() {
159         return newPBCP(new PBMaxClauseCardConstrDataStructure(),
160                 new VarOrderHeapObjective());
161     }
162 
163     public static PBSolverCP newCompetPBCPMixedConstraintsObjective() {
164         return newPBCP(new PBMaxClauseCardConstrDataStructure(),
165                 new VarOrderHeapObjective());
166     }
167 
168     public static PBSolverCP newCompetPBCPMixedConstraintsMinObjective() {
169         return newPBCP(new PBMinClauseCardConstrDataStructure(),
170                 new VarOrderHeapObjective());
171     }
172 
173     public static PBSolverCP newCompetPBCPMixedConstraintsLongMaxObjective() {
174         return newPBCP(new PBLongMaxClauseCardConstrDataStructure(),
175                 new VarOrderHeapObjective());
176     }
177 
178     public static PBSolverCP newCompetPBCPMixedConstraintsLongMinObjective() {
179         return newPBCP(new PBLongMinClauseCardConstrDataStructure(),
180                 new VarOrderHeapObjective());
181     }
182 
183     /**
184      * @return MiniLearning with Counter-based pseudo boolean constraints and
185      *         constraint learning. Clauses and cardinalities with watched
186      *         literals are also handled (and learnt). A specific heuristics
187      *         taking into account the objective value is used. Conflict
188      *         analysis with full cutting plane inference. Only clauses are
189      *         recorded.
190      */
191     public static PBSolverCP newPBCPMixedConstraintsObjectiveLearnJustClauses() {
192         ClauseOnlyLearning<PBDataStructureFactory> learning = new ClauseOnlyLearning<PBDataStructureFactory>();
193         PBSolverCP solver = new PBSolverCP(learning,
194                 new PBMaxClauseCardConstrDataStructure(),
195                 new VarOrderHeapObjective());
196         learning.setSolver(solver);
197         return solver;
198     }
199 
200     public static PBSolverCP newCompetPBCPMixedConstraintsObjectiveLearnJustClauses() {
201         ClauseOnlyLearning<PBDataStructureFactory> learning = new ClauseOnlyLearning<PBDataStructureFactory>();
202         PBSolverCP solver = new PBSolverCP(learning,
203                 new PBMaxClauseCardConstrDataStructure(),
204                 new VarOrderHeapObjective());
205         learning.setSolver(solver);
206         return solver;
207     }
208 
209     private static PBSolverCP newPBKiller(IPhaseSelectionStrategy phase) {
210         ClauseOnlyLearning<PBDataStructureFactory> learning = new ClauseOnlyLearning<PBDataStructureFactory>();
211         PBSolverCP solver = new PBSolverCP(learning,
212                 new PBMaxClauseCardConstrDataStructure(),
213                 new VarOrderHeapObjective(phase));
214         learning.setSolver(solver);
215         return solver;
216     }
217 
218     public static PBSolverCP newPBKillerRSAT() {
219         return newPBKiller(new RSATPhaseSelectionStrategy());
220     }
221 
222     public static PBSolverCP newPBKillerClassic() {
223         return newPBKiller(new PhaseInLastLearnedClauseSelectionStrategy());
224     }
225 
226     public static PBSolverCP newPBKillerFixed() {
227         return newPBKiller(new UserFixedPhaseSelectionStrategy());
228     }
229 
230     private static PBSolverCP newCompetPBKiller(IPhaseSelectionStrategy phase) {
231         ClauseOnlyLearning<PBDataStructureFactory> learning = new ClauseOnlyLearning<PBDataStructureFactory>();
232         PBSolverCP solver = new PBSolverCP(learning,
233                 new PBMaxClauseCardConstrDataStructure(),
234                 new VarOrderHeapObjective(phase));
235         learning.setSolver(solver);
236         return solver;
237     }
238 
239     public static PBSolverCP newCompetPBKillerRSAT() {
240         return newCompetPBKiller(new RSATPhaseSelectionStrategy());
241     }
242 
243     public static PBSolverCP newCompetPBKillerClassic() {
244         return newCompetPBKiller(new PhaseInLastLearnedClauseSelectionStrategy());
245     }
246 
247     public static PBSolverCP newCompetPBKillerFixed() {
248         return newCompetPBKiller(new UserFixedPhaseSelectionStrategy());
249     }
250 
251     /**
252      * @return MiniLearning with Counter-based pseudo boolean constraints and
253      *         constraint learning. Clauses and cardinalities with watched
254      *         literals are also handled (and learnt). A specific heuristics
255      *         taking into account the objective value is used. Conflict
256      *         analysis reduces to clauses to avoid computations
257      */
258     public static PBSolverCP newMiniLearningOPBClauseCardConstrMaxSpecificOrderIncrementalReductionToClause() {
259         // LimitedLearning learning = new LimitedLearning(10);
260         MiniSATLearning<PBDataStructureFactory> learning = new MiniSATLearning<PBDataStructureFactory>();
261         // LearningStrategy learning = new NoLearningButHeuristics();
262         PBSolverCP solver = new PBSolverClause(learning,
263                 new PBMaxClauseCardConstrDataStructure(),
264                 new VarOrderHeapObjective());
265         learning.setDataStructureFactory(solver.getDSFactory());
266         learning.setVarActivityListener(solver);
267         return solver;
268     }
269 
270     /**
271      * @return MiniLearning with Counter-based pseudo boolean constraints and
272      *         constraint learning. Clauses and cardinalities with watched
273      *         literals are also handled (and learnt). A specific heuristics
274      *         taking into account the objective value is used. The PB
275      *         constraints are not learnt (watched), just used for backjumping.
276      */
277     public static PBSolverCP newPBCPMixedConstraintsObjectiveNoLearning() {
278         NoLearningButHeuristics<PBDataStructureFactory> learning = new NoLearningButHeuristics<PBDataStructureFactory>();
279         // SearchParams params = new SearchParams(1.1,100);
280         PBSolverCP solver = new PBSolverCP(learning,
281                 new PBMaxClauseCardConstrDataStructure(),
282                 new VarOrderHeapObjective());
283         learning.setSolver(solver);
284         learning.setVarActivityListener(solver);
285         return solver;
286     }
287 
288     public static PBSolverResolution newPBResMixedConstraintsObjective() {
289         MiniSATLearning<PBDataStructureFactory> learning = new MiniSATLearning<PBDataStructureFactory>();
290         PBSolverResolution solver = new PBSolverResolution(learning,
291                 new PBMaxClauseCardConstrDataStructure(),
292                 new VarOrderHeapObjective(), new MiniSATRestarts());
293         learning.setDataStructureFactory(solver.getDSFactory());
294         learning.setVarActivityListener(solver);
295         return solver;
296     }
297 
298     public static PBSolverResolution newCompetPBResWLMixedConstraintsObjectiveExpSimp() {
299         return newCompetPBResMixedConstraintsObjectiveExpSimp(new CompetResolutionPBMixedWLClauseCardConstrDataStructure());
300     }
301 
302     public static PBSolverResolution newCompetPBResHTMixedConstraintsObjectiveExpSimp() {
303         return newCompetPBResMixedConstraintsObjectiveExpSimp(new CompetResolutionPBMixedHTClauseCardConstrDataStructure());
304     }
305 
306     public static PBSolverResolution newCompetPBResLongHTMixedConstraintsObjectiveExpSimp() {
307         return newCompetPBResMixedConstraintsObjectiveExpSimp(new CompetResolutionPBLongMixedHTClauseCardConstrDataStructure());
308     }
309 
310     public static PBSolverResolution newCompetPBResLongWLMixedConstraintsObjectiveExpSimp() {
311         return newCompetPBResMixedConstraintsObjectiveExpSimp(new CompetResolutionPBLongMixedWLClauseCardConstrDataStructure());
312     }
313 
314     public static PBSolverResolution newCompetMinPBResLongWLMixedConstraintsObjectiveExpSimp() {
315         return newCompetPBResMixedConstraintsObjectiveExpSimp(new CompetResolutionMinPBLongMixedWLClauseCardConstrDataStructure());
316     }
317 
318     public static PBSolverResolution newCompetPBResMixedConstraintsObjectiveExpSimp(
319             PBDataStructureFactory dsf) {
320         MiniSATLearning<PBDataStructureFactory> learning = new MiniSATLearning<PBDataStructureFactory>();
321         PBSolverResolution solver = new PBSolverResolution(learning, dsf,
322                 new VarOrderHeapObjective(new RSATPhaseSelectionStrategy()),
323                 new ArminRestarts());
324         learning.setDataStructureFactory(solver.getDSFactory());
325         learning.setVarActivityListener(solver);
326         solver.setSimplifier(solver.EXPENSIVE_SIMPLIFICATION);
327         return solver;
328     }
329 
330     public static PBSolverResolution newPBResHTMixedConstraintsObjective() {
331         MiniSATLearning<PBDataStructureFactory> learning = new MiniSATLearning<PBDataStructureFactory>();
332         AbstractPBDataStructureFactory ds = new CompetResolutionPBMixedHTClauseCardConstrDataStructure();
333         ds.setNormalizer(AbstractPBDataStructureFactory.NO_COMPETITION);
334         PBSolverResolution solver = new PBSolverResolution(learning, ds,
335                 new VarOrderHeapObjective(), new MiniSATRestarts());
336         learning.setDataStructureFactory(solver.getDSFactory());
337         learning.setVarActivityListener(solver);
338         return solver;
339     }
340 
341     public static PBSolverResolution newCompetPBResMinHTMixedConstraintsObjective() {
342         MiniSATLearning<PBDataStructureFactory> learning = new MiniSATLearning<PBDataStructureFactory>();
343         PBSolverResolution solver = new PBSolverResolution(learning,
344                 new CompetMinHTmixedClauseCardConstrDataStructureFactory(),
345                 new VarOrderHeapObjective(), new MiniSATRestarts());
346         learning.setDataStructureFactory(solver.getDSFactory());
347         learning.setVarActivityListener(solver);
348         return solver;
349     }
350 
351     public static PBSolverResolution newPBResMinHTMixedConstraintsObjective() {
352         MiniSATLearning<PBDataStructureFactory> learning = new MiniSATLearning<PBDataStructureFactory>();
353         AbstractPBDataStructureFactory ds = new CompetMinHTmixedClauseCardConstrDataStructureFactory();
354         ds.setNormalizer(AbstractPBDataStructureFactory.NO_COMPETITION);
355         PBSolverResolution solver = new PBSolverResolution(learning, ds,
356                 new VarOrderHeapObjective(), new MiniSATRestarts());
357         learning.setDataStructureFactory(solver.getDSFactory());
358         learning.setVarActivityListener(solver);
359         return solver;
360     }
361 
362     public static PBSolverResolution newCompetPBResMixedConstraintsObjectiveExpSimp() {
363         PBSolverResolution solver = newPBResMixedConstraintsObjective();
364         solver.setSimplifier(solver.EXPENSIVE_SIMPLIFICATION);
365         return solver;
366     }
367 
368     public static PBSolverResolution newPBResHTMixedConstraintsObjectiveExpSimp() {
369         PBSolverResolution solver = newPBResHTMixedConstraintsObjective();
370         solver.setSimplifier(solver.EXPENSIVE_SIMPLIFICATION);
371         return solver;
372     }
373 
374     public static PBSolverResolution newCompetPBResMinHTMixedConstraintsObjectiveExpSimp() {
375         PBSolverResolution solver = newCompetPBResMinHTMixedConstraintsObjective();
376         solver.setSimplifier(solver.EXPENSIVE_SIMPLIFICATION);
377         return solver;
378     }
379 
380     /**
381      * @return MiniSAT with Counter-based pseudo boolean constraints and
382      *         constraint learning. Clauses and cardinalities with watched
383      *         literals are also handled (and learnt). A reduction of
384      *         PB-constraints to clauses is made in order to simplify cutting
385      *         planes.
386      */
387     public static PBSolverClause newPBCPMixedConstraintsReduceToClause() {
388         MiniSATLearning<PBDataStructureFactory> learning = new MiniSATLearning<PBDataStructureFactory>();
389         PBSolverClause solver = new PBSolverClause(learning,
390                 new PBMaxClauseCardConstrDataStructure(), new VarOrderHeap());
391         learning.setDataStructureFactory(solver.getDSFactory());
392         learning.setVarActivityListener(solver);
393         return solver;
394     }
395 
396     /**
397      * @return MiniSAT with Counter-based pseudo boolean constraints and
398      *         constraint learning. Clauses and cardinalities with watched
399      *         literals are also handled (and learnt). A reduction of
400      *         PB-constraints to clauses is made in order to simplify cutting
401      *         planes (if coefficients are larger than bound).
402      */
403     public static PBSolverCautious newPBCPMixedConstraintsCautious(int bound) {
404         MiniSATLearning<PBDataStructureFactory> learning = new MiniSATLearning<PBDataStructureFactory>();
405         PBSolverCautious solver = new PBSolverCautious(learning,
406                 new PBMaxClauseCardConstrDataStructure(),
407                 new VarOrderHeapObjective(), bound);
408         learning.setDataStructureFactory(solver.getDSFactory());
409         learning.setVarActivityListener(solver);
410         return solver;
411     }
412 
413     public static PBSolverCautious newPBCPMixedConstraintsCautious() {
414         return newPBCPMixedConstraintsCautious(PBSolverCautious.BOUND);
415     }
416 
417     /**
418      * @return MiniSAT with Counter-based pseudo boolean constraints and
419      *         constraint learning. Clauses and cardinalities with watched
420      *         literals are also handled (and learnt). A reduction of
421      *         PB-constraints to clauses is made in order to simplify cutting
422      *         planes (if coefficients are larger than bound).
423      */
424     public static PBSolverResCP newPBCPMixedConstraintsResCP(long bound) {
425         MiniSATLearning<PBDataStructureFactory> learning = new MiniSATLearning<PBDataStructureFactory>();
426         PBSolverResCP solver = new PBSolverResCP(learning,
427                 new PBMaxClauseCardConstrDataStructure(),
428                 new VarOrderHeapObjective(), bound);
429         learning.setDataStructureFactory(solver.getDSFactory());
430         learning.setVarActivityListener(solver);
431         solver.setSimplifier(solver.EXPENSIVE_SIMPLIFICATION);
432         return solver;
433     }
434 
435     public static PBSolverResCP newPBCPMixedConstraintsResCP() {
436         return newPBCPMixedConstraintsResCP(PBSolverResCP.MAXCONFLICTS);
437     }
438 
439     /**
440      * @return MiniSAT with Counter-based pseudo boolean constraints and
441      *         constraint learning. Clauses and cardinalities with watched
442      *         literals are also handled (and learnt). a pre-processing is
443      *         applied which adds implied clauses from PB-constraints.
444      */
445     public static PBSolverWithImpliedClause newPBCPMixedConstrainsImplied() {
446         MiniSATLearning<PBDataStructureFactory> learning = new MiniSATLearning<PBDataStructureFactory>();
447         PBSolverWithImpliedClause solver = new PBSolverWithImpliedClause(
448                 learning, new PBMaxClauseCardConstrDataStructure(),
449                 new VarOrderHeap());
450         learning.setDataStructureFactory(solver.getDSFactory());
451         learning.setVarActivityListener(solver);
452         return solver;
453     }
454 
455     /**
456      * @return MiniSAT with Counter-based pseudo boolean constraints,
457      *         counter-based cardinalities, watched clauses and constraint
458      *         learning. methods isAssertive() and getBacktrackLevel() are
459      *         totally incremental. Conflicts for PB-constraints use a Map
460      *         structure
461      */
462     public static PBSolverCP newMiniOPBClauseAtLeastConstrMax() {
463         return newPBCP(new PBMaxClauseAtLeastConstrDataStructure());
464     }
465 
466     /**
467      * @return MiniSAT with WL-based pseudo boolean constraints and clause
468      *         learning.
469      */
470     public static PBSolverResolution newPBResAllPBWL() {
471         return newPBRes(new PBMinDataStructure());
472     }
473 
474     /**
475      * @return MiniSAT with WL-based pseudo boolean constraints and constraint
476      *         learning.
477      */
478     public static PBSolverCP newPBCPAllPBWL() {
479         return newPBCP(new PBMinDataStructure());
480     }
481 
482     /**
483      * @return MiniSAT with WL-based pseudo boolean constraints and clause
484      *         learning.
485      */
486     public static PBSolverResolution newPBResAllPBWLPueblo() {
487         return newPBRes(new PuebloPBMinDataStructure());
488     }
489 
490     private static PBSolverResolution newPBRes(PBDataStructureFactory dsf) {
491         MiniSATLearning<PBDataStructureFactory> learning = new MiniSATLearning<PBDataStructureFactory>();
492         PBSolverResolution solver = new PBSolverResolution(learning, dsf,
493                 new VarOrderHeap(), new MiniSATRestarts());
494         learning.setDataStructureFactory(solver.getDSFactory());
495         learning.setVarActivityListener(solver);
496         return solver;
497     }
498 
499     /**
500      * @return MiniSAT with WL-based pseudo boolean constraints and constraint
501      *         learning.
502      */
503     public static PBSolverCP newPBCPAllPBWLPueblo() {
504         return newPBCP(new PuebloPBMinDataStructure());
505     }
506 
507     /**
508      * @return MiniSAT with WL-based pseudo boolean constraints and clauses,
509      *         cardinalities, and constraint learning.
510      */
511     public static PBSolverCP newMiniOPBClauseCardMinPueblo() {
512         return newPBCP(new PuebloPBMinClauseCardConstrDataStructure());
513     }
514 
515     /**
516      * @return MiniSAT with WL-based pseudo boolean constraints and clauses,
517      *         cardinalities, and constraint learning.
518      */
519     public static PBSolverCP newMiniOPBClauseCardMin() {
520         return newPBCP(new PBMinClauseCardConstrDataStructure());
521     }
522 
523     /**
524      * @return MiniSAT with WL-based pseudo boolean constraints and clauses,
525      *         counter-based cardinalities, and constraint learning.
526      */
527     public static PBSolverCP newMiniOPBClauseAtLeastMinPueblo() {
528         return newPBCP(new PuebloPBMinClauseAtLeastConstrDataStructure());
529     }
530 
531     private static PBSolverCP newPBCP(PBDataStructureFactory dsf, IOrder order) {
532         MiniSATLearning<PBDataStructureFactory> learning = new MiniSATLearning<PBDataStructureFactory>();
533         PBSolverCP solver = new PBSolverCP(learning, dsf, order);
534         learning.setDataStructureFactory(solver.getDSFactory());
535         learning.setVarActivityListener(solver);
536         solver.setRestartStrategy(new ArminRestarts());
537         solver.setLearnedConstraintsDeletionStrategy(solver.glucose);
538         return solver;
539     }
540 
541     private static PBSolverCP newPBCP(PBDataStructureFactory dsf) {
542         return newPBCP(dsf, new VarOrderHeap());
543     }
544 
545     /**
546      * Cutting Planes based solver. The inference during conflict analysis is
547      * based on cutting planes instead of resolution as in a SAT solver.
548      * 
549      * @return the best available cutting planes based solver of the library.
550      */
551     public static IPBSolver newCuttingPlanes() {
552         return newCompetPBCPMixedConstraintsObjective();
553     }
554 
555     /**
556      * Cutting Planes based solver. The inference during conflict analysis is
557      * based on cutting planes instead of resolution as in a SAT solver.
558      * 
559      * @return the best available cutting planes based solver of the library.
560      */
561     public static IPBSolver newCuttingPlanesAggressiveCleanup() {
562         PBSolverCP solver = newCompetPBCPMixedConstraintsObjective();
563         solver.setLearnedConstraintsDeletionStrategy(solver.fixedSize(100));
564         return solver;
565     }
566 
567     /**
568      * Resolution based solver (i.e. classic SAT solver able to handle generic
569      * constraints. No specific inference mechanism.
570      * 
571      * @return the best available resolution based solver of the library.
572      */
573     public static IPBSolver newResolution() {
574         return newResolutionGlucoseExpSimp();
575     }
576 
577     /**
578      * Resolution and CuttingPlanes based solvers running in parallel. Does only
579      * make sense if run on a computer with several cores.
580      * 
581      * @return a parallel solver using both resolution and cutting planes proof
582      *         system.
583      */
584     public static IPBSolver newBoth() {
585         return new ManyCorePB(newResolution(), newCuttingPlanes());
586     }
587 
588     /**
589      * Two solvers are running in //: one for solving SAT instances, the other
590      * one for solving unsat instances.
591      * 
592      * @return a parallel solver for both SAT and UNSAT problems.
593      */
594     public static IPBSolver newSATUNSAT() {
595         return new ManyCorePB(newSAT(), newUNSAT());
596     }
597 
598     /**
599      * That solver is expected to perform better on satisfiable benchmarks.
600      * 
601      * @return a solver for satisfiable benchmarks.
602      */
603     public static PBSolverResolution newSAT() {
604         PBSolverResolution solver = newResolutionGlucose();
605         solver.setRestartStrategy(new LubyRestarts(100));
606         solver.setLearnedConstraintsDeletionStrategy(solver.memory_based);
607         return solver;
608     }
609 
610     /**
611      * That solver is expected to perform better on unsatisfiable benchmarks.
612      * 
613      * @return a solver for unsatisfiable benchmarks.
614      */
615     public static PBSolverResolution newUNSAT() {
616         return newResolutionGlucose();
617     }
618 
619     /**
620      * Resolution based solver (i.e. classic SAT solver able to handle generic
621      * constraints. No specific inference mechanism). Uses glucose based memory
622      * management. The reason simplification is now disabled by default because
623      * it slows down a lot when long PB or cardinality constraints are used.
624      * 
625      * @return the best available resolution based solver of the library.
626      */
627     public static PBSolverResolution newResolutionGlucose() {
628         PBSolverResolution solver = newCompetPBResLongWLMixedConstraintsObjectiveExpSimp();
629         solver.setSimplifier(Solver.NO_SIMPLIFICATION);
630         solver.setLearnedConstraintsDeletionStrategy(solver.glucose);
631         return solver;
632     }
633 
634     /**
635      * Resolution based solver (i.e. classic SAT solver able to handle generic
636      * constraints. No specific inference mechanism). Uses glucose based memory
637      * management.
638      * 
639      * @return the best available resolution based solver of the library.
640      */
641     public static PBSolverResolution newResolutionGlucoseSimpleSimp() {
642         PBSolverResolution solver = newResolutionGlucose();
643         solver.setSimplifier(solver.SIMPLE_SIMPLIFICATION);
644         return solver;
645     }
646 
647     /**
648      * Resolution based solver (i.e. classic SAT solver able to handle generic
649      * constraints. No specific inference mechanism). Uses glucose based memory
650      * management. It uses the expensive reason simplification. If the problem
651      * contains long PB or cardinality constraints, it might be slowed down by
652      * such treatment.
653      * 
654      * @return the best available resolution based solver of the library.
655      */
656     public static PBSolverResolution newResolutionGlucoseExpSimp() {
657         PBSolverResolution solver = newResolutionGlucose();
658         solver.setSimplifier(solver.EXPENSIVE_SIMPLIFICATION);
659         return solver;
660     }
661 
662     /**
663      * Resolution based solver (i.e. classic SAT solver able to handle generic
664      * constraints. No specific inference mechanism). Uses glucose based memory
665      * management.
666      * 
667      * @return the best available resolution based solver of the library.
668      */
669     public static IPBSolver newSimpleSimplification() {
670         PBSolverResolution solver = newCompetPBResWLMixedConstraintsObjectiveExpSimp();
671         solver.setLearnedConstraintsDeletionStrategy(solver.glucose);
672         solver.setSimplifier(solver.SIMPLE_SIMPLIFICATION);
673         return solver;
674     }
675 
676     /**
677      * Resolution based solver (i.e. classic SAT solver able to handle generic
678      * constraints. No specific inference mechanism). Uses glucose based memory
679      * management. Uses a simple restart strategy (original Minisat's one).
680      * 
681      * @return the best available resolution based solver of the library.
682      */
683     public static IPBSolver newResolutionSimpleRestarts() {
684         PBSolverResolution solver = newCompetPBResLongWLMixedConstraintsObjectiveExpSimp();
685         solver.setLearnedConstraintsDeletionStrategy(solver.glucose);
686         solver.setRestartStrategy(new MiniSATRestarts());
687         return solver;
688     }
689 
690     /**
691      * Resolution based solver (i.e. classic SAT solver able to handle generic
692      * constraints. No specific inference mechanism).
693      * 
694      * Keeps the constraints as long as there is enough memory available.
695      * 
696      * @return the best available resolution based solver of the library.
697      */
698     public static IPBSolver newResolutionMaxMemory() {
699         PBSolverResolution solver = newCompetPBResLongWLMixedConstraintsObjectiveExpSimp();
700         solver.setLearnedConstraintsDeletionStrategy(solver.memory_based);
701         return solver;
702     }
703 
704     /**
705      * Default solver of the SolverFactory. This solver is meant to be used on
706      * challenging SAT benchmarks.
707      * 
708      * @return the best "general purpose" SAT solver available in the factory.
709      * @see #defaultSolver() the same method, polymorphic, to be called from an
710      *      instance of ASolverFactory.
711      */
712     public static PBSolver newDefault() {
713         return newResolutionGlucose();
714     }
715 
716     /**
717      * Default solver of the SolverFactory for instances not normalized. This
718      * solver is meant to be used on challenging SAT benchmarks.
719      * 
720      * @return the best "general purpose" SAT solver available in the factory.
721      * @see #defaultSolver() the same method, polymorphic, to be called from an
722      *      instance of ASolverFactory.
723      */
724     public static IPBSolver newDefaultNonNormalized() {
725         PBSolver solver = newDefault();
726         CompetResolutionPBLongMixedWLClauseCardConstrDataStructure ds = new CompetResolutionPBLongMixedWLClauseCardConstrDataStructure();
727         ds.setNormalizer(AbstractPBDataStructureFactory.NO_COMPETITION);
728         solver.setDataStructureFactory(ds);
729         return solver;
730     }
731 
732     @Override
733     public PBSolver defaultSolver() {
734         return newDefault();
735     }
736 
737     /**
738      * Small footprint SAT solver.
739      * 
740      * @return a SAT solver suitable for solving small/easy SAT benchmarks.
741      * @see #lightSolver() the same method, polymorphic, to be called from an
742      *      instance of ASolverFactory.
743      */
744     public static IPBSolver newLight() {
745         return newCompetPBResMixedConstraintsObjectiveExpSimp();
746     }
747 
748     @Override
749     public IPBSolver lightSolver() {
750         return newLight();
751     }
752 
753     public static ISolver newDimacsOutput() {
754         return new ClausalConstraintsDecorator(new DimacsOutputSolver());
755     }
756 
757     public static IPBSolver newEclipseP2() {
758         MiniSATLearning<PBDataStructureFactory> learning = new MiniSATLearning<PBDataStructureFactory>();
759         PBSolverResolution solver = new PBSolverResolution(learning,
760                 new CompetResolutionPBMixedHTClauseCardConstrDataStructure(),
761                 new VarOrderHeapObjective(new RSATPhaseSelectionStrategy()),
762                 new ArminRestarts());
763         learning.setDataStructureFactory(solver.getDSFactory());
764         learning.setVarActivityListener(solver);
765         solver.setTimeoutOnConflicts(300);
766         solver.setVerbose(false);
767         return new OptToPBSATAdapter(new PseudoOptDecorator(solver));
768     }
769 
770 }