Search in sources :

Example 1 with CapacityExceededException

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

the class TranslateAlloyToKodkod method execute_commandFromBook.

/**
 * Based on the specified "options", execute one command and return the
 * resulting A4Solution object.
 * <p>
 * Note: it will first test whether the model fits one of the model from the
 * "Software Abstractions" book; if so, it will use the exact instance that was
 * in the book.
 *
 * @param rep - if nonnull, we'll send compilation diagnostic messages to it
 * @param sigs - the list of sigs; this list must be complete
 * @param cmd - the Command to execute
 * @param opt - the set of options guiding the execution of the command
 * @return null if the user chose "save to FILE" as the SAT solver, and nonnull
 *         if the solver finishes the entire solving and is either satisfiable
 *         or unsatisfiable.
 *         <p>
 *         If the return value X is satisfiable, you can call X.next() to get
 *         the next satisfying solution X2; and you can call X2.next() to get
 *         the next satisfying solution X3... until you get an unsatisfying
 *         solution.
 */
public static A4Solution execute_commandFromBook(A4Reporter rep, Iterable<Sig> sigs, Command cmd, A4Options opt) throws Err {
    if (rep == null)
        rep = A4Reporter.NOP;
    TranslateAlloyToKodkod tr = null;
    try {
        if (cmd.parent != null || !cmd.getGrowableSigs().isEmpty())
            return execute_greedyCommand(rep, sigs, cmd, opt);
        tr = new TranslateAlloyToKodkod(rep, opt, sigs, cmd);
        tr.makeFacts(cmd.formula);
        return tr.frame.solve(rep, cmd, new Simplifier(), true);
    } catch (UnsatisfiedLinkError ex) {
        throw new ErrorFatal("The required JNI library cannot be found: " + ex.toString().trim(), ex);
    } catch (CapacityExceededException ex) {
        throw rethrow(ex);
    } catch (HigherOrderDeclException ex) {
        Pos p = tr != null ? tr.frame.kv2typepos(ex.decl().variable()).b : Pos.UNKNOWN;
        throw new ErrorType(p, "Analysis cannot be performed since it requires higher-order quantification that could not be skolemized.");
    } catch (Throwable ex) {
        if (ex instanceof Err)
            throw (Err) ex;
        else
            throw new ErrorFatal("Unknown exception occurred: " + ex, ex);
    }
}
Also used : CapacityExceededException(kodkod.engine.CapacityExceededException) ErrorFatal(edu.mit.csail.sdg.alloy4.ErrorFatal) ErrorType(edu.mit.csail.sdg.alloy4.ErrorType) Err(edu.mit.csail.sdg.alloy4.Err) Pos(edu.mit.csail.sdg.alloy4.Pos) HigherOrderDeclException(kodkod.engine.fol2sat.HigherOrderDeclException)

Example 2 with CapacityExceededException

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

the class TranslateAlloyToKodkod method execute_command.

/**
 * Based on the specified "options", execute one command and return the
 * resulting A4Solution object.
 *
 * @param rep - if nonnull, we'll send compilation diagnostic messages to it
 * @param sigs - the list of sigs; this list must be complete
 * @param cmd - the Command to execute
 * @param opt - the set of options guiding the execution of the command
 * @return null if the user chose "save to FILE" as the SAT solver, and nonnull
 *         if the solver finishes the entire solving and is either satisfiable
 *         or unsatisfiable.
 *         <p>
 *         If the return value X is satisfiable, you can call X.next() to get
 *         the next satisfying solution X2; and you can call X2.next() to get
 *         the next satisfying solution X3... until you get an unsatisfying
 *         solution.
 */
public static A4Solution execute_command(A4Reporter rep, Iterable<Sig> sigs, Command cmd, A4Options opt) throws Err {
    if (rep == null)
        rep = A4Reporter.NOP;
    TranslateAlloyToKodkod tr = null;
    try {
        if (cmd.parent != null || !cmd.getGrowableSigs().isEmpty())
            return execute_greedyCommand(rep, sigs, cmd, opt);
        tr = new TranslateAlloyToKodkod(rep, opt, sigs, cmd);
        tr.makeFacts(cmd.formula);
        return tr.frame.solve(rep, cmd, new Simplifier(), false);
    } catch (UnsatisfiedLinkError ex) {
        throw new ErrorFatal("The required JNI library cannot be found: " + ex.toString().trim(), ex);
    } catch (CapacityExceededException ex) {
        throw rethrow(ex);
    } catch (HigherOrderDeclException ex) {
        Pos p = tr != null ? tr.frame.kv2typepos(ex.decl().variable()).b : Pos.UNKNOWN;
        throw new ErrorType(p, "Analysis cannot be performed since it requires higher-order quantification that could not be skolemized.");
    } catch (Throwable ex) {
        if (ex instanceof Err)
            throw (Err) ex;
        else
            throw new ErrorFatal("Unknown exception occurred: " + ex, ex);
    }
}
Also used : CapacityExceededException(kodkod.engine.CapacityExceededException) ErrorFatal(edu.mit.csail.sdg.alloy4.ErrorFatal) ErrorType(edu.mit.csail.sdg.alloy4.ErrorType) Err(edu.mit.csail.sdg.alloy4.Err) Pos(edu.mit.csail.sdg.alloy4.Pos) HigherOrderDeclException(kodkod.engine.fol2sat.HigherOrderDeclException)

Example 3 with CapacityExceededException

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

the class TranslateAlloyToKodkod method execute_greedyCommand.

private static A4Solution execute_greedyCommand(A4Reporter rep, Iterable<Sig> sigs, Command usercommand, A4Options opt) throws Exception {
    // FIXTHIS: if the next command has a "smaller scope" than the last
    // command, we would get a Kodkod exception...
    // FIXTHIS: if the solver is "toCNF" or "toKodkod" then this method will
    // throw an Exception...
    // FIXTHIS: does solution enumeration still work when we're doing a
    // greedy solve?
    TranslateAlloyToKodkod tr = null;
    try {
        long start = System.currentTimeMillis();
        GreedySimulator sim = new GreedySimulator();
        sim.allSigs = sigs;
        sim.partial = null;
        A4Reporter rep2 = new A4Reporter(rep) {

            private boolean first = true;

            @Override
            public void translate(String solver, int bitwidth, int maxseq, int skolemDepth, int symmetry) {
                if (first)
                    super.translate(solver, bitwidth, maxseq, skolemDepth, symmetry);
                first = false;
            }

            @Override
            public void resultSAT(Object command, long solvingTime, Object solution) {
            }

            @Override
            public void resultUNSAT(Object command, long solvingTime, Object solution) {
            }
        };
        // Form the list of commands
        List<Command> commands = new ArrayList<Command>();
        while (usercommand != null) {
            commands.add(usercommand);
            usercommand = usercommand.parent;
        }
        // For each command...
        A4Solution sol = null;
        for (int i = commands.size() - 1; i >= 0; i--) {
            Command cmd = commands.get(i);
            sim.growableSigs = cmd.getGrowableSigs();
            while (cmd != null) {
                rep.debug(cmd.scope.toString());
                usercommand = cmd;
                tr = new TranslateAlloyToKodkod(rep2, opt, sigs, cmd);
                tr.makeFacts(cmd.formula);
                sim.totalOrderPredicates = tr.totalOrderPredicates;
                sol = tr.frame.solve(rep2, cmd, sim.partial == null || cmd.check ? new Simplifier() : sim, false);
                if (!sol.satisfiable() && !cmd.check) {
                    start = System.currentTimeMillis() - start;
                    if (sim.partial == null) {
                        rep.resultUNSAT(cmd, start, sol);
                        return sol;
                    } else {
                        rep.resultSAT(cmd, start, sim.partial);
                        return sim.partial;
                    }
                }
                if (sol.satisfiable() && cmd.check) {
                    start = System.currentTimeMillis() - start;
                    rep.resultSAT(cmd, start, sol);
                    return sol;
                }
                sim.partial = sol;
                if (sim.growableSigs.isEmpty())
                    break;
                for (Sig s : sim.growableSigs) {
                    CommandScope sc = cmd.getScope(s);
                    if (sc.increment > sc.endingScope - sc.startingScope) {
                        cmd = null;
                        break;
                    }
                    cmd = cmd.change(s, sc.isExact, sc.startingScope + sc.increment, sc.endingScope, sc.increment);
                }
            }
        }
        if (sol.satisfiable())
            rep.resultSAT(usercommand, System.currentTimeMillis() - start, sol);
        else
            rep.resultUNSAT(usercommand, System.currentTimeMillis() - start, sol);
        return sol;
    } catch (CapacityExceededException ex) {
        throw rethrow(ex);
    } catch (HigherOrderDeclException ex) {
        Pos p = tr != null ? tr.frame.kv2typepos(ex.decl().variable()).b : Pos.UNKNOWN;
        throw new ErrorType(p, "Analysis cannot be performed since it requires higher-order quantification that could not be skolemized.");
    }
}
Also used : A4Reporter(edu.mit.csail.sdg.alloy4.A4Reporter) ArrayList(java.util.ArrayList) Sig(edu.mit.csail.sdg.ast.Sig) CapacityExceededException(kodkod.engine.CapacityExceededException) ErrorType(edu.mit.csail.sdg.alloy4.ErrorType) Command(edu.mit.csail.sdg.ast.Command) Pos(edu.mit.csail.sdg.alloy4.Pos) HigherOrderDeclException(kodkod.engine.fol2sat.HigherOrderDeclException) CommandScope(edu.mit.csail.sdg.ast.CommandScope)

Example 4 with CapacityExceededException

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

the class TranslateAlloyToKodkod method alloy2kodkod.

/**
 * Translate the Alloy expression into an equivalent Kodkod Expression or
 * IntExpression or Formula object.
 *
 * @param sol - an existing satisfiable A4Solution object
 * @param expr - this is the Alloy expression we want to translate
 */
public static Object alloy2kodkod(A4Solution sol, Expr expr) throws Err {
    if (expr.ambiguous && !expr.errors.isEmpty())
        expr = expr.resolve(expr.type(), null);
    if (!expr.errors.isEmpty())
        throw expr.errors.pick();
    TranslateAlloyToKodkod tr = new TranslateAlloyToKodkod(sol.getBitwidth(), sol.unrolls(), sol.a2k(), sol.s2k());
    Object ans;
    try {
        ans = tr.visitThis(expr);
    } catch (UnsatisfiedLinkError ex) {
        throw new ErrorFatal("The required JNI library cannot be found: " + ex.toString().trim());
    } catch (CapacityExceededException ex) {
        throw rethrow(ex);
    } catch (HigherOrderDeclException ex) {
        throw new ErrorType("Analysis cannot be performed since it requires higher-order quantification that could not be skolemized.");
    } catch (Throwable ex) {
        if (ex instanceof Err)
            throw (Err) ex;
        throw new ErrorFatal("Unknown exception occurred: " + ex, ex);
    }
    if ((ans instanceof IntExpression) || (ans instanceof Formula) || (ans instanceof Expression))
        return ans;
    throw new ErrorFatal("Unknown internal error encountered in the evaluator.");
}
Also used : QuantifiedFormula(kodkod.ast.QuantifiedFormula) Formula(kodkod.ast.Formula) CapacityExceededException(kodkod.engine.CapacityExceededException) ErrorFatal(edu.mit.csail.sdg.alloy4.ErrorFatal) ErrorType(edu.mit.csail.sdg.alloy4.ErrorType) Err(edu.mit.csail.sdg.alloy4.Err) Expression(kodkod.ast.Expression) BinaryExpression(kodkod.ast.BinaryExpression) IntExpression(kodkod.ast.IntExpression) IntExpression(kodkod.ast.IntExpression) HigherOrderDeclException(kodkod.engine.fol2sat.HigherOrderDeclException)

Aggregations

ErrorType (edu.mit.csail.sdg.alloy4.ErrorType)4 CapacityExceededException (kodkod.engine.CapacityExceededException)4 HigherOrderDeclException (kodkod.engine.fol2sat.HigherOrderDeclException)4 Err (edu.mit.csail.sdg.alloy4.Err)3 ErrorFatal (edu.mit.csail.sdg.alloy4.ErrorFatal)3 Pos (edu.mit.csail.sdg.alloy4.Pos)3 A4Reporter (edu.mit.csail.sdg.alloy4.A4Reporter)1 Command (edu.mit.csail.sdg.ast.Command)1 CommandScope (edu.mit.csail.sdg.ast.CommandScope)1 Sig (edu.mit.csail.sdg.ast.Sig)1 ArrayList (java.util.ArrayList)1 BinaryExpression (kodkod.ast.BinaryExpression)1 Expression (kodkod.ast.Expression)1 Formula (kodkod.ast.Formula)1 IntExpression (kodkod.ast.IntExpression)1 QuantifiedFormula (kodkod.ast.QuantifiedFormula)1