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 public static ISolver newSAT() {
106 return org.sat4j.pb.SolverFactory.newSAT();
107 }
108
109 public static ISolver newUNSAT() {
110 return org.sat4j.pb.SolverFactory.newUNSAT();
111 }
112
113 public static ISolver newCuttingPlanes() {
114 return org.sat4j.pb.SolverFactory.newCuttingPlanes();
115 }
116
117 @Override
118 public ISolver defaultSolver() {
119 return newDefault();
120 }
121
122
123
124
125
126
127
128
129 public static ISolver newLight() {
130 return newMiniSAT(new MixedDataStructureDanielWL());
131 }
132
133 @Override
134 public ISolver lightSolver() {
135 return newLight();
136 }
137
138 public static ISolver newDimacsOutput() {
139 return new DimacsOutputSolver();
140 }
141
142 }