-
Notifications
You must be signed in to change notification settings - Fork 56
Handle model generation api through implementation delegates #673
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
baierd
merged 10 commits into
master
from
handle_model_generation_api_through_impl_delegates
Jun 12, 2026
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c794274
Add common API in AbstractProver to check inheritors for closed status
baierd 4a2e807
Add new OptimizationProverDelegate that handled common checks of Opti…
baierd d3c7a74
Remove common checks from Optimization Provers of Z3 and Mathsat
baierd 0886c38
Add implementations for getModel() and getEvaluator() in AbstractProv…
baierd bfb7f23
Reduce visibility of getModelImpl() and getEvaluatorImpl() as they sh…
baierd 1075a97
Remove another redundant usage of checkGenerateModels() from MathSAT
baierd 3928243
Add type check for delegate in OptimizationProverDelegate
baierd faeb24f
Add type check for delegate in InterpolatingProverDelegate
baierd 7527299
Merge branch 'master' into add_common_optimizationProver_delegate2
baierd 181128a
Merge branch 'add_common_optimizationProver_delegate2' into handle_mo…
baierd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
src/org/sosy_lab/java_smt/basicimpl/OptimizationProverDelegate.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| /* | ||
| * This file is part of JavaSMT, | ||
| * an API wrapper for a collection of SMT solvers: | ||
| * https://github.com/sosy-lab/java-smt | ||
| * | ||
| * SPDX-FileCopyrightText: 2026 Dirk Beyer <https://www.sosy-lab.org> | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package org.sosy_lab.java_smt.basicimpl; | ||
|
|
||
| import static com.google.common.base.Preconditions.checkArgument; | ||
| import static com.google.common.base.Preconditions.checkNotNull; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.List; | ||
| import java.util.Optional; | ||
| import org.checkerframework.checker.nullness.qual.Nullable; | ||
| import org.sosy_lab.common.rationals.Rational; | ||
| import org.sosy_lab.java_smt.api.BooleanFormula; | ||
| import org.sosy_lab.java_smt.api.Formula; | ||
| import org.sosy_lab.java_smt.api.Model; | ||
| import org.sosy_lab.java_smt.api.OptimizationProverEnvironment; | ||
| import org.sosy_lab.java_smt.api.SolverException; | ||
|
|
||
| /** | ||
| * This delegate enables common implementations for methods in {@link OptimizationProverEnvironment} | ||
| * based on the implementations in the abstract/theorem prover that can not be done using abstract | ||
| * implementations. | ||
| */ | ||
| public class OptimizationProverDelegate implements OptimizationProverEnvironment { | ||
|
|
||
| private final OptimizationProverEnvironment optimizationProver; | ||
|
|
||
| OptimizationProverDelegate(OptimizationProverEnvironment pBaseProver) { | ||
| checkArgument(pBaseProver instanceof AbstractProver<?>); | ||
| optimizationProver = checkNotNull(pBaseProver); | ||
| } | ||
|
|
||
| @SuppressWarnings("resource") | ||
| @Override | ||
| public int maximize(Formula objective) { | ||
| getDelegateAsAbstractProver().checkClosed(); | ||
| return optimizationProver.maximize(objective); | ||
| } | ||
|
|
||
| @SuppressWarnings("resource") | ||
| @Override | ||
| public int minimize(Formula objective) { | ||
| getDelegateAsAbstractProver().checkClosed(); | ||
| return optimizationProver.minimize(objective); | ||
| } | ||
|
|
||
| @SuppressWarnings("resource") | ||
| @Override | ||
| public Optional<Rational> upper(int handle, Rational epsilon) { | ||
| getDelegateAsAbstractProver().checkGenerateModels(); | ||
| return optimizationProver.upper(handle, epsilon); | ||
| } | ||
|
|
||
| @SuppressWarnings("resource") | ||
| @Override | ||
| public Optional<Rational> lower(int handle, Rational epsilon) { | ||
| getDelegateAsAbstractProver().checkGenerateModels(); | ||
| return optimizationProver.lower(handle, epsilon); | ||
| } | ||
|
|
||
| @Override | ||
| public OptStatus check() throws InterruptedException, SolverException { | ||
| // We don't need to do anything for check, as it is already handled in AbstractProver | ||
| return optimizationProver.check(); | ||
| } | ||
|
|
||
| /* ########################## Delegate methods of ProverEnvironment ########################## */ | ||
|
|
||
| @SuppressWarnings("resource") | ||
| @Override | ||
| public Model getModel() throws SolverException { | ||
| return optimizationProver.getModel(); | ||
| } | ||
|
|
||
| @Override | ||
| public void pop() { | ||
| optimizationProver.pop(); | ||
| } | ||
|
|
||
| @Override | ||
| public @Nullable Void addConstraint(BooleanFormula constraint) throws InterruptedException { | ||
| return optimizationProver.addConstraint(constraint); | ||
| } | ||
|
|
||
| @Override | ||
| public void push() throws InterruptedException { | ||
| optimizationProver.push(); | ||
| } | ||
|
|
||
| @Override | ||
| public int size() { | ||
| return optimizationProver.size(); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isUnsat() throws SolverException, InterruptedException { | ||
| return optimizationProver.isUnsat(); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isUnsatWithAssumptions(Collection<BooleanFormula> assumptions) | ||
| throws SolverException, InterruptedException { | ||
| return optimizationProver.isUnsatWithAssumptions(assumptions); | ||
| } | ||
|
|
||
| @Override | ||
| public List<BooleanFormula> getUnsatCore() { | ||
| return optimizationProver.getUnsatCore(); | ||
| } | ||
|
|
||
| @Override | ||
| public Optional<List<BooleanFormula>> unsatCoreOverAssumptions( | ||
| Collection<BooleanFormula> assumptions) throws SolverException, InterruptedException { | ||
| return optimizationProver.unsatCoreOverAssumptions(assumptions); | ||
| } | ||
|
|
||
| @Override | ||
| public void close() { | ||
| optimizationProver.close(); | ||
| } | ||
|
|
||
| @Override | ||
| public <R> R allSat(AllSatCallback<R> callback, List<BooleanFormula> important) | ||
| throws InterruptedException, SolverException { | ||
| return optimizationProver.allSat(callback, important); | ||
| } | ||
|
|
||
| /* ############################### Utility methods ############################### */ | ||
| @SuppressWarnings("unchecked") | ||
| private AbstractProver<?> getDelegateAsAbstractProver() { | ||
| return (AbstractProver<?>) optimizationProver; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.