Search in sources :

Example 1 with SATAbortedException

use of kodkod.engine.satlab.SATAbortedException in project org.alloytools.alloy by AlloyTools.

the class HOLSolver method solve.

/**
 * Adds the specified formula and bounds to the solver's state, modifies the
 * current solution to reflect the updated state (if needed), and returns this
 * solver. This solver should not be used again if a call to this method results
 * in an exception.
 *
 * @requires this.{@link #usable() usable}()
 * @requires f.*components & Relation in (this.bounds + b).relations
 * @requires some this.bounds => this.bounds.universe = b.universe && no
 *           b.intBound && no (this.bounds.relations & b.relations)
 * @requires some this.bounds => all s:
 *           {@link SymmetryDetector#partition(Bounds) partition}(this.bounds) |
 *           some p: {@link SymmetryDetector#partition(Bounds) partition}(b) |
 *           s.elements in p.elements
 * @ensures this.formulas' = this.formulas + f
 * @ensures some this.bounds => (this.bounds.relations' = this.bounds.relations
 *          + b.relations && this.bounds.upperBound' = this.bounds.upperBound +
 *          b.upperBound && this.bounds.lowerBound' = this.bounds.lowerBound +
 *          b.lowerBound) else (this.bounds' = bounds)
 * @return some sol: Solution | sol.instance() = null => UNSAT(this.formulas',
 *         this.bounds', this.options) else sol.instance() in
 *         MODELS(Formula.and(this.formulas'), this.bounds', this.options)
 * @throws IllegalStateException a prior call returned an UNSAT solution or
 *             resulted in an exception
 * @throws NullPointerException any of the arguments are null
 * @throws UnboundLeafException the formula refers to an undeclared variable or
 *             a relation not mapped by this.bounds + b
 * @throws HigherOrderDeclException the formula contains a higher order
 *             declaration
 * @throws IllegalArgumentException any of the remaining preconditions on
 *             {@code f} and {@code b} are violated
 * @throws AbortedException this solving task has been aborted
 */
@Override
public Solution solve(Formula f, Bounds b) throws HigherOrderDeclException, UnboundLeafException, AbortedException {
    if (outcome == Boolean.FALSE)
        throw new IllegalStateException("Cannot use this solver since a prior call to solve(...) produced an UNSAT solution.");
    if (outcome != null && translation == null)
        throw new IllegalStateException("Cannot use this solver since a prior call to solve(...) resulted in an exception.");
    try {
        final long startProcTransl = System.currentTimeMillis();
        Proc proc = Translator.translate2proc(f, b, options);
        final long endProcTransl = System.currentTimeMillis();
        final long startTransl = System.currentTimeMillis();
        translation = HOLTranslator.proc2transl(proc, options);
        final long endTransl = System.currentTimeMillis();
        return toSolution(endProcTransl - startProcTransl, endTransl - startTransl, translation);
    } catch (SATAbortedException sae) {
        free();
        throw new AbortedException(sae);
    } catch (RuntimeException e) {
        free();
        throw e;
    }
}
Also used : Proc(kodkod.engine.hol.Proc) SATAbortedException(kodkod.engine.satlab.SATAbortedException) SATAbortedException(kodkod.engine.satlab.SATAbortedException)

Example 2 with SATAbortedException

use of kodkod.engine.satlab.SATAbortedException in project org.alloytools.alloy by AlloyTools.

the class IncrementalSolver method solve.

/**
 * Adds the specified formula and bounds to the solver's state, modifies the
 * current solution to reflect the updated state (if needed), and returns this
 * solver. This solver should not be used again if a call to this method results
 * in an exception.
 *
 * @requires this.{@link #usable() usable}()
 * @requires f.*components & Relation in (this.bounds + b).relations
 * @requires some this.bounds => this.bounds.universe = b.universe && no
 *           b.intBound && no (this.bounds.relations & b.relations)
 * @requires some this.bounds => all s:
 *           {@link SymmetryDetector#partition(Bounds) partition}(this.bounds) |
 *           some p: {@link SymmetryDetector#partition(Bounds) partition}(b) |
 *           s.elements in p.elements
 * @ensures this.formulas' = this.formulas + f
 * @ensures some this.bounds => (this.bounds.relations' = this.bounds.relations
 *          + b.relations && this.bounds.upperBound' = this.bounds.upperBound +
 *          b.upperBound && this.bounds.lowerBound' = this.bounds.lowerBound +
 *          b.lowerBound) else (this.bounds' = bounds)
 * @return some sol: Solution | sol.instance() = null => UNSAT(this.formulas',
 *         this.bounds', this.options) else sol.instance() in
 *         MODELS(Formula.and(this.formulas'), this.bounds', this.options)
 * @throws IllegalStateException a prior call returned an UNSAT solution or
 *             resulted in an exception
 * @throws NullPointerException any of the arguments are null
 * @throws UnboundLeafException the formula refers to an undeclared variable or
 *             a relation not mapped by this.bounds + b
 * @throws HigherOrderDeclException the formula contains a higher order
 *             declaration
 * @throws IllegalArgumentException any of the remaining preconditions on
 *             {@code f} and {@code b} are violated
 * @throws AbortedException this solving task has been aborted
 */
@Override
public Solution solve(Formula f, Bounds b) throws HigherOrderDeclException, UnboundLeafException, AbortedException {
    if (outcome == Boolean.FALSE)
        throw new IllegalStateException("Cannot use this solver since a prior call to solve(...) produced an UNSAT solution.");
    if (outcome != null && translation == null)
        throw new IllegalStateException("Cannot use this solver since a prior call to solve(...) resulted in an exception.");
    final Solution solution;
    try {
        final long startTransl = System.currentTimeMillis();
        translation = translation == null ? Translator.translateIncremental(f, b, options) : Translator.translateIncremental(f, b, translation);
        final long endTransl = System.currentTimeMillis();
        if (translation.trivial()) {
            final Statistics stats = new Statistics(translation, endTransl - startTransl, 0);
            if (translation.cnf().solve()) {
                solution = Solution.triviallySatisfiable(stats, translation.interpret());
            } else {
                solution = Solution.triviallyUnsatisfiable(stats, null);
            }
        } else {
            final SATSolver cnf = translation.cnf();
            translation.options().reporter().solvingCNF(translation.numPrimaryVariables(), cnf.numberOfVariables(), cnf.numberOfClauses());
            final long startSolve = System.currentTimeMillis();
            final boolean sat = cnf.solve();
            final long endSolve = System.currentTimeMillis();
            final Statistics stats = new Statistics(translation, endTransl - startTransl, endSolve - startSolve);
            if (sat) {
                solution = Solution.satisfiable(stats, translation.interpret());
            } else {
                solution = Solution.unsatisfiable(stats, null);
            }
        }
    } catch (SATAbortedException sae) {
        free();
        throw new AbortedException(sae);
    } catch (RuntimeException e) {
        free();
        throw e;
    }
    if (solution.sat()) {
        outcome = Boolean.TRUE;
    } else {
        outcome = Boolean.FALSE;
        free();
    }
    return solution;
}
Also used : SATSolver(kodkod.engine.satlab.SATSolver) SATAbortedException(kodkod.engine.satlab.SATAbortedException) SATAbortedException(kodkod.engine.satlab.SATAbortedException)

Example 3 with SATAbortedException

use of kodkod.engine.satlab.SATAbortedException in project org.alloytools.alloy by AlloyTools.

the class Solver method solve.

/**
 * Attempts to satisfy the given {@code formula} and {@code bounds} with respect
 * to {@code this.options} or, optionally, prove the problem's unsatisfiability.
 * If the method completes normally, the result is a {@linkplain Solution
 * solution} containing either an {@linkplain Instance instance} of the given
 * problem or, optionally, a {@linkplain Proof proof} of its unsatisfiability.
 * An unsatisfiability proof will be constructed iff {@code this.options.solver}
 * specifies a {@linkplain SATProver} and
 * {@code this.options.logTranslation > 0}.
 *
 * @return some sol: {@link Solution} | some sol.instance() => sol.instance() in
 *         MODELS(formula, bounds, this.options) else UNSAT(formula, bound,
 *         this.options)
 * @throws NullPointerException formula = null || bounds = null
 * @throws UnboundLeafException the formula contains an undeclared variable or a
 *             relation not mapped by the given bounds
 * @throws HigherOrderDeclException the formula contains a higher order
 *             declaration that cannot be skolemized, or it can be skolemized
 *             but {@code this.options.skolemDepth} is insufficiently large
 * @throws AbortedException this solving task was aborted
 * @see Options
 * @see Solution
 * @see Instance
 * @see Proof
 */
@Override
public Solution solve(Formula formula, Bounds bounds) throws HigherOrderDeclException, UnboundLeafException, AbortedException {
    final long startTransl = System.currentTimeMillis();
    try {
        final Translation.Whole translation = Translator.translate(formula, bounds, options);
        final long endTransl = System.currentTimeMillis();
        if (translation.trivial())
            return trivial(translation, endTransl - startTransl);
        final SATSolver cnf = translation.cnf();
        options.reporter().solvingCNF(translation.numPrimaryVariables(), cnf.numberOfVariables(), cnf.numberOfClauses());
        final long startSolve = System.currentTimeMillis();
        final boolean isSat = cnf.solve();
        final long endSolve = System.currentTimeMillis();
        final Statistics stats = new Statistics(translation, endTransl - startTransl, endSolve - startSolve);
        return isSat ? sat(translation, stats) : unsat(translation, stats);
    } catch (SATAbortedException sae) {
        throw new AbortedException(sae);
    }
}
Also used : SATSolver(kodkod.engine.satlab.SATSolver) Translation(kodkod.engine.fol2sat.Translation) SATAbortedException(kodkod.engine.satlab.SATAbortedException) SATAbortedException(kodkod.engine.satlab.SATAbortedException)

Aggregations

SATAbortedException (kodkod.engine.satlab.SATAbortedException)3 SATSolver (kodkod.engine.satlab.SATSolver)2 Translation (kodkod.engine.fol2sat.Translation)1 Proc (kodkod.engine.hol.Proc)1