-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathSolverContext.java
More file actions
202 lines (182 loc) · 9.9 KB
/
SolverContext.java
File metadata and controls
202 lines (182 loc) · 9.9 KB
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
196
197
198
199
200
201
202
// This file is part of JavaSMT,
// an API wrapper for a collection of SMT solvers:
// https://github.com/sosy-lab/java-smt
//
// SPDX-FileCopyrightText: 2020 Dirk Beyer <https://www.sosy-lab.org>
//
// SPDX-License-Identifier: Apache-2.0
package org.sosy_lab.java_smt.api;
import com.google.common.collect.ImmutableMap;
import org.sosy_lab.common.ShutdownNotifier;
import org.sosy_lab.java_smt.SolverContextFactory.Solvers;
/**
* Instances of this interface provide access to an SMT solver. A single SolverContext should be
* used only from a single thread.
*
* <p>If you wish to use multiple contexts (even for the same solver), create one SolverContext per
* each. Formulas can be transferred between different contexts using {@link
* FormulaManager#translateFrom(BooleanFormula, FormulaManager)}.
*/
public interface SolverContext extends AutoCloseable {
/** Get the formula manager, which is used for formula manipulation. */
FormulaManager getFormulaManager();
/** Options for the prover environment. */
enum ProverOptions {
/**
* Whether the solver should generate models (i.e., satisfying assignments) for satisfiable
* formulas.
*/
GENERATE_MODELS,
/**
* Whether the solver should allow to query all satisfying assignments for satisfiable formulas.
*/
GENERATE_ALL_SAT,
/**
* Whether the solver should generate an unsat core for unsatisfiable formulas. Unsat core is
* generated over all formulas asserted with {@link
* ProverEnvironment#addConstraint(BooleanFormula)} or {@link
* ProverEnvironment#push(BooleanFormula)}.
*/
GENERATE_UNSAT_CORE,
/**
* Whether the solver should generate an unsat core for unsatisfiable formulas <b>only</b> over
* the assumptions explicitly passed to the solver.
*/
GENERATE_UNSAT_CORE_OVER_ASSUMPTIONS,
/** Whether the solver should enable support for formulae build in SL theory. */
ENABLE_SEPARATION_LOGIC
}
/**
* Create a fresh new {@link ProverEnvironment} which encapsulates an assertion stack and can be
* used to check formulas for unsatisfiability.
*
* @param options Options specified for the prover environment. All the options specified in
* {@link ProverOptions} are turned off by default.
*/
ProverEnvironment newProverEnvironment(ProverOptions... options);
/**
* Create a fresh new {@link ProverEnvironment} which encapsulates an assertion stack and can be
* used to check formulas for unsatisfiability. Allows the shutdown of the prover instance
* returned with the given {@link ShutdownNotifier}, without stopping other provers of the context
* calling this (except for provers also connected via the given {@link ShutdownNotifier}).
*
* @param pProverShutdownNotifier a {@link ShutdownNotifier} that stops the prover returned by
* this method. The prover is not usable anymore after a shutdown has been requested and only
* ever returns {@link InterruptedException}s. The context can be used normally and new
* provers can be created and used. If a {@link ShutdownNotifier} has been given to the
* context that is used to call this method, both notifiers can be used to stop the prover
* returned by this method. Note that once a shutdown-request has been given to the contexts
* {@link ShutdownNotifier}, no prover can ever be used again on that context instance.
* Solvers that don't support isolated prover shutdown throw a {@link
* UnsupportedOperationException} for this method and {@link
* #newProverEnvironment(ProverOptions...)} should be used instead.
* @param options Options specified for the prover environment. All the options specified in
* {@link ProverOptions} are turned off by default.
*/
ProverEnvironment newProverEnvironment(
ShutdownNotifier pProverShutdownNotifier, ProverOptions... options);
/**
* Create a fresh new {@link InterpolatingProverEnvironment} which encapsulates an assertion stack
* and allows generating and retrieve interpolants for unsatisfiable formulas. If the SMT solver
* is able to handle satisfiability tests with assumptions please consider implementing the {@link
* InterpolatingProverEnvironment} interface, and return an Object of this type here.
*
* @param options Options specified for the prover environment. All the options specified in
* {@link ProverOptions} are turned off by default.
*/
InterpolatingProverEnvironment<?> newProverEnvironmentWithInterpolation(ProverOptions... options);
/**
* Create a fresh new {@link InterpolatingProverEnvironment} which encapsulates an assertion stack
* and allows generating and retrieve interpolants for unsatisfiable formulas. If the SMT solver
* is able to handle satisfiability tests with assumptions please consider implementing the {@link
* InterpolatingProverEnvironment} interface, and return an Object of this type here. Allows the
* shutdown of the prover instance returned with the given {@link ShutdownNotifier}, without
* stopping other provers of the context calling this (except for provers also connected via the
* given {@link ShutdownNotifier}).
*
* @param pProverShutdownNotifier a {@link ShutdownNotifier} that stops the prover returned by
* this method. The prover is not usable anymore after a shutdown has been requested and only
* ever returns {@link InterruptedException}s. The context can be used normally and new
* provers can be created and used. If a {@link ShutdownNotifier} has been given to the
* context that is used to call this method, both notifiers can be used to stop the prover
* returned by this method. Note that once a shutdown-request has been given to the contexts
* {@link ShutdownNotifier}, no prover can ever be used again on that context instance.
* Solvers that don't support isolated prover shutdown throw a {@link
* UnsupportedOperationException} for this method and {@link
* #newProverEnvironment(ProverOptions...)} should be used instead.
* @param options Options specified for the prover environment. All the options specified in
* {@link ProverOptions} are turned off by default.
*/
InterpolatingProverEnvironment<?> newProverEnvironmentWithInterpolation(
ShutdownNotifier pProverShutdownNotifier, ProverOptions... options);
/**
* Create a fresh new {@link OptimizationProverEnvironment} which encapsulates an assertion stack
* and allows solving optimization queries.
*
* @param options Options specified for the prover environment. All the options specified in
* {@link ProverOptions} are turned off by default.
*/
OptimizationProverEnvironment newOptimizationProverEnvironment(ProverOptions... options);
/**
* Create a fresh new {@link OptimizationProverEnvironment} which encapsulates an assertion stack
* and allows solving optimization queries. Allows the shutdown of the prover instance returned
* with the given {@link ShutdownNotifier}, without stopping other provers of the context calling
* this (except for provers also connected via the given {@link ShutdownNotifier}).
*
* @param pProverShutdownNotifier a {@link ShutdownNotifier} that stops the prover returned by
* this method. The prover is not usable anymore after a shutdown has been requested and only
* ever returns {@link InterruptedException}s. The context can be used normally and new
* provers can be created and used. If a {@link ShutdownNotifier} has been given to the
* context that is used to call this method, both notifiers can be used to stop the prover
* returned by this method. Note that once a shutdown-request has been given to the contexts
* {@link ShutdownNotifier}, no prover can ever be used again on that context instance.
* Solvers that don't support isolated prover shutdown throw a {@link
* UnsupportedOperationException} for this method and {@link
* #newProverEnvironment(ProverOptions...)} should be used instead.
* @param options Options specified for the prover environment. All the options specified in
* {@link ProverOptions} are turned off by default.
*/
OptimizationProverEnvironment newOptimizationProverEnvironment(
ShutdownNotifier pProverShutdownNotifier, ProverOptions... options);
/**
* Get version information out of the solver.
*
* <p>In most cases, the version contains the name of the solver followed by some numbers and
* additional info about the version, e.g., "SMTInterpol 2.5-12-g3d15a15c".
*/
String getVersion();
/**
* Get solver name (MATHSAT5/Z3/etc...).
*
* <p>This is an uppercase String matching the enum identifier from {@link Solvers}
*/
Solvers getSolverName();
/**
* Get statistics for a complete solver context. The returned mapping is intended to provide the
* solver-internal statistics. The keys can differ between individual solvers.
*
* <p>Calling the statistics several times for the same context returns accumulated number, i.e.,
* we currently do not provide any possibility to reset the statistics.
*
* <p>We do not guarantee any specific key to be present, as this depends on the used solver. We
* might even return an empty mapping if the solver does not support calling this method or is in
* an invalid state.
*
* @see ProverEnvironment#getStatistics()
*/
default ImmutableMap<String, String> getStatistics() {
return ImmutableMap.of();
}
/**
* Close the solver context.
*
* <p>After calling this method, further access to any object that had been returned from this
* context is not wanted, i.e., it depends on the solver. Java-based solvers might wait for the
* next garbage collection with any cleanup operation. Native solvers might even reference invalid
* memory and cause segmentation faults.
*
* <p>Necessary for the solvers implemented in native code, frees the associated memory.
*/
@Override
void close();
}