Search in sources :

Example 31 with Bounds

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

the class BugTests method testVincent_02182006.

public final void testVincent_02182006() {
    // 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();
    final Relation oneRel = Relation.unary("oneRel");
    final Relation pCourses = Relation.binary("pCourses");
    final Relation prev = Relation.binary("prev");
    final Relation sCourses = Relation.binary("sCourses");
    final Relation prereqs = Relation.binary("prereqs");
    final Relation semester = Relation.unary("Semester");
    final Relation course = Relation.unary("Course");
    final Relation prereqset = Relation.unary("PrereqSet");
    final int courseIndex = 0;
    final int courseScope = 254;
    final int semesterIndex = 254;
    final int semesterScope = 2;
    final int prereqsetIndex = 256;
    final int prereqsetScope = 1;
    bounds.bound(course, factory.range(factory.tuple(atoms.get(courseIndex)), factory.tuple(atoms.get(courseIndex + courseScope - 1))));
    bounds.bound(semester, factory.range(factory.tuple(atoms.get(semesterIndex)), factory.tuple(atoms.get(semesterIndex + semesterScope - 1))));
    bounds.bound(prereqset, factory.range(factory.tuple(atoms.get(prereqsetIndex)), factory.tuple(atoms.get(prereqsetIndex + prereqsetScope - 1))));
    bounds.bound(oneRel, factory.setOf(factory.tuple(atoms.get(0))), factory.setOf(factory.tuple(atoms.get(0))));
    // list1 = [256, 2]
    // list2 = [256, 3]
    // pCoursesTS = [ [256, 2], [256, 3] ]
    List<Integer> list1 = new ArrayList<Integer>();
    list1.add(atoms.get(256));
    list1.add(atoms.get(1));
    List<Integer> list2 = new ArrayList<Integer>();
    list2.add(atoms.get(256));
    list2.add(atoms.get(2));
    TupleSet pCoursesTS = factory.setOf(factory.tuple(list1), factory.tuple(list2));
    bounds.bound(pCourses, pCoursesTS, pCoursesTS);
    // prevTS = [ [255, 254] ]
    TupleSet prevTS = factory.setOf(factory.tuple((Object) atoms.get(255), (Object) atoms.get(254)));
    bounds.bound(prev, prevTS, prevTS);
    // sCourses can be anything from Semester -> Course
    bounds.bound(sCourses, factory.area(factory.tuple((Object) atoms.get(semesterIndex), (Object) atoms.get(courseIndex)), factory.tuple((Object) atoms.get(semesterIndex + semesterScope - 1), (Object) atoms.get(courseIndex + courseScope - 1))));
    // pCoursesTS = [ [0, 256] ]
    TupleSet prereqsTS = factory.setOf(factory.tuple((Object) atoms.get(0), (Object) atoms.get(256)));
    bounds.bound(prereqs, prereqsTS, prereqsTS);
    // all s: futureSemesters | all c: s.courses | no c.prereqs or some p:
    // c.prereqs | p.courses in s.prev^.courses
    final Variable s = Variable.unary("s"), c = Variable.unary("c"), p = Variable.unary("p");
    Formula formula = (p.join(pCourses).in(s.join(prev.closure()).join(sCourses)).forAll(p.oneOf(c.join(prereqs)))).forAll(c.oneOf(s.join(sCourses))).forAll(s.oneOf(semester));
    // System.out.println(formula);
    final Instance instance = solver.solve(formula, bounds).instance();
    assertNotNull(instance);
}
Also used : TupleSet(kodkod.instance.TupleSet) Variable(kodkod.ast.Variable) Instance(kodkod.instance.Instance) Bounds(kodkod.instance.Bounds) ArrayList(java.util.ArrayList) TupleFactory(kodkod.instance.TupleFactory) Universe(kodkod.instance.Universe) Formula(kodkod.ast.Formula) Relation(kodkod.ast.Relation)

Example 32 with Bounds

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

the class BugTests method testEmina_05072008.

public final void testEmina_05072008() {
    Relation A = Relation.unary("A"), first = Relation.unary("OrdFirst"), last = Relation.unary("OrdLast"), next = Relation.nary("OrdNext", 2);
    Relation B = Relation.unary("B"), acyclic = Relation.binary("acyclic");
    List<String> atomlist = Arrays.asList("A1", "A2", "A3", "B1", "B2", "B3", "C1", "C2");
    Universe universe = new Universe(atomlist);
    TupleFactory factory = universe.factory();
    Bounds bounds = new Bounds(universe);
    TupleSet allA = factory.setOf("A1", "A2", "A3");
    TupleSet allB = factory.setOf("B1", "B2", "B3");
    TupleSet allC = factory.setOf("C1", "C2");
    bounds.boundExactly(A, allA);
    bounds.bound(first, allA);
    bounds.bound(last, allA);
    bounds.bound(next, allA.product(allA));
    bounds.boundExactly(B, allB);
    bounds.bound(acyclic, allC.product(allC));
    Variable v = Variable.unary("v");
    Formula f0 = Formula.TRUE.forSome(v.setOf(B));
    Formula f1 = next.totalOrder(A, first, last);
    Formula f2 = acyclic.acyclic();
    Formula form = f0.and(f1).and(f2);
    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);
    int i = 1;
    while (sol.hasNext()) {
        assertTrue(i <= 17);
        sol.next();
        i++;
    }
}
Also used : TupleSet(kodkod.instance.TupleSet) Solver(kodkod.engine.Solver) Variable(kodkod.ast.Variable) Bounds(kodkod.instance.Bounds) TupleFactory(kodkod.instance.TupleFactory) Universe(kodkod.instance.Universe) Formula(kodkod.ast.Formula) Relation(kodkod.ast.Relation) Solution(kodkod.engine.Solution)

Example 33 with Bounds

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

the class BugTests method testEmina_10092006.

public final void testEmina_10092006() {
    Relation r = Relation.ternary("r");
    final Variable a = Variable.unary("A");
    final Variable b = Variable.unary("B");
    final Variable c = Variable.unary("C");
    final Variable d = Variable.unary("D");
    final Formula f0 = (b.join(a.join(r))).eq(d.join(c.join(r)));
    final Formula f1 = a.in(c).and(b.in(d));
    final Formula f = f0.implies(f1).forAll(a.oneOf(UNIV).and(b.oneOf(UNIV)).and(c.oneOf(UNIV)).and(d.oneOf(UNIV)));
    final Universe u = new Universe(Arrays.asList("a0", "a1"));
    final Bounds bounds = new Bounds(u);
    bounds.bound(r, u.factory().allOf(3));
    // System.out.println(f); System.out.println(bounds);
    solver.options().setSymmetryBreaking(0);
    // solver.options().setFlatten(false);
    final Solution s = solver.solve(f, bounds);
    // System.out.println(s);
    assertEquals(Solution.Outcome.SATISFIABLE, s.outcome());
}
Also used : Formula(kodkod.ast.Formula) Relation(kodkod.ast.Relation) Variable(kodkod.ast.Variable) Bounds(kodkod.instance.Bounds) Universe(kodkod.instance.Universe) Solution(kodkod.engine.Solution)

Example 34 with Bounds

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

the class BugTests method testFelix_10272008.

public final void testFelix_10272008() {
    Relation x0 = Relation.unary("Int/min");
    Relation x1 = Relation.unary("Int/zero");
    Relation x2 = Relation.unary("Int/max");
    Relation x3 = Relation.nary("Int/next", 2);
    Relation x4 = Relation.unary("seq/Int");
    Relation x5 = Relation.unary("this/X");
    List<String> atomlist = Arrays.asList("-1", "-2", "-3", "-4", "-5", "-6", "-7", "-8", "0", "1", "2", "3", "4", "5", "6", "7", "unused0", "unused1", "unused2");
    Universe universe = new Universe(atomlist);
    TupleFactory factory = universe.factory();
    Bounds bounds = new Bounds(universe);
    TupleSet x0_upper = factory.noneOf(1);
    x0_upper.add(factory.tuple("-8"));
    bounds.boundExactly(x0, x0_upper);
    TupleSet x1_upper = factory.noneOf(1);
    x1_upper.add(factory.tuple("0"));
    bounds.boundExactly(x1, x1_upper);
    TupleSet x2_upper = factory.noneOf(1);
    x2_upper.add(factory.tuple("7"));
    bounds.boundExactly(x2, x2_upper);
    TupleSet x3_upper = factory.noneOf(2);
    x3_upper.add(factory.tuple("-8").product(factory.tuple("-7")));
    x3_upper.add(factory.tuple("-7").product(factory.tuple("-6")));
    x3_upper.add(factory.tuple("-6").product(factory.tuple("-5")));
    x3_upper.add(factory.tuple("-5").product(factory.tuple("-4")));
    x3_upper.add(factory.tuple("-4").product(factory.tuple("-3")));
    x3_upper.add(factory.tuple("-3").product(factory.tuple("-2")));
    x3_upper.add(factory.tuple("-2").product(factory.tuple("-1")));
    x3_upper.add(factory.tuple("-1").product(factory.tuple("0")));
    x3_upper.add(factory.tuple("0").product(factory.tuple("1")));
    x3_upper.add(factory.tuple("1").product(factory.tuple("2")));
    x3_upper.add(factory.tuple("2").product(factory.tuple("3")));
    x3_upper.add(factory.tuple("3").product(factory.tuple("4")));
    x3_upper.add(factory.tuple("4").product(factory.tuple("5")));
    x3_upper.add(factory.tuple("5").product(factory.tuple("6")));
    x3_upper.add(factory.tuple("6").product(factory.tuple("7")));
    bounds.boundExactly(x3, x3_upper);
    TupleSet x4_upper = factory.noneOf(1);
    x4_upper.add(factory.tuple("0"));
    x4_upper.add(factory.tuple("1"));
    x4_upper.add(factory.tuple("2"));
    x4_upper.add(factory.tuple("3"));
    bounds.boundExactly(x4, x4_upper);
    TupleSet x5_upper = factory.noneOf(1);
    x5_upper.add(factory.tuple("unused0"));
    x5_upper.add(factory.tuple("unused1"));
    x5_upper.add(factory.tuple("unused2"));
    bounds.bound(x5, x5_upper);
    bounds.boundExactly(-8, factory.range(factory.tuple("-8"), factory.tuple("-8")));
    bounds.boundExactly(-7, factory.range(factory.tuple("-7"), factory.tuple("-7")));
    bounds.boundExactly(-6, factory.range(factory.tuple("-6"), factory.tuple("-6")));
    bounds.boundExactly(-5, factory.range(factory.tuple("-5"), factory.tuple("-5")));
    bounds.boundExactly(-4, factory.range(factory.tuple("-4"), factory.tuple("-4")));
    bounds.boundExactly(-3, factory.range(factory.tuple("-3"), factory.tuple("-3")));
    bounds.boundExactly(-2, factory.range(factory.tuple("-2"), factory.tuple("-2")));
    bounds.boundExactly(-1, factory.range(factory.tuple("-1"), factory.tuple("-1")));
    bounds.boundExactly(0, factory.range(factory.tuple("0"), factory.tuple("0")));
    bounds.boundExactly(1, factory.range(factory.tuple("1"), factory.tuple("1")));
    bounds.boundExactly(2, factory.range(factory.tuple("2"), factory.tuple("2")));
    bounds.boundExactly(3, factory.range(factory.tuple("3"), factory.tuple("3")));
    bounds.boundExactly(4, factory.range(factory.tuple("4"), factory.tuple("4")));
    bounds.boundExactly(5, factory.range(factory.tuple("5"), factory.tuple("5")));
    bounds.boundExactly(6, factory.range(factory.tuple("6"), factory.tuple("6")));
    bounds.boundExactly(7, factory.range(factory.tuple("7"), factory.tuple("7")));
    Variable x11 = Variable.unary("c");
    Expression x12 = x5.difference(x5);
    Decls x10 = x11.oneOf(x12);
    IntExpression x13 = IntConstant.constant(0);
    IntExpression x9 = x13.sum(x10);
    IntExpression x14 = IntConstant.constant(0);
    Formula x8 = x9.eq(x14);
    Formula x17 = x0.eq(x0);
    Formula x18 = x2.eq(x2);
    Formula x16 = x17.and(x18);
    Formula x19 = x3.eq(x3);
    Formula x15 = x16.and(x19);
    Formula x7 = x8.and(x15);
    Formula x22 = x1.eq(x1);
    Formula x23 = x4.eq(x4);
    Formula x21 = x22.and(x23);
    Formula x24 = x5.eq(x5);
    Formula x20 = x21.and(x24);
    Formula x6 = x7.and(x20);
    Solver solver = new Solver();
    solver.options().setSolver(SATFactory.DefaultSAT4J);
    solver.options().setBitwidth(4);
    // solver.options().setFlatten(false);
    solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT);
    solver.options().setSymmetryBreaking(20);
    solver.options().setSkolemDepth(0);
    Solution sol = solver.solve(x6, bounds);
    assertEquals(sol.outcome(), Solution.Outcome.TRIVIALLY_SATISFIABLE);
}
Also used : TupleSet(kodkod.instance.TupleSet) Solver(kodkod.engine.Solver) Variable(kodkod.ast.Variable) Decls(kodkod.ast.Decls) Bounds(kodkod.instance.Bounds) IntExpression(kodkod.ast.IntExpression) 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 35 with Bounds

use of kodkod.instance.Bounds 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)

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