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