Search in sources :

Example 61 with Bounds

use of kodkod.instance.Bounds in project org.alloytools.alloy by AlloyTools.

the class MGT066 method bounds.

/**
 * Returns a bounds for a universe of the given size.
 *
 * @return bounds for a universe of the given size.
 */
public final Bounds bounds(int size) {
    assert size > 0;
    final List<String> atoms = new ArrayList<String>(size);
    for (int i = 0; i < size; i++) atoms.add("a" + i);
    final Universe u = new Universe(atoms);
    final TupleFactory f = u.factory();
    final Bounds b = new Bounds(u);
    b.bound(lt, f.allOf(2));
    b.bound(leq, f.allOf(2));
    b.bound(gt, f.allOf(2));
    b.bound(geq, f.allOf(2));
    return b;
}
Also used : Bounds(kodkod.instance.Bounds) ArrayList(java.util.ArrayList) TupleFactory(kodkod.instance.TupleFactory) Universe(kodkod.instance.Universe)

Example 62 with Bounds

use of kodkod.instance.Bounds in project org.alloytools.alloy by AlloyTools.

the class SET943 method bounds.

/**
 * Returns bounds for the given scope.
 *
 * @return bounds for the given scope.
 */
public final Bounds bounds(int n) {
    assert n > 0;
    final List<String> atoms = new ArrayList<String>(n);
    for (int i = 0; i < n; i++) atoms.add("a" + i);
    final Universe u = new Universe(atoms);
    final Bounds b = new Bounds(u);
    final TupleFactory f = u.factory();
    b.bound(empty, f.allOf(1));
    b.bound(subset, f.allOf(2));
    b.bound(in, f.allOf(2));
    b.bound(union, f.allOf(2));
    b.bound(union2, f.allOf(3));
    return b;
}
Also used : Bounds(kodkod.instance.Bounds) ArrayList(java.util.ArrayList) TupleFactory(kodkod.instance.TupleFactory) Universe(kodkod.instance.Universe)

Example 63 with Bounds

use of kodkod.instance.Bounds in project org.alloytools.alloy by AlloyTools.

the class SET967 method bounds.

/**
 * Returns bounds for the given scope.
 *
 * @return bounds for the given scope.
 */
public final Bounds bounds(int n) {
    assert n > 0;
    final List<String> atoms = new ArrayList<String>(n);
    for (int i = 0; i < n; i++) atoms.add("a" + i);
    final Universe u = new Universe(atoms);
    final Bounds b = new Bounds(u);
    final TupleFactory f = u.factory();
    b.bound(empty, f.allOf(1));
    b.bound(subset, f.allOf(2));
    b.bound(in, f.allOf(2));
    b.bound(disjoint, f.allOf(2));
    b.bound(union, f.allOf(2));
    b.bound(singleton, f.allOf(2));
    b.bound(intersect2, f.allOf(3));
    b.bound(cartesian2, f.allOf(3));
    b.bound(union2, f.allOf(3));
    b.bound(ordered, f.allOf(3));
    b.bound(unordered, f.allOf(3));
    return b;
}
Also used : Bounds(kodkod.instance.Bounds) ArrayList(java.util.ArrayList) TupleFactory(kodkod.instance.TupleFactory) Universe(kodkod.instance.Universe)

Example 64 with Bounds

use of kodkod.instance.Bounds in project org.alloytools.alloy by AlloyTools.

the class TOP020 method main.

/**
 * Usage: java examples.tptp.TOP020 [univ size]
 */
public static void main(String[] args) {
    if (args.length < 1)
        usage();
    try {
        final int n = Integer.parseInt(args[0]);
        if (n < 1)
            usage();
        final TOP020 model = new TOP020();
        final Solver solver = new Solver();
        solver.options().setSolver(SATFactory.MiniSat);
        final Formula f = model.checkChallenge_AMR_1_4_4();
        final Bounds b = model.bounds(n);
        // System.out.println(f);
        // System.out.println(b);
        final Solution sol = solver.solve(f, b);
        System.out.println(sol);
    } catch (NumberFormatException nfe) {
        usage();
    }
}
Also used : Formula(kodkod.ast.Formula) Solver(kodkod.engine.Solver) Bounds(kodkod.instance.Bounds) Solution(kodkod.engine.Solution)

Example 65 with Bounds

use of kodkod.instance.Bounds in project org.alloytools.alloy by AlloyTools.

the class BookExamples method trial.

/**
 * This tries a particular solution against the formula.
 */
private static Solution trial(A4Reporter rep, TupleFactory fac, Solver solver, Iterable<Sig> sigs, Formula f, A4Solution frame, Object[] t) {
    try {
        frame.kr2typeCLEAR();
        Bounds b = null;
        TupleSet ts = null;
        for (int i = 1; i < t.length; i++) {
            Object x = t[i];
            if (x == null)
                return null;
            if (x instanceof String && ((String) x).length() > 0) {
                // This
                // means
                // it's
                // a
                // unary
                // Tuple
                // containing
                // the
                // given
                // atom
                Tuple xx = fac.tuple((String) x);
                if (ts == null)
                    ts = fac.noneOf(1);
                ts.add(xx);
                continue;
            }
            if (x instanceof Tuple) {
                // This means it's a Tuple
                Tuple xx = (Tuple) x;
                if (ts == null)
                    ts = fac.noneOf(xx.arity());
                ts.add(xx);
                continue;
            }
            if (x instanceof String) {
                // The empty string means the sig
                // name follows here
                i++;
                if (i >= t.length - 1 || !(t[i] instanceof String) || !(t[i + 1] instanceof String))
                    return null;
                String sigName = (String) (t[i]);
                i++;
                String fieldName = (String) (t[i]);
                Sig first = hasSig(sigs, sigName);
                if (first == null)
                    return null;
                Expression expr = null;
                if (fieldName.length() == 0) {
                    expr = frame.a2k(first);
                } else {
                    for (Field field : first.getFields()) if (field.label.equals(fieldName)) {
                        expr = frame.a2k(field);
                        while (expr instanceof BinaryExpression) expr = ((BinaryExpression) expr).right();
                        break;
                    }
                }
                if (!(expr instanceof Relation))
                    return null;
                if (b == null)
                    // We delay the expansive
                    b = frame.getBounds();
                // really find a possible match
                if (ts == null)
                    ts = fac.noneOf(expr.arity());
                if (!ts.containsAll(b.lowerBound((Relation) expr)))
                    // Sanity check
                    return null;
                if (!b.upperBound((Relation) expr).containsAll(ts))
                    // Sanity check
                    return null;
                b.boundExactly((Relation) expr, ts);
                ts = null;
                continue;
            }
        }
        SATFactory sat = solver.options().solver();
        Solution sol;
        try {
            solver.options().setSolver(SATFactory.DefaultSAT4J);
            sol = solver.solve(f, b);
        } finally {
            solver.options().setSolver(sat);
        }
        if (sol == null || (sol.outcome() != SATISFIABLE && sol.outcome() != TRIVIALLY_SATISFIABLE))
            return null;
        if (rep != null)
            rep.debug("Comment: " + t[0] + "\n");
        return sol;
    } catch (Throwable ex) {
        return null;
    }
}
Also used : TupleSet(kodkod.instance.TupleSet) Bounds(kodkod.instance.Bounds) Sig(edu.mit.csail.sdg.ast.Sig) Field(edu.mit.csail.sdg.ast.Sig.Field) Relation(kodkod.ast.Relation) SATFactory(kodkod.engine.satlab.SATFactory) BinaryExpression(kodkod.ast.BinaryExpression) Expression(kodkod.ast.Expression) BinaryExpression(kodkod.ast.BinaryExpression) Tuple(kodkod.instance.Tuple) Solution(kodkod.engine.Solution)

Aggregations

Bounds (kodkod.instance.Bounds)140 Formula (kodkod.ast.Formula)83 Universe (kodkod.instance.Universe)79 TupleFactory (kodkod.instance.TupleFactory)76 Solution (kodkod.engine.Solution)75 Solver (kodkod.engine.Solver)67 TupleSet (kodkod.instance.TupleSet)55 Relation (kodkod.ast.Relation)49 ArrayList (java.util.ArrayList)45 Expression (kodkod.ast.Expression)21 Variable (kodkod.ast.Variable)21 IntExpression (kodkod.ast.IntExpression)20 Instance (kodkod.instance.Instance)12 Decls (kodkod.ast.Decls)11 Evaluator (kodkod.engine.Evaluator)8 HigherOrderDeclException (kodkod.engine.fol2sat.HigherOrderDeclException)7 UnboundLeafException (kodkod.engine.fol2sat.UnboundLeafException)7 ConsoleReporter (kodkod.engine.config.ConsoleReporter)6 Tuple (kodkod.instance.Tuple)6 LinkedHashSet (java.util.LinkedHashSet)5