Search in sources :

Example 1 with SolverContext

use of org.sosy_lab.java_smt.api.SolverContext in project java-smt by sosy-lab.

the class Interpolation method main.

public static void main(String... args) throws InvalidConfigurationException, SolverException, InterruptedException {
    // set up a basic environment
    Configuration config = Configuration.defaultConfiguration();
    LogManager logger = BasicLogManager.create(config);
    ShutdownNotifier notifier = ShutdownNotifier.createDummy();
    // choose solver
    // works for all interpolation strategies
    Solvers solver = Solvers.SMTINTERPOL;
    // setup context
    try (SolverContext context = SolverContextFactory.createSolverContext(config, logger, notifier, solver);
        InterpolatingProverEnvironment<?> prover = context.newProverEnvironmentWithInterpolation()) {
        logger.log(Level.WARNING, "Using solver " + solver + " in version " + context.getVersion());
        IntegerFormulaManager imgr = context.getFormulaManager().getIntegerFormulaManager();
        // example
        prover.push();
        interpolateExample(prover, imgr, logger);
        prover.pop();
        // and another example
        prover.push();
        interpolateProgramTrace(prover, imgr, logger);
        prover.pop();
    } catch (InvalidConfigurationException | UnsatisfiedLinkError e) {
        // on some machines we support only some solvers,
        // thus we can ignore these errors.
        logger.logUserException(Level.INFO, e, "Solver " + solver + " is not available.");
    } catch (UnsupportedOperationException e) {
        logger.logUserException(Level.INFO, e, e.getMessage());
    }
}
Also used : ShutdownNotifier(org.sosy_lab.common.ShutdownNotifier) SolverContext(org.sosy_lab.java_smt.api.SolverContext) Configuration(org.sosy_lab.common.configuration.Configuration) Solvers(org.sosy_lab.java_smt.SolverContextFactory.Solvers) LogManager(org.sosy_lab.common.log.LogManager) BasicLogManager(org.sosy_lab.common.log.BasicLogManager) IntegerFormulaManager(org.sosy_lab.java_smt.api.IntegerFormulaManager) InvalidConfigurationException(org.sosy_lab.common.configuration.InvalidConfigurationException)

Example 2 with SolverContext

use of org.sosy_lab.java_smt.api.SolverContext in project java-smt by sosy-lab.

the class OptimizationFormulaWeights method main.

public static void main(String... args) throws InvalidConfigurationException, SolverException, InterruptedException {
    Configuration config = Configuration.defaultConfiguration();
    LogManager logger = BasicLogManager.create(config);
    ShutdownNotifier notifier = ShutdownNotifier.createDummy();
    // Z3 works for optimization
    Solvers solver = Solvers.Z3;
    try (SolverContext context = SolverContextFactory.createSolverContext(config, logger, notifier, solver);
        OptimizationProverEnvironment prover = context.newOptimizationProverEnvironment(ProverOptions.GENERATE_MODELS)) {
        logger.log(Level.WARNING, "Using solver " + solver + " in version " + context.getVersion());
        BooleanFormulaManager bmgr = context.getFormulaManager().getBooleanFormulaManager();
        IntegerFormulaManager imgr = context.getFormulaManager().getIntegerFormulaManager();
        optimizeWithWeights(prover, bmgr, imgr, logger);
    } catch (InvalidConfigurationException | UnsatisfiedLinkError e) {
        // on some machines we support only some solvers,
        // thus we can ignore these errors.
        logger.logUserException(Level.INFO, e, "Solver " + solver + " is not available.");
    } catch (UnsupportedOperationException e) {
        logger.logUserException(Level.INFO, e, e.getMessage());
    }
}
Also used : ShutdownNotifier(org.sosy_lab.common.ShutdownNotifier) SolverContext(org.sosy_lab.java_smt.api.SolverContext) BooleanFormulaManager(org.sosy_lab.java_smt.api.BooleanFormulaManager) Configuration(org.sosy_lab.common.configuration.Configuration) Solvers(org.sosy_lab.java_smt.SolverContextFactory.Solvers) OptimizationProverEnvironment(org.sosy_lab.java_smt.api.OptimizationProverEnvironment) LogManager(org.sosy_lab.common.log.LogManager) BasicLogManager(org.sosy_lab.common.log.BasicLogManager) IntegerFormulaManager(org.sosy_lab.java_smt.api.IntegerFormulaManager) InvalidConfigurationException(org.sosy_lab.common.configuration.InvalidConfigurationException)

Example 3 with SolverContext

use of org.sosy_lab.java_smt.api.SolverContext in project java-smt by sosy-lab.

the class OptimizationIntReal method optimizeWithRationals.

/**
 * Solve the problem with rational logic.
 */
private static void optimizeWithRationals(Configuration config, LogManager logger, ShutdownNotifier notifier, Solvers solver) throws InterruptedException, SolverException {
    // create solver context
    try (SolverContext context = SolverContextFactory.createSolverContext(config, logger, notifier, solver);
        OptimizationProverEnvironment prover = context.newOptimizationProverEnvironment(ProverOptions.GENERATE_MODELS)) {
        BooleanFormulaManager bmgr = context.getFormulaManager().getBooleanFormulaManager();
        RationalFormulaManager nmgr = context.getFormulaManager().getRationalFormulaManager();
        RationalFormula x = nmgr.makeVariable("x");
        prover.addConstraint(bmgr.and(nmgr.greaterOrEquals(x, nmgr.makeNumber(0)), nmgr.lessThan(x, nmgr.makeNumber(10))));
        logger.log(Level.INFO, "optimizing with rational logic");
        printUpperAndLowerBound(prover, x, logger);
    } catch (InvalidConfigurationException | UnsatisfiedLinkError e) {
        // on some machines we support only some solvers,
        // thus we can ignore these errors.
        logger.logUserException(Level.INFO, e, "Solver " + solver + " is not available.");
    } catch (UnsupportedOperationException e) {
        logger.logUserException(Level.INFO, e, e.getMessage());
    }
}
Also used : SolverContext(org.sosy_lab.java_smt.api.SolverContext) RationalFormula(org.sosy_lab.java_smt.api.NumeralFormula.RationalFormula) BooleanFormulaManager(org.sosy_lab.java_smt.api.BooleanFormulaManager) OptimizationProverEnvironment(org.sosy_lab.java_smt.api.OptimizationProverEnvironment) RationalFormulaManager(org.sosy_lab.java_smt.api.RationalFormulaManager) InvalidConfigurationException(org.sosy_lab.common.configuration.InvalidConfigurationException)

Example 4 with SolverContext

use of org.sosy_lab.java_smt.api.SolverContext in project java-smt by sosy-lab.

the class OptimizationIntReal method optimizeWithIntegers.

/**
 * Solve the problem with integer logic.
 */
private static void optimizeWithIntegers(Configuration config, LogManager logger, ShutdownNotifier notifier, Solvers solver) throws InterruptedException, SolverException {
    // create solver context
    try (SolverContext context = SolverContextFactory.createSolverContext(config, logger, notifier, solver);
        OptimizationProverEnvironment prover = context.newOptimizationProverEnvironment(ProverOptions.GENERATE_MODELS)) {
        logger.log(Level.WARNING, "Using solver " + solver + " in version " + context.getVersion());
        BooleanFormulaManager bmgr = context.getFormulaManager().getBooleanFormulaManager();
        IntegerFormulaManager nmgr = context.getFormulaManager().getIntegerFormulaManager();
        IntegerFormula x = nmgr.makeVariable("x");
        // assert  0 <= x < 10
        prover.addConstraint(bmgr.and(nmgr.greaterOrEquals(x, nmgr.makeNumber(0)), nmgr.lessThan(x, nmgr.makeNumber(10))));
        logger.log(Level.INFO, "optimizing with integer logic");
        printUpperAndLowerBound(prover, x, logger);
    } catch (InvalidConfigurationException | UnsatisfiedLinkError e) {
        // on some machines we support only some solvers,
        // thus we can ignore these errors.
        logger.logUserException(Level.INFO, e, "Solver " + solver + " is not available.");
    } catch (UnsupportedOperationException e) {
        logger.logUserException(Level.INFO, e, e.getMessage());
    }
}
Also used : SolverContext(org.sosy_lab.java_smt.api.SolverContext) BooleanFormulaManager(org.sosy_lab.java_smt.api.BooleanFormulaManager) IntegerFormula(org.sosy_lab.java_smt.api.NumeralFormula.IntegerFormula) OptimizationProverEnvironment(org.sosy_lab.java_smt.api.OptimizationProverEnvironment) IntegerFormulaManager(org.sosy_lab.java_smt.api.IntegerFormulaManager) InvalidConfigurationException(org.sosy_lab.common.configuration.InvalidConfigurationException)

Example 5 with SolverContext

use of org.sosy_lab.java_smt.api.SolverContext in project java-smt by sosy-lab.

the class PrettyPrinter method main.

public static void main(String... args) throws InvalidConfigurationException, SolverException, InterruptedException, IOException {
    if (args.length == 0) {
        help();
    }
    Solvers solver = Solvers.MATHSAT5;
    Type type = Type.TEXT;
    Path path = null;
    for (String arg : args) {
        if (arg.startsWith("-solver=")) {
            solver = Solvers.valueOf(arg.substring(8));
        } else if (arg.startsWith("-type=")) {
            type = Type.valueOf(arg.substring(6).toUpperCase());
        } else if (path == null) {
            path = Path.of(arg);
        } else {
            help();
        }
    }
    if (path == null) {
        help();
    }
    Configuration config = Configuration.defaultConfiguration();
    LogManager logger = BasicLogManager.create(config);
    ShutdownNotifier notifier = ShutdownNotifier.createDummy();
    // we need a solver that supports all theories, at least for parsing.
    try (SolverContext context = SolverContextFactory.createSolverContext(config, logger, notifier, solver)) {
        List<BooleanFormula> formulas = new ArrayList<>();
        // read all formulas from the file
        List<String> definitions = new ArrayList<>();
        for (String line : Files.readAllLines(path)) {
            // we assume a line-based content
            if (Iterables.any(ImmutableList.of(";", "(push ", "(pop ", "(reset", "(set-logic"), line::startsWith)) {
                continue;
            } else if (line.startsWith("(assert ")) {
                BooleanFormula bf = context.getFormulaManager().parse(Joiner.on("").join(definitions) + line);
                formulas.add(bf);
            } else {
                // it is a definition
                definitions.add(line);
            }
        }
        // classify the formulas
        org.sosy_lab.java_smt.utils.PrettyPrinter pp = SolverUtils.prettyPrinter(context.getFormulaManager());
        for (BooleanFormula formula : formulas) {
            System.out.println(formulaToString(formula, pp, type));
        }
    } catch (InvalidConfigurationException | UnsatisfiedLinkError e) {
        // on some machines we support only some solvers,
        // thus we can ignore these errors.
        logger.logUserException(Level.INFO, e, "Solver " + solver + " is not available.");
    } catch (UnsupportedOperationException e) {
        logger.logUserException(Level.INFO, e, e.getMessage());
    }
}
Also used : Path(java.nio.file.Path) ShutdownNotifier(org.sosy_lab.common.ShutdownNotifier) Configuration(org.sosy_lab.common.configuration.Configuration) ArrayList(java.util.ArrayList) InvalidConfigurationException(org.sosy_lab.common.configuration.InvalidConfigurationException) SolverContext(org.sosy_lab.java_smt.api.SolverContext) Solvers(org.sosy_lab.java_smt.SolverContextFactory.Solvers) LogManager(org.sosy_lab.common.log.LogManager) BasicLogManager(org.sosy_lab.common.log.BasicLogManager) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula)

Aggregations

SolverContext (org.sosy_lab.java_smt.api.SolverContext)37 Test (org.junit.Test)16 InvalidConfigurationException (org.sosy_lab.common.configuration.InvalidConfigurationException)15 BooleanFormula (org.sosy_lab.java_smt.api.BooleanFormula)15 BooleanFormulaManager (org.sosy_lab.java_smt.api.BooleanFormulaManager)15 Configuration (org.sosy_lab.common.configuration.Configuration)14 IntegerFormulaManager (org.sosy_lab.java_smt.api.IntegerFormulaManager)10 Event (com.dat3m.dartagnan.program.event.core.Event)8 ProverEnvironment (org.sosy_lab.java_smt.api.ProverEnvironment)8 Program (com.dat3m.dartagnan.program.Program)7 ShutdownNotifier (org.sosy_lab.common.ShutdownNotifier)7 BasicLogManager (org.sosy_lab.common.log.BasicLogManager)7 LogManager (org.sosy_lab.common.log.LogManager)7 FormulaManager (org.sosy_lab.java_smt.api.FormulaManager)7 Thread (com.dat3m.dartagnan.program.Thread)6 Tag (com.dat3m.dartagnan.program.event.Tag)6 VerificationTask (com.dat3m.dartagnan.verification.VerificationTask)6 Tuple (com.dat3m.dartagnan.wmm.utils.Tuple)6 Collectors (java.util.stream.Collectors)6 Solvers (org.sosy_lab.java_smt.SolverContextFactory.Solvers)6