Search in sources :

Example 51 with Variable

use of kodkod.ast.Variable 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 52 with Variable

use of kodkod.ast.Variable 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 53 with Variable

use of kodkod.ast.Variable 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 54 with Variable

use of kodkod.ast.Variable 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 55 with Variable

use of kodkod.ast.Variable in project org.alloytools.alloy by AlloyTools.

the class TranslatorTest method testTranslateProjection.

public final void testTranslateProjection() {
    assertTrue(isSatisfiable(r3[0].eq(r2[0].project(IntConstant.constant(0), IntConstant.constant(1), IntConstant.constant(0)))));
    assertTrue(isSatisfiable(r2[1].in(r3[0].project(r1[3].count(), r1[2].count()))));
    final Variable v = Variable.nary("r", 2);
    assertFalse(isSatisfiable(v.transpose().eq(v.project(IntConstant.constant(1), IntConstant.constant(0))).not().forSome(v.setOf(r2[0]))));
    bounds.boundExactly(r3[0], bounds.upperBound(r3[0]));
    bounds.boundExactly(r2[0], bounds.upperBound(r2[0]));
    assertTrue(isSatisfiable(r3[0].project(IntConstant.constant(0), IntConstant.constant(1)).eq(r2[0])));
    assertTrue(isSatisfiable(r3[0].project(IntConstant.constant(0), IntConstant.constant(4), IntConstant.constant(2)).eq(Expression.NONE.product(Expression.NONE).product(Expression.NONE))));
    assertTrue(isSatisfiable(r3[0].project(IntConstant.constant(0), IntConstant.constant(-1), IntConstant.constant(2)).eq(Expression.NONE.product(Expression.NONE).product(Expression.NONE))));
}
Also used : Variable(kodkod.ast.Variable)

Aggregations

Variable (kodkod.ast.Variable)221 Formula (kodkod.ast.Formula)151 Expression (kodkod.ast.Expression)80 Decls (kodkod.ast.Decls)24 Solution (kodkod.engine.Solution)24 Relation (kodkod.ast.Relation)23 IntExpression (kodkod.ast.IntExpression)22 Bounds (kodkod.instance.Bounds)21 Universe (kodkod.instance.Universe)21 ArrayList (java.util.ArrayList)19 TupleFactory (kodkod.instance.TupleFactory)19 TupleSet (kodkod.instance.TupleSet)15 Solver (kodkod.engine.Solver)14 Decl (kodkod.ast.Decl)12 QuantifiedFormula (kodkod.ast.QuantifiedFormula)10 Test (org.junit.Test)10 Instance (kodkod.instance.Instance)8 BinaryExpression (kodkod.ast.BinaryExpression)5 SumExpression (kodkod.ast.SumExpression)3 Expr (edu.mit.csail.sdg.ast.Expr)2