Search in sources :

Example 56 with Universe

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

the class TOP020 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(hausdorff, f.allOf(1));
    b.bound(member, f.allOf(2));
    b.bound(open, f.allOf(2));
    b.bound(disjoint, f.allOf(2));
    b.bound(closed, f.allOf(2));
    b.bound(coerce, f.allOf(2));
    b.bound(diagonal, f.allOf(2));
    b.bound(product, f.allOf(3));
    b.bound(tsproduct, f.allOf(3));
    b.bound(ordered, f.allOf(3));
    return b;
}
Also used : Bounds(kodkod.instance.Bounds) ArrayList(java.util.ArrayList) TupleFactory(kodkod.instance.TupleFactory) Universe(kodkod.instance.Universe)

Example 57 with Universe

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

the class KK method main.

public static void main(String[] args) throws Exception {
    Relation x6 = Relation.unary("R");
    int[] ints = new int[] { 0, 1, 2 };
    List<Object> atomlist = new LinkedList<Object>();
    atomlist.add("R$0");
    atomlist.add("R$1");
    atomlist.add("R$2");
    for (int i : ints) atomlist.add(i);
    Universe universe = new Universe(atomlist);
    TupleFactory factory = universe.factory();
    Bounds bounds = new Bounds(universe);
    TupleSet x6_upper = factory.noneOf(1);
    x6_upper.add(factory.tuple("R$0"));
    x6_upper.add(factory.tuple("R$1"));
    x6_upper.add(factory.tuple("R$2"));
    bounds.bound(x6, x6_upper);
    for (int i : ints) {
        bounds.boundExactly(i, factory.setOf(i));
    }
    Formula x11 = x6.some();
    IntExpression x5 = x6.count();
    Formula x9 = x11.implies(x5.gt(IntConstant.constant(0)));
    Formula x7 = x9.not();
    Solver solver = new Solver();
    solver.options().setSolver(SATFactory.DefaultSAT4J);
    solver.options().setBitwidth(2);
    // solver.options().setFlatten(false);
    solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT);
    solver.options().setSymmetryBreaking(20);
    solver.options().setSkolemDepth(0);
    System.out.println("Solving...");
    System.out.println(PrettyPrinter.print(x7, 0));
    System.out.println(bounds);
    Solution sol = solver.solve(x7, bounds);
    System.out.println(sol.toString());
    Instance inst = sol.instance();
    Evaluator ev = new Evaluator(inst);
    System.out.println(ev.evaluate(x6.some()));
    System.out.println(ev.evaluate(x5));
    System.out.println(ev.evaluate(x5.gt(IntConstant.constant(0))));
    System.out.println(ev.evaluate(x6.some().implies(x5.gt(IntConstant.constant(0))).not()));
    System.out.println(ev.evaluate(x7));
}
Also used : TupleSet(kodkod.instance.TupleSet) Solver(kodkod.engine.Solver) Instance(kodkod.instance.Instance) Bounds(kodkod.instance.Bounds) IntExpression(kodkod.ast.IntExpression) TupleFactory(kodkod.instance.TupleFactory) Universe(kodkod.instance.Universe) Evaluator(kodkod.engine.Evaluator) LinkedList(java.util.LinkedList) Formula(kodkod.ast.Formula) Relation(kodkod.ast.Relation) Solution(kodkod.engine.Solution)

Example 58 with Universe

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

the class BugTests method testMana_01312007.

public final void testMana_01312007() {
    final Relation A = Relation.unary("A");
    final Relation first1 = Relation.unary("first1");
    final Relation first2 = Relation.unary("first2");
    final Relation last1 = Relation.unary("last1");
    final Relation last2 = Relation.unary("last2");
    final Relation next1 = Relation.binary("next1");
    final Relation next2 = Relation.binary("next2");
    final Formula f0 = next1.totalOrder(A, first1, last1);
    final Formula f1 = next2.totalOrder(A, first2, last2);
    final Formula f2 = first1.eq(last2);
    final Formula f3 = f0.and(f1).and(f2);
    final Universe u = new Universe(Arrays.asList("a0", "a1", "a2"));
    final TupleFactory f = u.factory();
    final Bounds b = new Bounds(u);
    b.bound(A, f.allOf(1));
    b.bound(first1, f.allOf(1));
    b.bound(first2, f.allOf(1));
    b.bound(last1, f.allOf(1));
    b.bound(last2, f.allOf(1));
    b.bound(next1, f.allOf(2));
    b.bound(next2, f.allOf(2));
    final Solver solver = new Solver();
    final Solution sol = solver.solve(f3, b);
    assertEquals(Solution.Outcome.SATISFIABLE, sol.outcome());
}
Also used : Formula(kodkod.ast.Formula) Relation(kodkod.ast.Relation) Solver(kodkod.engine.Solver) Bounds(kodkod.instance.Bounds) TupleFactory(kodkod.instance.TupleFactory) Universe(kodkod.instance.Universe) Solution(kodkod.engine.Solution)

Example 59 with Universe

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

the class BugTests method testFelix_02222008.

public final void testFelix_02222008() {
    List<String> atomlist = Arrays.asList("X1", "X2", "X3");
    Universe universe = new Universe(atomlist);
    TupleFactory factory = universe.factory();
    Bounds bounds = new Bounds(universe);
    Relation x = Relation.unary("X");
    TupleSet x_upper = factory.noneOf(1);
    x_upper.add(factory.tuple("X1"));
    x_upper.add(factory.tuple("X2"));
    x_upper.add(factory.tuple("X3"));
    bounds.bound(x, x_upper);
    Variable a = Variable.unary("a");
    Variable b = Variable.unary("b");
    Variable c = Variable.unary("c");
    Formula goal = x.lone().not().and(b.union(c).eq(a).forSome(c.oneOf(x)).forAll(b.oneOf(x)).forSome(a.setOf(x)));
    Solver solver = new Solver();
    solver.options().setSolver(SATFactory.DefaultSAT4J);
    solver.options().setBitwidth(4);
    solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT);
    solver.options().setSymmetryBreaking(0);
    solver.options().setSkolemDepth(2);
    Iterator<Solution> itr = solver.solveAll(goal, bounds);
    int sols = 0;
    while (itr.hasNext()) {
        Solution sol = itr.next();
        Instance inst = sol.instance();
        if (inst == null)
            break;
        sols++;
        for (Relation rel : inst.relations()) {
            if (rel != x) {
                if (rel.arity() == 1) {
                    // rel = a
                    assertEquals(inst.tuples(x), inst.tuples(rel));
                } else {
                    // rel = c
                    final TupleSet dom = factory.noneOf(1);
                    for (Tuple t : inst.tuples(rel)) {
                        dom.add(factory.tuple(t.atom(0)));
                    }
                    assertEquals(inst.tuples(x), dom);
                }
            }
        }
    }
    assertEquals(3, sols);
}
Also used : TupleSet(kodkod.instance.TupleSet) Solver(kodkod.engine.Solver) Variable(kodkod.ast.Variable) Instance(kodkod.instance.Instance) Bounds(kodkod.instance.Bounds) TupleFactory(kodkod.instance.TupleFactory) Universe(kodkod.instance.Universe) Formula(kodkod.ast.Formula) Relation(kodkod.ast.Relation) Solution(kodkod.engine.Solution) Tuple(kodkod.instance.Tuple)

Example 60 with Universe

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

the class BugTests method testFelix_08022006.

public final void testFelix_08022006() {
    Relation x = Relation.nary("P", 1);
    String[] atoms = { "-8", "-7", "-6", "-5", "-4", "-3", "-2", "-1", "0", "1", "2", "3", "4", "5", "6", "7" };
    java.util.ArrayList<String> atomlist = new java.util.ArrayList<String>();
    for (String a : atoms) atomlist.add(a);
    Universe universe = new Universe(atomlist);
    TupleFactory factory = universe.factory();
    Bounds bounds = new Bounds(universe);
    for (int i = -8; i <= 7; i++) bounds.boundExactly(i, factory.setOf(String.valueOf(i)));
    bounds.bound(x, factory.allOf(1));
    Formula f = x.in(Expression.INTS).and(x.some());
    // System.out.println(bounds);
    Solver solver = new Solver();
    // solver.options().setSolver(SATFactory.ZChaff);
    solver.options().setSolver(SATFactory.DefaultSAT4J);
    solver.options().setBitwidth(4);
    solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT);
    Solution sol;
    try {
        sol = solver.solve(f, bounds);
        assertNotNull(sol.instance());
    } catch (HigherOrderDeclException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (UnboundLeafException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : Solver(kodkod.engine.Solver) UnboundLeafException(kodkod.engine.fol2sat.UnboundLeafException) Bounds(kodkod.instance.Bounds) ArrayList(java.util.ArrayList) TupleFactory(kodkod.instance.TupleFactory) Universe(kodkod.instance.Universe) Formula(kodkod.ast.Formula) Relation(kodkod.ast.Relation) HigherOrderDeclException(kodkod.engine.fol2sat.HigherOrderDeclException) Solution(kodkod.engine.Solution)

Aggregations

Universe (kodkod.instance.Universe)83 Bounds (kodkod.instance.Bounds)79 TupleFactory (kodkod.instance.TupleFactory)77 TupleSet (kodkod.instance.TupleSet)50 ArrayList (java.util.ArrayList)46 Relation (kodkod.ast.Relation)45 Formula (kodkod.ast.Formula)37 Solution (kodkod.engine.Solution)32 Solver (kodkod.engine.Solver)26 Variable (kodkod.ast.Variable)21 Expression (kodkod.ast.Expression)20 IntExpression (kodkod.ast.IntExpression)20 Instance (kodkod.instance.Instance)14 Decls (kodkod.ast.Decls)11 Evaluator (kodkod.engine.Evaluator)9 LinkedList (java.util.LinkedList)4 Tuple (kodkod.instance.Tuple)4 LinkedHashSet (java.util.LinkedHashSet)3 Map (java.util.Map)2 Set (java.util.Set)2