Search in sources :

Example 26 with Universe

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

the class BugTests method testVincent_02162006.

public final void testVincent_02162006() {
    // set ups universe of atoms [1..257]
    final List<Integer> atoms = new ArrayList<Integer>();
    // change this to 256, and the program works
    for (int i = 0; i < 257; i++) {
        atoms.add(i + 1);
    }
    final Universe universe = new Universe(atoms);
    final Bounds bounds = new Bounds(universe);
    final TupleFactory factory = universe.factory();
    // oneRel is bounded to the Integer 1
    final Relation oneRel = Relation.unary("oneRel");
    // rel can contain anything
    final Relation rel = Relation.unary("rel");
    bounds.bound(oneRel, factory.setOf(factory.tuple(atoms.get(0))), factory.setOf(factory.tuple(atoms.get(0))));
    bounds.bound(rel, factory.allOf(1));
    // constraint: oneRel in rel
    Formula formula = oneRel.in(rel);
    // solve
    final Instance instance = solver.solve(formula, bounds).instance();
    assertNotNull(instance);
// System.out.println(instance);
}
Also used : Formula(kodkod.ast.Formula) Relation(kodkod.ast.Relation) Instance(kodkod.instance.Instance) Bounds(kodkod.instance.Bounds) ArrayList(java.util.ArrayList) TupleFactory(kodkod.instance.TupleFactory) Universe(kodkod.instance.Universe)

Example 27 with Universe

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

the class BugTests method testFelix_03062008_2.

public final void testFelix_03062008_2() {
    Relation x5 = Relation.unary("Role");
    Relation x6 = Relation.unary("Session");
    List<String> atomlist = Arrays.asList("Role$0", "Session$0", "Session$1");
    Universe universe = new Universe(atomlist);
    TupleFactory factory = universe.factory();
    Bounds bounds = new Bounds(universe);
    TupleSet x5_upper = factory.noneOf(1);
    x5_upper.add(factory.tuple("Role$0"));
    bounds.bound(x5, x5_upper);
    TupleSet x6_upper = factory.noneOf(1);
    x6_upper.add(factory.tuple("Session$0"));
    x6_upper.add(factory.tuple("Session$1"));
    bounds.bound(x6, x6_upper);
    Variable x11 = Variable.unary("x_a");
    Decls x10 = x11.oneOf(x6);
    Variable x15 = Variable.unary("x_b");
    Decls x14 = x15.oneOf(x5);
    Variable x17 = Variable.unary("x_c");
    Decls x16 = x17.oneOf(x5);
    Decls x13 = x14.and(x16);
    Expression x20 = x15.product(x17);
    Expression x19 = x11.product(x20);
    Formula x18 = x19.some();
    Formula x12 = x18.forSome(x13);
    Formula x9 = x12.forAll(x10);
    Formula x24 = x5.some();
    Formula x23 = x24.not();
    Formula x28 = x5.eq(x5);
    Formula x29 = x6.eq(x6);
    Formula x25 = x28.and(x29);
    Formula x22 = x23.and(x25);
    Formula x8 = x9.and(x22).and(x5.no()).and(x6.no());
    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(2);
    System.out.flush();
    Solution sol = solver.solve(x8, bounds);
    Instance inst = sol.instance();
    assertNotNull(inst);
    for (Relation rel : inst.relations()) {
        if (rel != x5 && rel != x6) {
            final TupleSet range = inst.tuples(x6).product(inst.tuples(x5));
            assertTrue(range.containsAll(inst.tuples(rel)));
        }
    }
}
Also used : TupleSet(kodkod.instance.TupleSet) Solver(kodkod.engine.Solver) Variable(kodkod.ast.Variable) Decls(kodkod.ast.Decls) Instance(kodkod.instance.Instance) Bounds(kodkod.instance.Bounds) TupleFactory(kodkod.instance.TupleFactory) Universe(kodkod.instance.Universe) Formula(kodkod.ast.Formula) Relation(kodkod.ast.Relation) IntExpression(kodkod.ast.IntExpression) Expression(kodkod.ast.Expression) Solution(kodkod.engine.Solution)

Example 28 with Universe

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

the class BugTests method testFelix_01062007.

public final void testFelix_01062007() {
    Relation x1 = Relation.nary("A", 1);
    List<String> atomlist = Arrays.asList("A");
    Universe universe = new Universe(atomlist);
    TupleFactory factory = universe.factory();
    Bounds bounds = new Bounds(universe);
    TupleSet x1_upper = factory.noneOf(1);
    x1_upper.add(factory.tuple("A"));
    bounds.bound(x1, x1_upper);
    Solver solver = new Solver();
    solver.options().setSolver(SATFactory.MiniSat);
    Iterator<Solution> sols = solver.solveAll(Formula.TRUE, bounds);
    assertNotNull(sols.next().instance());
    assertNotNull(sols.next().instance());
    assertNull(sols.next().instance());
// Solution sol1=sols.next();
// System.out.println("Solution1:"+sol1.instance());
// 
// Solution sol2=sols.next();
// System.out.println("Solution2:"+sol2.instance());
// 
// Solution sol3=sols.next();
// System.out.println("Solution3:"+sol3.instance());
}
Also used : TupleSet(kodkod.instance.TupleSet) 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 29 with Universe

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

the class BugTests method testFelix_05072008.

public final void testFelix_05072008() {
    Relation A = Relation.unary("A"), first = Relation.unary("OrdFirst"), last = Relation.unary("OrdLast"), next = Relation.nary("OrdNext", 2);
    List<String> atomlist = Arrays.asList("A1", "A2", "A3");
    Universe universe = new Universe(atomlist);
    TupleFactory factory = universe.factory();
    Bounds bounds = new Bounds(universe);
    TupleSet all = factory.setOf("A1", "A2", "A3");
    bounds.boundExactly(A, all);
    bounds.bound(first, all);
    bounds.bound(last, all);
    bounds.bound(next, all.product(all));
    Formula form = next.totalOrder(A, first, last);
    Solver solver = new Solver();
    solver.options().setSolver(SATFactory.MiniSat);
    solver.options().setBitwidth(4);
    // solver.options().setFlatten(false);
    solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT);
    solver.options().setSymmetryBreaking(0);
    solver.options().setSkolemDepth(0);
    Iterator<Solution> sol = solver.solveAll(form, bounds);
    assertTrue(sol.hasNext());
    assertEquals(sol.next().outcome(), Solution.Outcome.TRIVIALLY_SATISFIABLE);
    assertTrue(sol.hasNext());
    assertEquals(sol.next().outcome(), Solution.Outcome.TRIVIALLY_UNSATISFIABLE);
    assertFalse(sol.hasNext());
// int i=1;
// 
// while (sol.hasNext()) {
// System.out.println("================================== "+i+"
// ===================================");
// System.out.println(sol.next());
// System.out.flush();
// i++;
// }
}
Also used : TupleSet(kodkod.instance.TupleSet) 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 30 with Universe

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

the class EvaluatorTest method testEvalTransitiveClosure.

public final void testEvalTransitiveClosure() {
    // // ^(Hilary->Jocelyn) = Hilary->Jocelyn
    // assertEquals(eval(hilary.product(jocelyn).closure()),
    // eval(hilary.product(jocelyn)));
    // // ^spouse = spouse + spouse.spouse
    // assertEquals(eval(spouse.closure()),
    // eval(spouse.union(spouse.join(spouse))));
    // // Hilary.^shaken = univ - (univ - Person.shaken)
    // assertEquals(eval(hilary.join(shaken.closure())),
    // eval(univ.difference(univ.difference(person.join(shaken)))));
    // try {
    // eval(person.closure());
    // fail("Expected IllegalArgumentException");
    // } catch (IllegalArgumentException iae) {}
    // ^r = value(^r)
    final Relation r = Relation.binary("r");
    final Universe u = evaluator.instance().universe();
    final TupleFactory f = u.factory();
    final Instance instance = new Instance(u);
    // value(r) = u[0]->u[1] + u[1]->u[2] + u[2]->u[3] + u[3]->u[4]
    TupleSet s = f.noneOf(r.arity());
    for (int i = 0; i < 4; i++) s.add(f.tuple(u.atom(i), u.atom(i + 1)));
    instance.add(r, s);
    // value(^r) = value(r) + u[0]->u[2] + u[0]->u[3] + u[0]->u[4] +
    // u[1]->u[3] u[1]->u[4] + u[2]->u[4]
    Set<Tuple> result = new HashSet<Tuple>();
    for (int i = 0; i < 4; i++) {
        for (int j = i + 1; j < 5; j++) {
            result.add(f.tuple(u.atom(i), u.atom(j)));
        }
    }
    assertEquals((new Evaluator(instance)).evaluate(r.closure()), result);
    // value(*r) = value(^r) + iden
    for (int i = 0; i < 10; i++) {
        result.add(f.tuple(u.atom(i), u.atom(i)));
    }
    assertEquals((new Evaluator(instance)).evaluate(r.reflexiveClosure()), result);
}
Also used : TupleSet(kodkod.instance.TupleSet) Relation(kodkod.ast.Relation) Instance(kodkod.instance.Instance) TupleFactory(kodkod.instance.TupleFactory) Universe(kodkod.instance.Universe) Evaluator(kodkod.engine.Evaluator) Tuple(kodkod.instance.Tuple) HashSet(java.util.HashSet)

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