-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathCVC5SolverContext.java
195 lines (166 loc) · 6.84 KB
/
CVC5SolverContext.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
// This file is part of JavaSMT,
// an API wrapper for a collection of SMT solvers:
// https://github.com/sosy-lab/java-smt
//
// SPDX-FileCopyrightText: 2022 Dirk Beyer <https://www.sosy-lab.org>
//
// SPDX-License-Identifier: Apache-2.0
package org.sosy_lab.java_smt.solvers.cvc5;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import io.github.cvc5.Solver;
import java.util.Set;
import java.util.function.Consumer;
import org.sosy_lab.common.ShutdownNotifier;
import org.sosy_lab.common.log.LogManager;
import org.sosy_lab.java_smt.SolverContextFactory.Solvers;
import org.sosy_lab.java_smt.api.FloatingPointRoundingMode;
import org.sosy_lab.java_smt.api.InterpolatingProverEnvironment;
import org.sosy_lab.java_smt.api.OptimizationProverEnvironment;
import org.sosy_lab.java_smt.api.ProverEnvironment;
import org.sosy_lab.java_smt.api.SolverContext;
import org.sosy_lab.java_smt.basicimpl.AbstractNumeralFormulaManager.NonLinearArithmetic;
import org.sosy_lab.java_smt.basicimpl.AbstractSolverContext;
public final class CVC5SolverContext extends AbstractSolverContext {
// creator is final, except after closing, then null.
private CVC5FormulaCreator creator;
private final Solver solver;
private final ShutdownNotifier shutdownNotifier;
private final int randomSeed;
private boolean closed = false;
private CVC5SolverContext(
CVC5FormulaCreator pCreator,
CVC5FormulaManager manager,
ShutdownNotifier pShutdownNotifier,
Solver pSolver,
int pRandomSeed) {
super(manager);
creator = pCreator;
shutdownNotifier = pShutdownNotifier;
randomSeed = pRandomSeed;
solver = pSolver;
}
@VisibleForTesting
static void loadLibrary(Consumer<String> pLoader) {
pLoader.accept("cvc5jni");
// disable CVC5's own loading mechanism,
// see io.github.cvc5.Util#loadLibraries and https://github.com/cvc5/cvc5/pull/9047
System.setProperty("cvc5.skipLibraryLoad", "true");
}
@SuppressWarnings({"unused", "resource"})
public static SolverContext create(
LogManager pLogger,
ShutdownNotifier pShutdownNotifier,
int randomSeed,
NonLinearArithmetic pNonLinearArithmetic,
FloatingPointRoundingMode pFloatingPointRoundingMode,
Consumer<String> pLoader) {
loadLibrary(pLoader);
// This Solver is the central class for creating expressions/terms/formulae.
// We keep this instance available until the whole context is closed.
Solver newSolver = new Solver();
setSolverOptions(newSolver, randomSeed);
CVC5FormulaCreator pCreator = new CVC5FormulaCreator(newSolver);
// Create managers
CVC5UFManager functionTheory = new CVC5UFManager(pCreator);
CVC5BooleanFormulaManager booleanTheory = new CVC5BooleanFormulaManager(pCreator);
CVC5IntegerFormulaManager integerTheory =
new CVC5IntegerFormulaManager(pCreator, pNonLinearArithmetic);
CVC5RationalFormulaManager rationalTheory =
new CVC5RationalFormulaManager(pCreator, pNonLinearArithmetic);
CVC5BitvectorFormulaManager bitvectorTheory =
new CVC5BitvectorFormulaManager(pCreator, booleanTheory);
CVC5FloatingPointFormulaManager fpTheory =
new CVC5FloatingPointFormulaManager(pCreator, pFloatingPointRoundingMode);
CVC5QuantifiedFormulaManager qfTheory = new CVC5QuantifiedFormulaManager(pCreator);
CVC5ArrayFormulaManager arrayTheory = new CVC5ArrayFormulaManager(pCreator);
CVC5SLFormulaManager slTheory = new CVC5SLFormulaManager(pCreator);
CVC5StringFormulaManager strTheory = new CVC5StringFormulaManager(pCreator);
CVC5EnumerationFormulaManager enumTheory = new CVC5EnumerationFormulaManager(pCreator);
CVC5FormulaManager manager =
new CVC5FormulaManager(
pCreator,
functionTheory,
booleanTheory,
integerTheory,
rationalTheory,
bitvectorTheory,
fpTheory,
qfTheory,
arrayTheory,
slTheory,
strTheory,
enumTheory);
return new CVC5SolverContext(pCreator, manager, pShutdownNotifier, newSolver, randomSeed);
}
/** Set common options for a CVC5 solver. */
private static void setSolverOptions(Solver pSolver, int randomSeed) {
pSolver.setOption("seed", String.valueOf(randomSeed));
pSolver.setOption("output-language", "smtlib2");
// Set Strings option to enable all String features (such as lessOrEquals).
// This should not have any effect for non-string theories.
// pSolver.setOption("strings-exp", "true");
// pSolver.setOption("finite-model-find", "true");
// pSolver.setOption("sets-ext", "true");
// pSolver.setOption("produce-models", "true");
// pSolver.setOption("produce-unsat-cores", "true");
// Neither simplification, arith-rewrite-equalities, pb-rewrites provide rewrites of trivial
// formulas only.
// Note: with solver.getOptionNames() you can get all options
}
@Override
public String getVersion() {
String version = solver.getInfo("version");
if (version.startsWith("\"") && version.endsWith("\"")) {
version = version.substring(1, version.length() - 1);
}
return "CVC5 " + version;
}
@Override
public void close() {
if (creator != null) {
closed = true;
creator = null;
}
}
@Override
public Solvers getSolverName() {
return Solvers.CVC5;
}
@Override
public ProverEnvironment newProverEnvironment0(Set<ProverOptions> pOptions) {
Preconditions.checkState(!closed, "solver context is already closed");
return new CVC5TheoremProver(
creator, shutdownNotifier, randomSeed, pOptions, getFormulaManager());
}
@Override
protected ProverEnvironment copyProverEnvironment0(ProverEnvironment proverToCopy) {
throw new UnsupportedOperationException(
"CVC5 does not support the copying of ProverEnvironments");
}
@Override
protected boolean supportsAssumptionSolving() {
return false;
}
@Override
protected InterpolatingProverEnvironment<?> newProverEnvironmentWithInterpolation0(
Set<ProverOptions> pOptions) {
throw new UnsupportedOperationException("CVC5 does not support Craig interpolation.");
}
@Override
protected InterpolatingProverEnvironment<?> copyProverEnvironmentWithInterpolation0(
InterpolatingProverEnvironment<?> proverToCopy) {
throw new UnsupportedOperationException(
"CVC5 does not support the copying of ProverEnvironments");
}
@Override
protected OptimizationProverEnvironment newOptimizationProverEnvironment0(
Set<ProverOptions> pSet) {
throw new UnsupportedOperationException("CVC5 does not support optimization");
}
@Override
public OptimizationProverEnvironment copyOptimizationProverEnvironment(
OptimizationProverEnvironment proverToCopy) {
throw new UnsupportedOperationException("CVC5 does not support optimization");
}
}