Search in sources :

Example 1 with HigherOrderDeclException

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

the class HOL2ProcTranslator method visit.

@Override
public Formula visit(QuantifiedFormula qf) {
    for (Decl decl : qf.decls()) {
        if (decl.multiplicity() != Multiplicity.ONE) {
            if (!isSkolemizableUpToNow())
                throw new HigherOrderDeclException(decl);
            assert qf.decls().size() == 1 : "not implemented for quantifiers with multiple decls";
            QuantifiedFormula revQuant = (QuantifiedFormula) qf.formula().quantify(qf.quantifier().opposite, decl);
            conversions.add(new Conversion(qf, revQuant));
            return revQuant;
        }
    }
    return super.visit(qf);
}
Also used : HigherOrderDeclException(kodkod.engine.fol2sat.HigherOrderDeclException) Decl(kodkod.ast.Decl) QuantifiedFormula(kodkod.ast.QuantifiedFormula)

Example 2 with HigherOrderDeclException

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

the class Lists method main.

/**
 * Usage: java examples.Lists [scope]
 */
public static void main(String[] args) {
    if (args.length < 1)
        usage();
    try {
        final int n = Integer.parseInt(args[0]);
        final Lists model = new Lists();
        final Bounds b = model.bounds(n);
        final Solver solver = new Solver();
        solver.options().setSolver(SATFactory.MiniSat);
        // solver.options().setFlatten(false);
        // solver.options().setSkolemize(false);
        Formula f = model.runShow();
        System.out.println("running show");
        Solution s = solver.solve(f, b);
        System.out.println(s);
        f = model.checkEmpties();
        System.out.println("checking empties");
        s = solver.solve(f, b);
        System.out.println(s);
        f = model.checkReflexive();
        System.out.println("checking reflexive");
        s = solver.solve(f, b);
        System.out.println(s);
        f = model.checkSymmetric();
        System.out.println("checking symmetric");
        s = solver.solve(f, b);
        System.out.println(s);
    } catch (NumberFormatException nfe) {
        usage();
    } catch (HigherOrderDeclException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (UnboundLeafException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : Formula(kodkod.ast.Formula) Solver(kodkod.engine.Solver) UnboundLeafException(kodkod.engine.fol2sat.UnboundLeafException) Bounds(kodkod.instance.Bounds) HigherOrderDeclException(kodkod.engine.fol2sat.HigherOrderDeclException) Solution(kodkod.engine.Solution)

Example 3 with HigherOrderDeclException

use of kodkod.engine.fol2sat.HigherOrderDeclException 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 4 with HigherOrderDeclException

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

the class LAT258 method main.

/**
 * Usage: java examples.tptp.LAT258 [scope]
 */
public static void main(String[] args) {
    if (args.length < 1)
        usage();
    try {
        final int n = Integer.parseInt(args[0]);
        final LAT258 model = new LAT258();
        final Bounds b = model.bounds(n);
        final Solver solver = new Solver();
        solver.options().setSolver(SATFactory.MiniSat);
        final Formula f = model.checkGoalToBeProved();
        System.out.println(f);
        // System.out.println(b);
        final Solution s = solver.solve(f, b);
        System.out.println(s);
    } catch (NumberFormatException nfe) {
        usage();
    } catch (HigherOrderDeclException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (UnboundLeafException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : Formula(kodkod.ast.Formula) Solver(kodkod.engine.Solver) UnboundLeafException(kodkod.engine.fol2sat.UnboundLeafException) Bounds(kodkod.instance.Bounds) HigherOrderDeclException(kodkod.engine.fol2sat.HigherOrderDeclException) Solution(kodkod.engine.Solution)

Example 5 with HigherOrderDeclException

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

the class FileSystem method main.

/**
 * Usage: java examples.alloy.FileSystem [scope]
 */
public static void main(String[] args) {
    if (args.length < 1)
        usage();
    try {
        final int n = Integer.parseInt(args[0]);
        final FileSystem model = new FileSystem();
        final Formula f = model.checkNoDirAliases();
        System.out.println(f);
        final Bounds b = model.bounds(n);
        final Solver solver = new Solver();
        solver.options().setSolver(SATFactory.MiniSat);
        final Solution s = solver.solve(f, b);
        System.out.println(s);
    } catch (NumberFormatException nfe) {
        usage();
    } catch (HigherOrderDeclException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (UnboundLeafException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : Formula(kodkod.ast.Formula) Solver(kodkod.engine.Solver) UnboundLeafException(kodkod.engine.fol2sat.UnboundLeafException) Bounds(kodkod.instance.Bounds) HigherOrderDeclException(kodkod.engine.fol2sat.HigherOrderDeclException) Solution(kodkod.engine.Solution)

Aggregations

HigherOrderDeclException (kodkod.engine.fol2sat.HigherOrderDeclException)12 Formula (kodkod.ast.Formula)8 Solution (kodkod.engine.Solution)7 Solver (kodkod.engine.Solver)7 UnboundLeafException (kodkod.engine.fol2sat.UnboundLeafException)7 Bounds (kodkod.instance.Bounds)7 ErrorType (edu.mit.csail.sdg.alloy4.ErrorType)4 CapacityExceededException (kodkod.engine.CapacityExceededException)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 ArrayList (java.util.ArrayList)3 Expression (kodkod.ast.Expression)2 IntExpression (kodkod.ast.IntExpression)2 QuantifiedFormula (kodkod.ast.QuantifiedFormula)2 Relation (kodkod.ast.Relation)2 TupleFactory (kodkod.instance.TupleFactory)2 Universe (kodkod.instance.Universe)2 A4Reporter (edu.mit.csail.sdg.alloy4.A4Reporter)1 Command (edu.mit.csail.sdg.ast.Command)1