-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathLoggingSmtInterpolInterpolatingProver.java
More file actions
142 lines (127 loc) · 4.59 KB
/
Copy pathLoggingSmtInterpolInterpolatingProver.java
File metadata and controls
142 lines (127 loc) · 4.59 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
// 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.solvers.smtinterpol;
import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
import de.uni_freiburg.informatik.ultimate.logic.Script;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.charset.Charset;
import java.nio.file.Path;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Collection;
import java.util.Deque;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.sosy_lab.common.ShutdownNotifier;
import org.sosy_lab.common.io.IO;
import org.sosy_lab.java_smt.api.BooleanFormula;
import org.sosy_lab.java_smt.api.SolverContext.ProverOptions;
import org.sosy_lab.java_smt.api.SolverException;
// reason: not maintained, some implementations for methods are missing
class LoggingSmtInterpolInterpolatingProver extends SmtInterpolInterpolatingProver {
private final PrintWriter out;
LoggingSmtInterpolInterpolatingProver(
SmtInterpolFormulaManager pMgr,
Script pScript,
Set<ProverOptions> pOptions,
ShutdownNotifier pShutdownNotifier,
Map<String, Object> pGlobalOptions,
Path pLogfile) {
super(pMgr, pScript, pOptions, pShutdownNotifier);
try {
out = initializeLoggerForInterpolation(pGlobalOptions, pLogfile);
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
private PrintWriter initializeLoggerForInterpolation(
Map<String, Object> globalOptions, Path logfile) throws IOException {
@SuppressWarnings("IllegalInstantiation")
PrintWriter writer = new PrintWriter(IO.openOutputFile(logfile, Charset.defaultCharset()));
for (Map.Entry<String, Object> entry : globalOptions.entrySet()) {
writer.println("(set-option %s %s)".formatted(entry.getKey(), entry.getValue()));
}
writer.println("(set-logic " + env.getTheory().getLogic().name() + ")");
return writer;
}
@Override
protected void pushImpl() {
out.println("(push 1)");
}
@Override
protected void popImpl() {
out.println("(pop 1)");
}
@Override
protected String addConstraintImpl(BooleanFormula f) throws InterruptedException {
String result = super.addConstraintImpl(f);
out.println("(assert (! " + f + " :named " + result + "))");
return result;
}
@Override
public List<BooleanFormula> getUnsatCore() {
out.println("(get-unsat-core)");
return super.getUnsatCore();
}
@Override
public <R> R allSat(AllSatCallback<R> callback, List<BooleanFormula> predicates)
throws InterruptedException, SolverException {
out.println("(all-sat (" + Joiner.on(", ").join(predicates) + "))");
return super.allSat(callback, predicates);
}
@Override
protected boolean isUnsatImpl() throws InterruptedException, SolverException {
out.print("(check-sat)");
boolean isUnsat = super.isUnsatImpl();
out.println(" ; " + (isUnsat ? "UNSAT" : "SAT"));
return isUnsat;
}
@Override
public List<BooleanFormula> getTreeInterpolants(
List<? extends Collection<String>> partitionedTermNames, int[] startOfSubTree)
throws SolverException, InterruptedException {
Preconditions.checkArgument(partitionedTermNames.size() == startOfSubTree.length);
out.print("(get-interpolants");
Deque<Integer> subtrees = new ArrayDeque<>();
for (int i = 0; i < startOfSubTree.length; i++) {
final Collection<String> names = partitionedTermNames.get(i);
final int currentStartOfSubtree = startOfSubTree[i];
final String currentTerms;
if (names.size() == 1) {
currentTerms = names.iterator().next();
} else {
currentTerms = "(and " + Joiner.on(" ").join(names) + ")";
}
while (!subtrees.isEmpty() && subtrees.peek() > currentStartOfSubtree) {
subtrees.pop();
out.print(")");
}
out.print(" ");
if (!subtrees.isEmpty() && subtrees.peek() < currentStartOfSubtree) {
subtrees.push(currentStartOfSubtree);
out.print("(");
}
if (subtrees.isEmpty()) {
subtrees.push(currentStartOfSubtree);
}
out.print(currentTerms);
}
out.print(") ; subtrees=" + Arrays.toString(startOfSubTree));
List<BooleanFormula> result = super.getTreeInterpolants(partitionedTermNames, startOfSubTree);
out.println(" ; interpolants=" + result);
return result;
}
@Override
public void close() {
out.close();
super.close();
}
}