1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.sat4j.csp;
20
21 import org.sat4j.core.ASolverFactory;
22 import org.sat4j.minisat.constraints.MixedDataStructureDaniel;
23 import org.sat4j.minisat.constraints.MixedDataStructureWithBinary;
24 import org.sat4j.minisat.core.DataStructureFactory;
25 import org.sat4j.minisat.core.ILits;
26 import org.sat4j.minisat.core.Solver;
27 import org.sat4j.minisat.learning.MiniSATLearning;
28 import org.sat4j.minisat.orders.VarOrderHeap;
29 import org.sat4j.minisat.restarts.MiniSATRestarts;
30 import org.sat4j.minisat.uip.FirstUIP;
31 import org.sat4j.specs.ISolver;
32 import org.sat4j.tools.DimacsOutputSolver;
33
34
35
36
37
38
39 public class SolverFactory extends ASolverFactory<ISolver> {
40
41
42
43
44 private static final long serialVersionUID = 1L;
45
46
47 private static SolverFactory instance;
48
49
50
51
52
53
54 private SolverFactory() {
55 super();
56 }
57
58 private static synchronized void createInstance() {
59 if (instance == null) {
60 instance = new SolverFactory();
61 }
62 }
63
64
65
66
67
68
69 public static SolverFactory instance() {
70 if (instance == null) {
71 createInstance();
72 }
73 return instance;
74 }
75
76
77
78
79
80
81 public static <L extends ILits> Solver<L,DataStructureFactory<L>> newMiniSAT(
82 DataStructureFactory<L> dsf) {
83 MiniSATLearning<L,DataStructureFactory<L>> learning = new MiniSATLearning<L,DataStructureFactory<L>>();
84 Solver<L,DataStructureFactory<L>> solver = new Solver<L,DataStructureFactory<L>>(new FirstUIP(), learning, dsf,
85 new VarOrderHeap<L>(), new MiniSATRestarts());
86 learning.setDataStructureFactory(solver.getDSFactory());
87 learning.setVarActivityListener(solver);
88 return solver;
89 }
90
91
92
93
94
95
96
97
98
99
100
101 public static ISolver newDefault() {
102 Solver<ILits,DataStructureFactory<ILits>> solver = newMiniSAT(new MixedDataStructureDaniel());
103 solver.setSimplifier(solver.EXPENSIVE_SIMPLIFICATION);
104 return solver;
105 }
106
107 @Override
108 public ISolver defaultSolver() {
109 return newDefault();
110 }
111
112
113
114
115
116
117
118
119 public static ISolver newLight() {
120 return newMiniSAT(new MixedDataStructureWithBinary());
121 }
122
123 @Override
124 public ISolver lightSolver() {
125 return newLight();
126 }
127
128 public static ISolver newDimacsOutput() {
129 return new DimacsOutputSolver();
130 }
131
132 }