-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathBasicProverWithAssumptionsWrapper.java
More file actions
137 lines (115 loc) · 3.67 KB
/
BasicProverWithAssumptionsWrapper.java
File metadata and controls
137 lines (115 loc) · 3.67 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
// 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.basicimpl.withAssumptionsWrapper;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import org.sosy_lab.java_smt.api.BasicProverEnvironment;
import org.sosy_lab.java_smt.api.BooleanFormula;
import org.sosy_lab.java_smt.api.Model;
import org.sosy_lab.java_smt.api.SolverException;
import org.sosy_lab.java_smt.api.proofs.Proof;
public class BasicProverWithAssumptionsWrapper<T, P extends BasicProverEnvironment<T>>
implements BasicProverEnvironment<T> {
protected final P delegate;
protected final List<BooleanFormula> solverAssumptionsAsFormula = new ArrayList<>();
BasicProverWithAssumptionsWrapper(P pDelegate) {
delegate = pDelegate;
}
protected void clearAssumptions() {
for (int i = 0; i < solverAssumptionsAsFormula.size(); i++) {
delegate.pop();
}
solverAssumptionsAsFormula.clear();
}
@Override
public void pop() {
clearAssumptions();
delegate.pop();
}
@Override
public T addConstraint(BooleanFormula constraint) throws InterruptedException {
clearAssumptions();
return delegate.addConstraint(constraint);
}
@Override
public void push() throws InterruptedException {
clearAssumptions();
delegate.push();
}
@Override
public int size() {
return delegate.size();
}
@Override
public boolean isUnsat() throws SolverException, InterruptedException {
clearAssumptions();
return delegate.isUnsat();
}
@Override
public boolean isUnsatWithAssumptions(Collection<BooleanFormula> assumptions)
throws SolverException, InterruptedException {
clearAssumptions();
solverAssumptionsAsFormula.addAll(assumptions);
for (BooleanFormula formula : assumptions) {
registerPushedFormula(delegate.push(formula));
}
return delegate.isUnsat();
}
/** overridden in subclass. */
protected void registerPushedFormula(@SuppressWarnings("unused") T pPushResult) {}
@Override
public Model getModel() throws SolverException {
return delegate.getModel();
}
@Override
public ImmutableList<Model.ValueAssignment> getModelAssignments() throws SolverException {
return delegate.getModelAssignments();
}
@Override
public List<BooleanFormula> getUnsatCore() {
return delegate.getUnsatCore();
}
@Override
public Optional<List<BooleanFormula>> unsatCoreOverAssumptions(
Collection<BooleanFormula> pAssumptions) throws SolverException, InterruptedException {
clearAssumptions();
return delegate.unsatCoreOverAssumptions(pAssumptions);
// if (isUnsatWithAssumptions(pAssumptions)) {
// // TODO project to pAssumptions?
// return Optional.of(getUnsatCore());
// } else {
// return Optional.empty();
// }
}
@Override
public ImmutableMap<String, String> getStatistics() {
return delegate.getStatistics();
}
@Override
public void close() {
delegate.close();
}
@Override
public String toString() {
return delegate.toString();
}
@Override
public <R> R allSat(AllSatCallback<R> pCallback, List<BooleanFormula> pImportant)
throws InterruptedException, SolverException {
clearAssumptions();
return delegate.allSat(pCallback, pImportant);
}
@Override
public Proof getProof() throws SolverException, InterruptedException {
return delegate.getProof();
}
}