View Javadoc

1   /*
2    * SAT4J: a SATisfiability library for Java Copyright (C) 2004-2006 Daniel Le
3    * Berre
4    * 
5    * Based on the original minisat specification from:
6    * 
7    * An extensible SAT solver. Niklas E?n and Niklas S?rensson. Proceedings of the
8    * Sixth International Conference on Theory and Applications of Satisfiability
9    * Testing, LNCS 2919, pp 502-518, 2003.
10   * 
11   * This library is free software; you can redistribute it and/or modify it under
12   * the terms of the GNU Lesser General Public License as published by the Free
13   * Software Foundation; either version 2.1 of the License, or (at your option)
14   * any later version.
15   * 
16   * This library is distributed in the hope that it will be useful, but WITHOUT
17   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
19   * details.
20   * 
21   * You should have received a copy of the GNU Lesser General Public License
22   * along with this library; if not, write to the Free Software Foundation, Inc.,
23   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24   * 
25   */
26  
27  package org.sat4j.minisat;
28  
29  import java.io.Serializable;
30  
31  import org.sat4j.core.ASolverFactory;
32  import org.sat4j.minisat.constraints.CardinalityDataStructure;
33  import org.sat4j.minisat.constraints.ClausalDataStructureCB;
34  import org.sat4j.minisat.constraints.ClausalDataStructureCBWL;
35  import org.sat4j.minisat.constraints.MixedDataStructureDaniel;
36  import org.sat4j.minisat.constraints.MixedDataStructureDanielCBWL;
37  import org.sat4j.minisat.constraints.MixedDataStructureWithBinary;
38  import org.sat4j.minisat.constraints.MixedDataStructureWithBinaryAndTernary;
39  import org.sat4j.minisat.constraints.PBMaxCBClauseCardConstrDataStructure;
40  import org.sat4j.minisat.constraints.PBMaxClauseAtLeastConstrDataStructure;
41  import org.sat4j.minisat.constraints.PBMaxClauseCardConstrDataStructure;
42  import org.sat4j.minisat.constraints.PBMaxDataStructure;
43  import org.sat4j.minisat.constraints.PBMinClauseCardConstrDataStructure;
44  import org.sat4j.minisat.constraints.PBMinDataStructure;
45  import org.sat4j.minisat.constraints.PuebloPBMinClauseAtLeastConstrDataStructure;
46  import org.sat4j.minisat.constraints.PuebloPBMinClauseCardConstrDataStructure;
47  import org.sat4j.minisat.constraints.PuebloPBMinDataStructure;
48  import org.sat4j.minisat.constraints.pb.PBSolver;
49  import org.sat4j.minisat.constraints.pb.PBSolverClause;
50  import org.sat4j.minisat.constraints.pb.PBSolverMerging;
51  import org.sat4j.minisat.constraints.pb.PBSolverWithImpliedClause;
52  import org.sat4j.minisat.core.DataStructureFactory;
53  import org.sat4j.minisat.core.ILits;
54  import org.sat4j.minisat.core.ILits2;
55  import org.sat4j.minisat.core.ILits23;
56  import org.sat4j.minisat.core.IOrder;
57  import org.sat4j.minisat.core.SearchParams;
58  import org.sat4j.minisat.core.Solver;
59  import org.sat4j.minisat.learning.ActiveLearning;
60  import org.sat4j.minisat.learning.ClauseOnlyLearning;
61  import org.sat4j.minisat.learning.FixedLengthLearning;
62  import org.sat4j.minisat.learning.LimitedLearning;
63  import org.sat4j.minisat.learning.MiniSATLearning;
64  import org.sat4j.minisat.learning.NoLearningButHeuristics;
65  import org.sat4j.minisat.learning.PercentLengthLearning;
66  import org.sat4j.minisat.orders.JWOrder;
67  import org.sat4j.minisat.orders.MyOrder;
68  import org.sat4j.minisat.orders.PureOrder;
69  import org.sat4j.minisat.orders.VarOrder;
70  import org.sat4j.minisat.orders.VarOrderHeap;
71  import org.sat4j.minisat.orders.VarOrderHeapObjective;
72  import org.sat4j.minisat.orders.VarOrderHeapRsat;
73  import org.sat4j.minisat.restarts.ArminRestarts;
74  import org.sat4j.minisat.restarts.LubyRestarts;
75  import org.sat4j.minisat.restarts.MiniSATRestarts;
76  import org.sat4j.minisat.uip.DecisionUIP;
77  import org.sat4j.minisat.uip.FirstUIP;
78  import org.sat4j.specs.ISolver;
79  import org.sat4j.tools.DimacsOutputSolver;
80  
81  /**
82   * User friendly access to pre-constructed solvers.
83   * 
84   * @author leberre
85   */
86  public class SolverFactory extends ASolverFactory implements Serializable {
87  
88      /**
89       * 
90       */
91      private static final long serialVersionUID = 1L;
92  
93      // thread safe implementation of the singleton design pattern
94      private static SolverFactory instance;
95  
96      /**
97       * Private contructor. Use singleton method instance() instead.
98       * 
99       * @see #instance()
100      */
101     private SolverFactory() {
102         super();
103     }
104 
105     private static synchronized void createInstance() {
106         if (instance == null) {
107             instance = new SolverFactory();
108         }
109     }
110 
111     /**
112      * Access to the single instance of the factory.
113      * 
114      * @return the singleton of that class.
115      */
116     public static SolverFactory instance() {
117         if (instance == null) {
118             createInstance();
119         }
120         return instance;
121     }
122 
123     /**
124      * @return a "default" "minilearning" solver learning clauses of size
125      *         smaller than 10 % of the total number of variables
126      */
127     public static Solver<ILits> newMiniLearning() {
128         return newMiniLearning(10);
129     }
130 
131     /**
132      * @return a "default" "minilearning" solver learning clauses of size
133      *         smaller than 10 % of the total number of variables with a heap
134      *         based var order.
135      */
136     public static Solver<ILits> newMiniLearningHeap() {
137         return newMiniLearningHeap(new MixedDataStructureDaniel());
138     }
139 
140     public static Solver<ILits> newMiniLearningHeapEZSimp() {
141         Solver<ILits> solver = newMiniLearningHeap();
142         solver.setSimplifier(solver.SIMPLE_SIMPLIFICATION);
143         return solver;
144     }
145 
146     public static Solver<ILits> newMiniLearningHeapExpSimp() {
147         Solver<ILits> solver = newMiniLearningHeap();
148         solver.setSimplifier(solver.EXPENSIVE_SIMPLIFICATION);
149         return solver;
150     }
151 
152     public static Solver<ILits> newMiniLearningHeapRsatExpSimp() {
153         Solver<ILits> solver = newMiniLearningHeapExpSimp();
154         solver.setOrder(new VarOrderHeapRsat());
155         return solver;
156     }
157 
158     public static Solver<ILits> newMiniLearningHeapRsatExpSimpBiere() {
159         Solver<ILits> solver = newMiniLearningHeapRsatExpSimp();
160         solver.setRestartStrategy(new ArminRestarts());
161         solver.setSearchParams(new SearchParams(1.1, 100));
162         return solver;
163     }
164 
165     public static Solver<ILits> newMiniLearningHeapRsatExpSimpLuby() {
166         Solver<ILits> solver = newMiniLearningHeapRsatExpSimp();
167         solver.setRestartStrategy(new LubyRestarts());
168         return solver;
169     }
170 
171     /**
172      * @param n
173      *                the maximal size of the clauses to learn as a percentage
174      *                of the initial number of variables
175      * @return a "minilearning" solver learning clauses of size smaller than n
176      *         of the total number of variables
177      */
178     public static Solver<ILits> newMiniLearning(int n) {
179         return newMiniLearning(new MixedDataStructureDaniel(), n);
180     }
181 
182     /**
183      * @param dsf
184      *                a specific data structure factory
185      * @return a default "minilearning" solver using a specific data structure
186      *         factory, learning clauses of length smaller or equals to 10 % of
187      *         the number of variables.
188      */
189     public static <L extends ILits> Solver<L> newMiniLearning(
190             DataStructureFactory<L> dsf) {
191         return newMiniLearning(dsf, 10);
192     }
193 
194     /**
195      * @param dsf
196      *                a specific data structure factory
197      * @return a default "minilearning" solver using a specific data structure
198      *         factory, learning clauses of length smaller or equals to 10 % of
199      *         the number of variables and a heap based VSIDS heuristics
200      */
201     public static <L extends ILits> Solver<L> newMiniLearningHeap(
202             DataStructureFactory<L> dsf) {
203         return newMiniLearning(dsf, new VarOrderHeap<L>());
204     }
205 
206     /**
207      * @return a default minilearning solver using a specific data structure
208      *         described in Lawrence Ryan thesis to handle binary clauses.
209      * @see #newMiniLearning
210      */
211     public static Solver<ILits2> newMiniLearning2() {
212         return newMiniLearning(new MixedDataStructureWithBinary());
213     }
214 
215     public static Solver<ILits2> newMiniLearning2Heap() {
216         return newMiniLearningHeap(new MixedDataStructureWithBinary());
217     }
218 
219     /**
220      * @return a default minilearning solver using a specific data structures
221      *         described in Lawrence Ryan thesis to handle binary and ternary
222      *         clauses.
223      * @see #newMiniLearning
224      */
225     public static Solver<ILits23> newMiniLearning23() {
226         return newMiniLearning(new MixedDataStructureWithBinaryAndTernary());
227     }
228 
229     /**
230      * @return a default minilearning SAT solver using counter-based clause
231      *         representation (i.e. all the literals of a clause are watched)
232      */
233     public static Solver<ILits> newMiniLearningCB() {
234         return newMiniLearning(new ClausalDataStructureCB());
235     }
236 
237     /**
238      * @return a default minilearning SAT solver using counter-based clause
239      *         representation (i.e. all the literals of a clause are watched)
240      *         for the ORIGINAL clauses and watched-literals clause
241      *         representation for learnt clauses.
242      */
243     public static Solver<ILits> newMiniLearningCBWL() {
244         return newMiniLearning(new ClausalDataStructureCBWL());
245     }
246 
247     public static Solver<ILits2> newMiniLearning2NewOrder() {
248         return newMiniLearning(new MixedDataStructureWithBinary(),
249                 new MyOrder());
250     }
251 
252     /**
253      * @return a default minilearning SAT solver choosing periodically to branch
254      *         on "pure watched" literals if any. (a pure watched literal l is a
255      *         literal that is watched on at least one clause such that its
256      *         negation is not watched at all. It is not necessarily a watched
257      *         literal.)
258      */
259     public static Solver<ILits> newMiniLearningPure() {
260         return newMiniLearning(new MixedDataStructureDaniel(), new PureOrder());
261     }
262 
263     /**
264      * @return a default minilearning SAT solver choosing periodically to branch
265      *         on literal "pure in the original set of clauses" if any.
266      */
267     public static Solver<ILits> newMiniLearningCBWLPure() {
268         return newMiniLearning(new ClausalDataStructureCBWL(), new PureOrder());
269     }
270 
271     /**
272      * @param dsf
273      *                the data structure factory used to represent literals and
274      *                clauses
275      * @param n
276      *                the maximum size of learnt clauses as percentage of the
277      *                original number of variables.
278      * @return a SAT solver with learning limited to clauses of length smaller
279      *         or equal to n, the dsf data structure, the FirstUIP clause
280      *         generator and a sort of VSIDS heuristics.
281      */
282     public static <L extends ILits> Solver<L> newMiniLearning(
283             DataStructureFactory<L> dsf, int n) {
284         LimitedLearning<L> learning = new PercentLengthLearning<L>(n);
285         Solver<L> solver = new Solver<L>(new FirstUIP(), learning, dsf,
286                 new VarOrder<L>(), new MiniSATRestarts());
287         learning.setSolver(solver);
288         return solver;
289     }
290 
291     /**
292      * @param dsf
293      *                the data structure factory used to represent literals and
294      *                clauses
295      * @param order
296      *                the heuristics
297      * @return a SAT solver with learning limited to clauses of length smaller
298      *         or equal to 10 percent of the total number of variables, the dsf
299      *         data structure, the FirstUIP clause generator and order as
300      *         heuristics.
301      */
302     public static <L extends ILits> Solver<L> newMiniLearning(
303             DataStructureFactory<L> dsf, IOrder<L> order) {
304         LimitedLearning<L> learning = new PercentLengthLearning<L>(10);
305         Solver<L> solver = new Solver<L>(new FirstUIP(), learning, dsf, order,
306                 new MiniSATRestarts());
307         learning.setSolver(solver);
308         return solver;
309     }
310 
311     public static Solver<ILits> newMiniLearningEZSimp() {
312         return newMiniLearningEZSimp(new MixedDataStructureDaniel());
313     }
314 
315     // public static ISolver newMiniLearning2EZSimp() {
316     // return newMiniLearningEZSimp(new MixedDataStructureWithBinary());
317     // }
318 
319     public static <L extends ILits> Solver<L> newMiniLearningEZSimp(
320             DataStructureFactory<L> dsf) {
321         LimitedLearning<L> learning = new PercentLengthLearning<L>(10);
322         Solver<L> solver = new Solver<L>(new FirstUIP(), learning, dsf,
323                 new VarOrder<L>(), new MiniSATRestarts());
324         learning.setSolver(solver);
325         solver.setSimplifier(solver.SIMPLE_SIMPLIFICATION);
326         return solver;
327     }
328 
329     /**
330      * @return a default MiniLearning without restarts.
331      */
332     public static Solver<ILits> newMiniLearningHeapEZSimpNoRestarts() {
333         LimitedLearning<ILits> learning = new PercentLengthLearning<ILits>(10);
334         Solver<ILits> solver = new Solver<ILits>(new FirstUIP(), learning,
335                 new MixedDataStructureDaniel(), new SearchParams(
336                         Integer.MAX_VALUE), new VarOrderHeap<ILits>(),
337                 new MiniSATRestarts());
338         learning.setSolver(solver);
339         solver.setSimplifier(solver.SIMPLE_SIMPLIFICATION);
340         return solver;
341     }
342 
343     /**
344      * @return a default MiniLearning with restarts beginning at 1000 conflicts.
345      */
346     public static Solver<ILits> newMiniLearningHeapEZSimpLongRestarts() {
347         LimitedLearning<ILits> learning = new PercentLengthLearning<ILits>(10);
348         Solver<ILits> solver = new Solver<ILits>(new FirstUIP(), learning,
349                 new MixedDataStructureDaniel(), new SearchParams(1000),
350                 new VarOrderHeap<ILits>(), new MiniSATRestarts());
351         learning.setSolver(solver);
352         solver.setSimplifier(solver.SIMPLE_SIMPLIFICATION);
353         return solver;
354     }
355 
356     /**
357      * @return a SAT solver using First UIP clause generator, watched literals,
358      *         VSIDS like heuristics learning only clauses having a great number
359      *         of active variables, i.e. variables with an activity strictly
360      *         greater than one.
361      */
362     public static Solver<ILits> newActiveLearning() {
363         ActiveLearning<ILits> learning = new ActiveLearning<ILits>();
364         Solver<ILits> s = new Solver<ILits>(new FirstUIP(), learning,
365                 new MixedDataStructureDaniel(), new VarOrder<ILits>(),
366                 new MiniSATRestarts());
367         learning.setOrder(s.getOrder());
368         learning.setSolver(s);
369         return s;
370     }
371 
372     /**
373      * @return a SAT solver very close to the original MiniSAT sat solver.
374      */
375     public static Solver<ILits> newMiniSAT() {
376         return newMiniSAT(new MixedDataStructureDaniel());
377     }
378 
379     /**
380      * @return MiniSAT without restarts.
381      */
382     public static Solver<ILits> newMiniSATNoRestarts() {
383         MiniSATLearning<ILits> learning = new MiniSATLearning<ILits>();
384         Solver<ILits> solver = new Solver<ILits>(new FirstUIP(), learning,
385                 new MixedDataStructureDaniel(), new SearchParams(
386                         Integer.MAX_VALUE), new VarOrder<ILits>(),
387                 new MiniSATRestarts());
388         learning.setDataStructureFactory(solver.getDSFactory());
389         learning.setVarActivityListener(solver);
390         return solver;
391 
392     }
393 
394     /**
395      * @return MiniSAT with a special data structure from Lawrence Ryan thesis
396      *         for managing binary clauses.
397      */
398     public static Solver<ILits2> newMiniSAT2() {
399         return newMiniSAT(new MixedDataStructureWithBinary());
400     }
401 
402     /**
403      * @return MiniSAT with a special data structure from Lawrence Ryan thesis
404      *         for managing binary and ternary clauses.
405      */
406     public static Solver<ILits23> newMiniSAT23() {
407         return newMiniSAT(new MixedDataStructureWithBinaryAndTernary());
408     }
409 
410     /**
411      * @param dsf
412      *                the data structure used for representing clauses and lits
413      * @return MiniSAT the data structure dsf.
414      */
415     public static <L extends ILits> Solver<L> newMiniSAT(
416             DataStructureFactory<L> dsf) {
417         MiniSATLearning<L> learning = new MiniSATLearning<L>();
418         Solver<L> solver = new Solver<L>(new FirstUIP(), learning, dsf,
419                 new VarOrder<L>(), new MiniSATRestarts());
420         learning.setDataStructureFactory(solver.getDSFactory());
421         learning.setVarActivityListener(solver);
422         return solver;
423     }
424 
425     /**
426      * @return a SAT solver very close to the original MiniSAT sat solver.
427      */
428     public static Solver<ILits> newMiniSATHeap() {
429         return newMiniSATHeap(new MixedDataStructureDaniel());
430     }
431 
432     /**
433      * @return a SAT solver very close to the original MiniSAT sat solver
434      *         including easy reason simplification.
435      */
436     public static Solver<ILits> newMiniSATHeapEZSimp() {
437         Solver<ILits> solver = newMiniSATHeap();
438         solver.setSimplifier(solver.SIMPLE_SIMPLIFICATION);
439         return solver;
440     }
441 
442     public static Solver<ILits> newMiniSATHeapExpSimp() {
443         Solver<ILits> solver = newMiniSATHeap();
444         solver.setSimplifier(solver.EXPENSIVE_SIMPLIFICATION);
445         return solver;
446     }
447 
448     /**
449      * @return MiniSAT with a special data structure from Lawrence Ryan thesis
450      *         for managing binary clauses.
451      */
452     public static Solver<ILits2> newMiniSAT2Heap() {
453         return newMiniSATHeap(new MixedDataStructureWithBinary());
454     }
455 
456     /**
457      * @return MiniSAT with a special data structure from Lawrence Ryan thesis
458      *         for managing binary and ternary clauses.
459      */
460     public static Solver<ILits23> newMiniSAT23Heap() {
461         return newMiniSATHeap(new MixedDataStructureWithBinaryAndTernary());
462     }
463 
464     public static <L extends ILits> Solver<L> newMiniSATHeap(
465             DataStructureFactory<L> dsf) {
466         MiniSATLearning<L> learning = new MiniSATLearning<L>();
467         Solver<L> solver = new Solver<L>(new FirstUIP(), learning, dsf,
468                 new VarOrderHeap<L>(), new MiniSATRestarts());
469         learning.setDataStructureFactory(solver.getDSFactory());
470         learning.setVarActivityListener(solver);
471         return solver;
472     }
473 
474     /**
475      * @return MiniSAT with data structures to handle cardinality constraints.
476      */
477     public static Solver<ILits> newMiniCard() {
478         return newMiniSAT(new CardinalityDataStructure());
479     }
480 
481     /**
482      * @return MiniSAT with Counter-based pseudo boolean constraints and clause
483      *         learning.
484      */
485     public static Solver<ILits> newMinimalOPBMax() {
486         MiniSATLearning<ILits> learning = new MiniSATLearning<ILits>();
487         Solver<ILits> solver = new Solver<ILits>(new FirstUIP(), learning,
488                 new PBMaxDataStructure(), new VarOrderHeap<ILits>(),
489                 new MiniSATRestarts());
490         learning.setDataStructureFactory(solver.getDSFactory());
491         learning.setVarActivityListener(solver);
492         return solver;
493     }
494 
495     /**
496      * @return MiniSAT with Counter-based pseudo boolean constraints and
497      *         constraint learning.
498      */
499     public static Solver<ILits> newMiniOPBMax() {
500         MiniSATLearning<ILits> learning = new MiniSATLearning<ILits>();
501         Solver<ILits> solver = new PBSolver<ILits>(new FirstUIP(), learning,
502                 new PBMaxDataStructure(), new VarOrderHeap<ILits>());
503         learning.setDataStructureFactory(solver.getDSFactory());
504         learning.setVarActivityListener(solver);
505         return solver;
506     }
507 
508     /**
509      * @return MiniSAT with Counter-based pseudo boolean constraints and
510      *         constraint learning. Clauses and cardinalities with watched
511      *         literals are also handled (and learnt).
512      */
513     public static Solver<ILits> newMiniOPBClauseCardConstrMax() {
514         MiniSATLearning<ILits> learning = new MiniSATLearning<ILits>();
515         Solver<ILits> solver = new PBSolver<ILits>(new FirstUIP(), learning,
516                 new PBMaxClauseCardConstrDataStructure(),
517                 new VarOrderHeap<ILits>());
518         learning.setDataStructureFactory(solver.getDSFactory());
519         learning.setVarActivityListener(solver);
520         return solver;
521     }
522 
523     /**
524      * @return MiniSAT with Counter-based pseudo boolean constraints and
525      *         constraint learning. Clauses and cardinalities with watched
526      *         literals are also handled (and learnt). A specific heuristics
527      *         taking into account the objective value is used.
528      */
529     public static Solver<ILits> newMiniOPBClauseCardConstrMaxSpecificOrder() {
530         MiniSATLearning<ILits> learning = new MiniSATLearning<ILits>();
531         Solver<ILits> solver = new PBSolver<ILits>(new FirstUIP(), learning,
532                 new PBMaxClauseCardConstrDataStructure(),
533                 new VarOrderHeapObjective());
534         learning.setDataStructureFactory(solver.getDSFactory());
535         learning.setVarActivityListener(solver);
536         return solver;
537     }
538 
539     /**
540      * @return MiniLearning with Counter-based pseudo boolean constraints and
541      *         constraint learning. Clauses and cardinalities with watched
542      *         literals are also handled (and learnt). A specific heuristics
543      *         taking into account the objective value is used. Conflict
544      *         analysis with full cutting plane inference.
545      */
546     public static Solver<ILits> newMiniLearningOPBClauseCardConstrMaxSpecificOrderIncremental() {
547         // LimitedLearning learning = new LimitedLearning(10);
548         MiniSATLearning<ILits> learning = new MiniSATLearning<ILits>();
549         // LearningStrategy learning = new NoLearningButHeuristics();
550         Solver<ILits> solver = new PBSolver<ILits>(new FirstUIP(), learning,
551                 new PBMaxClauseCardConstrDataStructure(),
552                 new VarOrderHeapObjective());
553         learning.setDataStructureFactory(solver.getDSFactory());
554         learning.setVarActivityListener(solver);
555         return solver;
556     }
557 
558     /**
559      * @return MiniLearning with Counter-based pseudo boolean constraints and
560      *         constraint learning. Clauses and cardinalities with watched
561      *         literals are also handled (and learnt). A specific heuristics
562      *         taking into account the objective value is used. Conflict
563      *         analysis with full cutting plane inference. Only clauses are
564      *         recorded.
565      */
566     public static Solver<ILits> newMiniLearningOPBClauseCardConstrMaxSpecificOrderIncrementalLearnJustClauses() {
567         ClauseOnlyLearning<ILits> learning = new ClauseOnlyLearning<ILits>();
568         Solver<ILits> solver = new PBSolver<ILits>(new FirstUIP(), learning,
569                 new PBMaxClauseCardConstrDataStructure(),
570                 new VarOrderHeapObjective());
571         learning.setSolver(solver);
572         return solver;
573     }
574 
575     /**
576      * @return MiniLearning with Counter-based pseudo boolean constraints and
577      *         constraint learning. Clauses and cardinalities with watched
578      *         literals are also handled (and learnt). A specific heuristics
579      *         taking into account the objective value is used. Conflict
580      *         analysis reduces to clauses to avoid computations
581      */
582     public static Solver<ILits> newMiniLearningOPBClauseCardConstrMaxSpecificOrderIncrementalReductionToClause() {
583         // LimitedLearning learning = new LimitedLearning(10);
584         MiniSATLearning<ILits> learning = new MiniSATLearning<ILits>();
585         // LearningStrategy learning = new NoLearningButHeuristics();
586         Solver<ILits> solver = new PBSolverClause(new FirstUIP(), learning,
587                 new PBMaxClauseCardConstrDataStructure(),
588                 new VarOrderHeapObjective());
589         learning.setDataStructureFactory(solver.getDSFactory());
590         learning.setVarActivityListener(solver);
591         return solver;
592     }
593 
594     /**
595      * @return MiniLearning with Counter-based pseudo boolean constraints and
596      *         constraint learning. Clauses and cardinalities with watched
597      *         literals are also handled (and learnt). A specific heuristics
598      *         taking into account the objective value is used. The PB
599      *         constraints are not learnt (watched), just used for backjumping.
600      */
601     public static Solver<ILits> newMiniLearningOPBClauseCardConstrMaxSpecificOrderIncrementalNoLearning() {
602         NoLearningButHeuristics<ILits> learning = new NoLearningButHeuristics<ILits>();
603         // SearchParams params = new SearchParams(1.1,100);
604         Solver<ILits> solver = new PBSolver<ILits>(new FirstUIP(), learning,
605                 new PBMaxClauseCardConstrDataStructure(),
606                 new VarOrderHeapObjective());
607         learning.setSolver(solver);
608         learning.setVarActivityListener(solver);
609         return solver;
610     }
611 
612     /**
613      * @return MiniLearning with Counter-based pseudo boolean constraints and
614      *         constraint learning. Clauses and cardinalities with watched
615      *         literals are also handled (and learnt). A specific heuristics
616      *         taking into account the objective value is used. Conflict
617      *         analysis uses fusion rule
618      */
619     public static Solver<ILits> newMiniLearningOPBClauseCardConstrMaxSpecificOrderIncrementalMerging() {
620         // LimitedLearning learning = new LimitedLearning(10);
621         MiniSATLearning<ILits> learning = new MiniSATLearning<ILits>();
622         // LearningStrategy learning = new NoLearningButHeuristics();
623         Solver<ILits> solver = new PBSolverMerging(new FirstUIP(), learning,
624                 new PBMaxClauseCardConstrDataStructure(),
625                 new VarOrderHeapObjective());
626         learning.setDataStructureFactory(solver.getDSFactory());
627         learning.setVarActivityListener(solver);
628         return solver;
629     }
630 
631     public static Solver<ILits> newMinimalOPBClauseCardConstrMaxSpecificOrder() {
632         MiniSATLearning<ILits> learning = new MiniSATLearning<ILits>();
633         Solver<ILits> solver = new Solver<ILits>(new FirstUIP(), learning,
634                 new PBMaxClauseCardConstrDataStructure(),
635                 new VarOrderHeapObjective(), new MiniSATRestarts());
636         learning.setDataStructureFactory(solver.getDSFactory());
637         learning.setVarActivityListener(solver);
638         return solver;
639     }
640 
641     /**
642      * @return MiniSAT with Counter-based pseudo boolean constraints and
643      *         constraint learning. Clauses and cardinalities with watched
644      *         literals are also handled (and learnt). A reduction of
645      *         PB-constraints to clauses is made in order to simplify cutting
646      *         planes.
647      */
648     public static Solver<ILits> newMiniOPBClauseCardConstrMaxReduceToClause() {
649         MiniSATLearning<ILits> learning = new MiniSATLearning<ILits>();
650         Solver<ILits> solver = new PBSolverClause(new FirstUIP(), learning,
651                 new PBMaxClauseCardConstrDataStructure(),
652                 new VarOrderHeap<ILits>());
653         learning.setDataStructureFactory(solver.getDSFactory());
654         learning.setVarActivityListener(solver);
655         return solver;
656     }
657 
658     /**
659      * @return MiniSAT with Counter-based pseudo boolean constraints and
660      *         constraint learning. Clauses and cardinalities with watched
661      *         literals are also handled (and learnt). A reduction of
662      *         PB-constraints to cardinalities is made in order to simplify
663      *         cutting planes.
664      */
665     // public static ISolver newMiniOPBClauseCardConstrMaxReduceToCard() {
666     // MiniSATLearning learning = new MiniSATLearning();
667     // Solver solver = new PBSolverCard(new FirstUIP(), learning,
668     // new PBMaxClauseCardConstrDataStructure(), new VarOrderHeap());
669     // learning.setDataStructureFactory(solver.getDSFactory());
670     // learning.setVarActivityListener(solver);
671     // return solver;
672     // }
673     /**
674      * @return MiniSAT with Counter-based pseudo boolean constraints and
675      *         constraint learning. Clauses and cardinalities with watched
676      *         literals are also handled (and learnt). a pre-processing is
677      *         applied which adds implied clauses from PB-constraints.
678      */
679     public static Solver<ILits> newMiniOPBClauseCardConstrMaxImplied() {
680         MiniSATLearning<ILits> learning = new MiniSATLearning<ILits>();
681         Solver<ILits> solver = new PBSolverWithImpliedClause(new FirstUIP(),
682                 learning, new PBMaxClauseCardConstrDataStructure(),
683                 new VarOrderHeap<ILits>());
684         learning.setDataStructureFactory(solver.getDSFactory());
685         learning.setVarActivityListener(solver);
686         return solver;
687     }
688 
689     /**
690      * @return MiniSAT with Counter-based pseudo boolean constraints,
691      *         counter-based cardinalities, watched clauses and constraint
692      *         learning. methods isAssertive() and getBacktrackLevel() are
693      *         totally incremental. Conflicts for PB-constraints use a Map
694      *         structure
695      */
696     public static Solver<ILits> newMiniOPBClauseAtLeastConstrMax() {
697         MiniSATLearning<ILits> learning = new MiniSATLearning<ILits>();
698         Solver<ILits> solver = new PBSolver<ILits>(new FirstUIP(), learning,
699                 new PBMaxClauseAtLeastConstrDataStructure(),
700                 new VarOrderHeap<ILits>());
701         learning.setDataStructureFactory(solver.getDSFactory());
702         learning.setVarActivityListener(solver);
703         return solver;
704     }
705 
706     /**
707      * @return MiniSAT with Counter-based pseudo boolean constraints and
708      *         clauses, watched cardinalities, and constraint learning.
709      */
710     public static Solver<ILits> newMiniOPBCounterBasedClauseCardConstrMax() {
711         MiniSATLearning<ILits> learning = new MiniSATLearning<ILits>();
712         Solver<ILits> solver = new PBSolver<ILits>(new FirstUIP(), learning,
713                 new PBMaxCBClauseCardConstrDataStructure(),
714                 new VarOrderHeap<ILits>());
715         learning.setDataStructureFactory(solver.getDSFactory());
716         learning.setVarActivityListener(solver);
717         return solver;
718     }
719 
720     /**
721      * @return MiniSAT with WL-based pseudo boolean constraints and clause
722      *         learning.
723      */
724     public static Solver<ILits> newMinimalOPBMin() {
725         MiniSATLearning<ILits> learning = new MiniSATLearning<ILits>();
726         Solver<ILits> solver = new Solver<ILits>(new FirstUIP(), learning,
727                 new PBMinDataStructure(), new VarOrderHeap<ILits>(),
728                 new MiniSATRestarts());
729         learning.setDataStructureFactory(solver.getDSFactory());
730         learning.setVarActivityListener(solver);
731         return solver;
732     }
733 
734     /**
735      * @return MiniSAT with WL-based pseudo boolean constraints and constraint
736      *         learning.
737      */
738     public static Solver<ILits> newMiniOPBMin() {
739         MiniSATLearning<ILits> learning = new MiniSATLearning<ILits>();
740         Solver<ILits> solver = new PBSolver<ILits>(new FirstUIP(), learning,
741                 new PBMinDataStructure(), new VarOrderHeap<ILits>());
742         learning.setDataStructureFactory(solver.getDSFactory());
743         learning.setVarActivityListener(solver);
744         return solver;
745     }
746 
747     /**
748      * @return MiniSAT with WL-based pseudo boolean constraints and clause
749      *         learning.
750      */
751     public static Solver<ILits> newMinimalOPBMinPueblo() {
752         MiniSATLearning<ILits> learning = new MiniSATLearning<ILits>();
753         Solver<ILits> solver = new Solver<ILits>(new FirstUIP(), learning,
754                 new PuebloPBMinDataStructure(), new VarOrderHeap<ILits>(),
755                 new MiniSATRestarts());
756         learning.setDataStructureFactory(solver.getDSFactory());
757         learning.setVarActivityListener(solver);
758         return solver;
759     }
760 
761     /**
762      * @return MiniSAT with WL-based pseudo boolean constraints and constraint
763      *         learning.
764      */
765     public static Solver<ILits> newMiniOPBMinPueblo() {
766         MiniSATLearning<ILits> learning = new MiniSATLearning<ILits>();
767         Solver<ILits> solver = new PBSolver<ILits>(new FirstUIP(), learning,
768                 new PuebloPBMinDataStructure(), new VarOrderHeap<ILits>());
769         learning.setDataStructureFactory(solver.getDSFactory());
770         learning.setVarActivityListener(solver);
771         return solver;
772     }
773 
774     /**
775      * @return MiniSAT with WL-based pseudo boolean constraints and clauses,
776      *         cardinalities, and constraint learning.
777      */
778     public static Solver<ILits> newMiniOPBClauseCardMinPueblo() {
779         MiniSATLearning<ILits> learning = new MiniSATLearning<ILits>();
780         Solver<ILits> solver = new PBSolver<ILits>(new FirstUIP(), learning,
781                 new PuebloPBMinClauseCardConstrDataStructure(),
782                 new VarOrderHeap<ILits>());
783         learning.setDataStructureFactory(solver.getDSFactory());
784         learning.setVarActivityListener(solver);
785         return solver;
786     }
787 
788     /**
789      * @return MiniSAT with WL-based pseudo boolean constraints and clauses,
790      *         cardinalities, and constraint learning.
791      */
792     public static Solver<ILits> newMiniOPBClauseCardMin() {
793         MiniSATLearning<ILits> learning = new MiniSATLearning<ILits>();
794         Solver<ILits> solver = new PBSolver<ILits>(new FirstUIP(), learning,
795                 new PBMinClauseCardConstrDataStructure(),
796                 new VarOrderHeap<ILits>());
797         learning.setDataStructureFactory(solver.getDSFactory());
798         learning.setVarActivityListener(solver);
799         return solver;
800     }
801 
802     /**
803      * @return MiniSAT with WL-based pseudo boolean constraints and clauses,
804      *         counter-based cardinalities, and constraint learning.
805      */
806     public static Solver<ILits> newMiniOPBClauseAtLeastMinPueblo() {
807         MiniSATLearning<ILits> learning = new MiniSATLearning<ILits>();
808         Solver<ILits> solver = new PBSolver<ILits>(new FirstUIP(), learning,
809                 new PuebloPBMinClauseAtLeastConstrDataStructure(),
810                 new VarOrderHeap<ILits>());
811         learning.setDataStructureFactory(solver.getDSFactory());
812         learning.setVarActivityListener(solver);
813         return solver;
814     }
815 
816     /**
817      * @return MiniSAT with decision UIP clause generator.
818      */
819     public static Solver<ILits> newRelsat() {
820         MiniSATLearning<ILits> learning = new MiniSATLearning<ILits>();
821         Solver<ILits> solver = new Solver<ILits>(new DecisionUIP(), learning,
822                 new MixedDataStructureDaniel(), new VarOrderHeap<ILits>(),
823                 new MiniSATRestarts());
824         learning.setDataStructureFactory(solver.getDSFactory());
825         learning.setVarActivityListener(solver);
826         return solver;
827     }
828 
829     /**
830      * @return MiniSAT with VSIDS heuristics, FirstUIP clause generator for
831      *         backjumping but no learning.
832      */
833     public static Solver<ILits> newBackjumping() {
834         NoLearningButHeuristics<ILits> learning = new NoLearningButHeuristics<ILits>();
835         Solver<ILits> solver = new Solver<ILits>(new FirstUIP(), learning,
836                 new MixedDataStructureDaniel(), new VarOrderHeap<ILits>(),
837                 new MiniSATRestarts());
838         learning.setVarActivityListener(solver);
839         return solver;
840     }
841 
842     /**
843      * @return a SAT solver with learning limited to clauses of length smaller
844      *         or equals to 3, with a specific data structure for binary and
845      *         ternary clauses as found in Lawrence Ryan thesis, without
846      *         restarts, with a Jeroslow/Wang kind of heuristics.
847      */
848     public static Solver<ILits23> newMini3SAT() {
849         LimitedLearning<ILits23> learning = new FixedLengthLearning<ILits23>(3);
850         Solver<ILits23> solver = new Solver<ILits23>(new FirstUIP(), learning,
851                 new MixedDataStructureWithBinaryAndTernary(), new SearchParams(
852                         Integer.MAX_VALUE), new JWOrder(),
853                 new MiniSATRestarts());
854         learning.setSolver(solver);
855         return solver;
856     }
857 
858     /**
859      * @return a Mini3SAT with full learning.
860      * @see #newMini3SAT()
861      */
862     public static Solver<ILits23> newMini3SATb() {
863         MiniSATLearning<ILits23> learning = new MiniSATLearning<ILits23>();
864         Solver<ILits23> solver = new Solver<ILits23>(new FirstUIP(), learning,
865                 new MixedDataStructureWithBinaryAndTernary(), new SearchParams(
866                         Integer.MAX_VALUE), new JWOrder(),
867                 new MiniSATRestarts());
868         learning.setDataStructureFactory(solver.getDSFactory());
869         learning.setVarActivityListener(solver);
870         return solver;
871     }
872 
873     /**
874      * Builds a SAT solver for the MAX sat evaluation. Full clause learning, no
875      * restarts,
876      * 
877      * @return a
878      */
879     public static Solver<ILits> newMiniMaxSAT() {
880         MiniSATLearning<ILits> learning = new MiniSATLearning<ILits>();
881         Solver<ILits> solver = new Solver<ILits>(new FirstUIP(), learning,
882                 new MixedDataStructureDanielCBWL(), new SearchParams(1.2,
883                         100000), new VarOrderHeap<ILits>(),
884                 new MiniSATRestarts());
885         learning.setDataStructureFactory(solver.getDSFactory());
886         learning.setVarActivityListener(solver);
887         return solver;
888     }
889 
890     /**
891      * Default solver of the SolverFactory. This solver is meant to be used on
892      * challenging SAT benchmarks.
893      * 
894      * @return the best "general purpose" SAT solver available in the factory.
895      * @see #defaultSolver() the same method, polymorphic, to be called from an
896      *      instance of ASolverFactory.
897      */
898     public static ISolver newDefault() {
899         return newMiniLearningHeapRsatExpSimpBiere();
900     }
901 
902     @Override
903     public ISolver defaultSolver() {
904         return newDefault();
905     }
906 
907     /**
908      * Small footprint SAT solver.
909      * 
910      * @return a SAT solver suitable for solving small/easy SAT benchmarks.
911      * @see #lightSolver() the same method, polymorphic, to be called from an
912      *      instance of ASolverFactory.
913      */
914     public static ISolver newLight() {
915         return newMini3SAT();
916     }
917 
918     @Override
919     public ISolver lightSolver() {
920         return newLight();
921     }
922 
923     public static ISolver newDimacsOutput() {
924         return new DimacsOutputSolver();
925     }
926 
927 }