Search in sources :

Example 21 with TupleFactory

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

the class BugTests method testFelix_05152007_3.

public final void testFelix_05152007_3() {
    Relation x5 = Relation.nary("A", 1);
    List<String> atomlist = Arrays.asList("A[0]", "A[1]", "A[2]");
    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("A[0]"));
    x5_upper.add(factory.tuple("A[1]"));
    x5_upper.add(factory.tuple("A[2]"));
    bounds.bound(x5, x5_upper);
    Formula a = x5.some();
    Formula a1 = x5.no();
    Formula b = a1.and(Formula.TRUE.and(Formula.TRUE));
    Formula c = a.and(b);
    Solver solver = new Solver();
    solver.options().setLogTranslation(1);
    solver.options().setSolver(SATFactory.DefaultSAT4J);
    solver.options().setBitwidth(4);
    solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT);
    Solution sol = solver.solve(c, bounds);
    Set<Formula> core = Nodes.minRoots(c, sol.proof().highLevelCore().values());
    assertEquals(2, core.size());
    assertTrue(core.contains(a));
    assertTrue(core.contains(a1));
}
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 22 with TupleFactory

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

the class IntTest method testBitsetCast.

public void testBitsetCast() {
    final int width = 4, msb = width - 1;
    solver.options().setBitwidth(width);
    final List<Integer> atoms = new ArrayList<Integer>(width);
    for (int i = 0; i < msb; i++) {
        atoms.add(Integer.valueOf(1 << i));
    }
    atoms.add(Integer.valueOf(-1 << msb));
    final Bounds b = new Bounds(new Universe(atoms));
    final TupleFactory f = b.universe().factory();
    for (Integer i : atoms) {
        b.boundExactly(i, f.setOf(i));
    }
    b.bound(r1, f.allOf(1));
    for (int i = -1 << msb, max = 1 << msb; i < max; i++) {
        Formula test = r1.sum().toBitset().eq(IntConstant.constant(i).toBitset());
        Solution sol = solver.solve(test, b);
        Instance inst = sol.instance();
        assertNotNull(inst);
        Evaluator eval = new Evaluator(inst, solver.options());
        assertEquals(i, eval.evaluate(r1.sum()));
    }
}
Also used : Formula(kodkod.ast.Formula) Instance(kodkod.instance.Instance) Bounds(kodkod.instance.Bounds) ArrayList(java.util.ArrayList) TupleFactory(kodkod.instance.TupleFactory) Universe(kodkod.instance.Universe) Evaluator(kodkod.engine.Evaluator) Solution(kodkod.engine.Solution)

Example 23 with TupleFactory

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

the class BugTests method testFelix_05152007_2.

public final void testFelix_05152007_2() {
    Relation x5 = Relation.nary("A", 1);
    List<String> atomlist = Arrays.asList("A0", "A1", "A2");
    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("A2"));
    x5_upper.add(factory.tuple("A1"));
    x5_upper.add(factory.tuple("A0"));
    bounds.bound(x5, x5_upper);
    Formula x7 = x5.eq(x5).not();
    Solver solver = new Solver();
    solver.options().setLogTranslation(1);
    solver.options().setSolver(SATFactory.MiniSatProver);
    solver.options().setBitwidth(4);
    solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT);
    Solution sol = solver.solve(x7, bounds);
    Set<Formula> core = Nodes.minRoots(x7, sol.proof().highLevelCore().values());
    assertEquals(1, core.size());
    assertTrue(core.contains(x7));
}
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 24 with TupleFactory

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

the class BugTests method testMana_01132006.

public final void testMana_01132006() {
    // r0=[[], [[null], [DblLinkedList0]]],
    // null=[[[null]], [[null]]],
    // head=[[], [[DblLinkedList0, null], [DblLinkedList0,
    // DblLinkedListElem0]]],
    // next=[[], [[DblLinkedListElem0, null], [DblLinkedListElem0,
    // DblLinkedListElem0]]],
    // univ=[[[null], [DblLinkedList0], [1], [DblLinkedListElem0], [0]],
    // [[null], [DblLinkedList0], [1], [DblLinkedListElem0], [0]]]
    // r1=[[], [[null], [DblLinkedListElem0]]],
    final List<String> atoms = new ArrayList<String>(5);
    atoms.add("null");
    atoms.add("DblLinkedList0");
    atoms.add("1");
    atoms.add("DblLinkedListElem0");
    atoms.add("0");
    final Universe u = new Universe(atoms);
    final TupleFactory t = u.factory();
    // !((head . univ) in ((if (r1 in null) then (head ++ (r0 -> (r1 .
    // next))) else head) . univ))
    final Relation head = Relation.binary("head"), univ = Relation.unary("univ"), r0 = Relation.unary("r0"), r1 = Relation.unary("r1"), next = Relation.binary("next"), nil = Relation.unary("null"), none = Relation.unary("none");
    final Expression override = head.override(r0.product(r1.join(next)));
    final Expression ifElse = r1.in(nil).thenElse(override, head);
    final Formula f = head.join(univ).in(ifElse.join(univ)).not();
    final Bounds b = new Bounds(u);
    b.bound(r0, t.setOf("null", "DblLinkedList0"));
    b.bound(r1, t.setOf("null", "DblLinkedListElem0"));
    b.bound(head, t.setOf("DblLinkedList0").product(b.upperBound(r1)));
    b.bound(next, t.setOf(t.tuple("DblLinkedListElem0", "null"), t.tuple("DblLinkedListElem0", "DblLinkedListElem0")));
    b.boundExactly(univ, t.allOf(1));
    b.boundExactly(nil, t.setOf("null"));
    b.boundExactly(none, t.noneOf(1));
    // System.out.println(f);
    // System.out.println(b);
    final Instance instance = solver.solve(f, b).instance();
    assertNull(instance);
}
Also used : Formula(kodkod.ast.Formula) Relation(kodkod.ast.Relation) IntExpression(kodkod.ast.IntExpression) Expression(kodkod.ast.Expression) Instance(kodkod.instance.Instance) Bounds(kodkod.instance.Bounds) ArrayList(java.util.ArrayList) TupleFactory(kodkod.instance.TupleFactory) Universe(kodkod.instance.Universe)

Example 25 with TupleFactory

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

the class BugTests method testVincent_03182006_reduced.

public final void testVincent_03182006_reduced() {
    final Relation pCourses = Relation.binary("pCourses"), prereqs = Relation.binary("prereqs");
    final List<String> atoms = new ArrayList<String>(14);
    atoms.add("6.002");
    atoms.add("8.02");
    atoms.add("6.003");
    atoms.add("6.001");
    atoms.add("[8.02]");
    atoms.add("[6.001]");
    atoms.add("[]");
    final Universe u = new Universe(atoms);
    final Bounds b = new Bounds(u);
    final TupleFactory f = u.factory();
    b.bound(pCourses, f.setOf(f.tuple("[8.02]", "8.02"), f.tuple("[6.001]", "6.001")));
    b.bound(prereqs, f.setOf(f.tuple("6.002", "[8.02]"), f.tuple("8.02", "[]"), f.tuple("6.003", "[6.001]"), f.tuple("6.001", "[]")));
    // System.out.println(u);
    solver.options().setSolver(SATFactory.DefaultSAT4J);
    Solution solution = solver.solve((pCourses.some()).and(prereqs.some()), b);
    // System.out.println(solution); // SATISFIABLE
    assertEquals(solution.outcome(), Solution.Outcome.SATISFIABLE);
}
Also used : Relation(kodkod.ast.Relation) Bounds(kodkod.instance.Bounds) ArrayList(java.util.ArrayList) TupleFactory(kodkod.instance.TupleFactory) Universe(kodkod.instance.Universe) Solution(kodkod.engine.Solution)

Aggregations

TupleFactory (kodkod.instance.TupleFactory)85 Universe (kodkod.instance.Universe)77 Bounds (kodkod.instance.Bounds)76 TupleSet (kodkod.instance.TupleSet)55 ArrayList (java.util.ArrayList)45 Relation (kodkod.ast.Relation)45 Formula (kodkod.ast.Formula)35 Solution (kodkod.engine.Solution)30 Solver (kodkod.engine.Solver)25 IntExpression (kodkod.ast.IntExpression)20 Expression (kodkod.ast.Expression)19 Variable (kodkod.ast.Variable)19 Instance (kodkod.instance.Instance)15 Decls (kodkod.ast.Decls)11 Evaluator (kodkod.engine.Evaluator)9 Tuple (kodkod.instance.Tuple)8 LinkedList (java.util.LinkedList)4 LinkedHashSet (java.util.LinkedHashSet)3 Map (java.util.Map)2 Set (java.util.Set)2