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