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