Search in sources :

Example 81 with Relation

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

the class BugTests method testVincent_03182006.

public final void testVincent_03182006() {
    final Relation cAttributes = Relation.binary("cAttributes"), Int = Relation.unary("Integer"), c6001 = Relation.unary("6.001"), one = Relation.unary("ONE"), prereqsetUsed = Relation.binary("prereqsetUsed"), Course = Relation.unary("Course"), CardinalityGrouping = Relation.unary("CardinalityGrouping"), pCourses = Relation.binary("pCourses"), dec = Relation.binary("dec"), c6002 = Relation.unary("6.002"), greater = Relation.binary("greater"), size = Relation.binary("size"), less = Relation.binary("less"), sAttributes = Relation.binary("sAttributes"), PrereqSet = Relation.unary("PrereqSet"), inc = Relation.binary("inc"), next = Relation.binary("next"), equal = Relation.binary("equal"), Semester = Relation.unary("Semester"), index = Relation.ternary("index"), sCourses = Relation.binary("sCourses"), prev = Relation.binary("prev"), prereqs = Relation.binary("prereqs");
    // [6.002, 8.02, 6.003, 6.001, Spring 2006, Fall 2006, [8.02], [6.001],
    // [], Spring, Even, Fall, 1, 2]
    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("Spring 2006");
    atoms.add("Fall 2006");
    atoms.add("[8.02]");
    atoms.add("[6.001]");
    atoms.add("[]");
    atoms.add("Spring");
    atoms.add("Even");
    atoms.add("Fall");
    atoms.add("1");
    atoms.add("2");
    final Universe u = new Universe(atoms);
    final Bounds b = new Bounds(u);
    final TupleFactory f = u.factory();
    b.bound(cAttributes, f.noneOf(2));
    b.boundExactly(Int, f.range(f.tuple("1"), f.tuple("2")));
    b.boundExactly(c6001, f.setOf(f.tuple("6.001")));
    b.boundExactly(one, f.setOf(f.tuple("1")));
    b.bound(prereqsetUsed, f.setOf(f.tuple("6.002", "[8.02]"), f.tuple("8.02", "[]"), f.tuple("6.003", "[6.001]"), f.tuple("6.001", "[]")));
    b.bound(Course, f.range(f.tuple("6.002"), f.tuple("6.001")));
    b.bound(CardinalityGrouping, f.noneOf(1));
    b.boundExactly(pCourses, f.setOf(f.tuple("[8.02]", "8.02"), f.tuple("[6.001]", "6.001")));
    b.boundExactly(dec, f.setOf(f.tuple("2", "1")));
    b.boundExactly(greater, b.upperBound(dec));
    b.bound(size, f.noneOf(2));
    b.boundExactly(c6002, f.setOf(f.tuple("6.002")));
    b.boundExactly(less, f.setOf(f.tuple("1", "2")));
    b.boundExactly(sAttributes, f.setOf(f.tuple("Spring 2006", "Spring"), f.tuple("Spring 2006", "Even"), f.tuple("Fall 2006", "Even"), f.tuple("Fall 2006", "Fall")));
    b.boundExactly(PrereqSet, f.setOf("[8.02]", "[6.001]", "[]"));
    b.boundExactly(inc, b.upperBound(less));
    b.boundExactly(next, f.setOf(f.tuple("Spring 2006", "Fall 2006")));
    b.boundExactly(equal, f.setOf(f.tuple("1", "1"), f.tuple("2", "2")));
    b.boundExactly(Semester, f.setOf("Spring 2006", "Fall 2006"));
    b.bound(index, f.noneOf(3));
    b.bound(sCourses, f.range(f.tuple("Spring 2006"), f.tuple("Fall 2006")).product(f.range(f.tuple("6.002"), f.tuple("6.001"))));
    b.boundExactly(prev, f.setOf(f.tuple("Fall 2006", "Spring 2006")));
    b.boundExactly(prereqs, f.setOf(f.tuple("6.002", "[8.02]"), f.tuple("8.02", "[]"), f.tuple("6.003", "[6.001]"), f.tuple("6.001", "[]")));
    // for(Relation r : b.relations()) {
    // System.out.println(r + " " + r.arity() + " " + b.lowerBound(r) + " ;
    // " + b.upperBound(r));
    // }
    // System.out.println(u);
    final Formula f0 = sCourses.in(Semester.product(Course));
    final Formula f1 = size.function(CardinalityGrouping, Int);
    final Formula f2 = prereqsetUsed.function(Semester.join(sCourses), PrereqSet);
    final Formula f3 = prereqsetUsed.in(prereqs);
    final Variable s = Variable.unary("s");
    final Expression e0 = s.join(sCourses).join(prereqsetUsed).join(pCourses);
    final Expression e1 = s.join(prev.closure()).join(sCourses);
    final Formula f4 = e0.in(e1).forAll(s.oneOf(Semester));
    final Formula f5 = c6002.in(Semester.join(sCourses));
    final Variable e = Variable.unary("e");
    final Expression e3 = Semester.join(sCourses).difference(e);
    final Formula f60 = c6002.in(e3);
    final Formula f61 = e3.join(prereqsetUsed).join(pCourses).in(e3);
    final Formula f6 = (f60.and(f61)).not().forAll(e.oneOf(Semester.join(sCourses)));
    final Variable c = Variable.unary("c");
    final Formula f7 = c.join(cAttributes).in(s.join(sAttributes)).forAll(c.oneOf(s.join(sCourses))).forAll(s.oneOf(Semester));
    final Variable s1 = Variable.unary("s1"), s2 = Variable.unary("s2");
    final Formula f8 = s1.join(sCourses).intersection(s2.join(sCourses)).no().forAll(s2.oneOf(Semester.difference(s1))).forAll(s1.oneOf(Semester));
    final Formula f9 = c6001.intersection(Semester.join(sCourses)).no();
    final Formula x = f0.and(f1).and(f2).and(f3).and(f4).and(f5).and(f6).and(f7).and(f8);
    final Formula y = x.and(f9);
    // System.out.println(x);
    // System.out.println(y);
    solver.options().setSolver(SATFactory.DefaultSAT4J);
    Solution solution = solver.solve(x, b);
    // System.out.println(solution); // SATISFIABLE
    assertEquals(solution.outcome(), Solution.Outcome.SATISFIABLE);
    Solution solution2 = solver.solve(y, b);
    // System.out.println(solution2); // SATISFIABLE!!!???
    // System.out.println((new
    // Evaluator(solution2.instance())).evaluate(x));
    assertEquals(solution2.outcome(), Solution.Outcome.SATISFIABLE);
}
Also used : Formula(kodkod.ast.Formula) Relation(kodkod.ast.Relation) Variable(kodkod.ast.Variable) IntExpression(kodkod.ast.IntExpression) Expression(kodkod.ast.Expression) Bounds(kodkod.instance.Bounds) ArrayList(java.util.ArrayList) TupleFactory(kodkod.instance.TupleFactory) Universe(kodkod.instance.Universe) Solution(kodkod.engine.Solution)

Example 82 with Relation

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

the class BugTests method testGreg_03032006.

public final void testGreg_03032006() {
    Relation r = Relation.binary("r");
    Universe univ = new Universe(Collections.singleton("o"));
    Bounds bounds = new Bounds(univ);
    bounds.bound(r, univ.factory().allOf(2));
    assertEquals(Solution.Outcome.SATISFIABLE, solver.solve(r.some(), bounds).outcome());
}
Also used : Relation(kodkod.ast.Relation) Bounds(kodkod.instance.Bounds) Universe(kodkod.instance.Universe)

Example 83 with Relation

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

the class BugTests method testFelix_05192007.

public final void testFelix_05192007() {
    Relation x5 = Relation.nary("this/de", 1);
    Relation x6 = Relation.nary("this/dir", 1);
    Relation x7 = Relation.nary("this/de.contents", 2);
    Relation x8 = Relation.nary("this/dir.entries", 2);
    Relation x9 = Relation.nary("this/dir.parent", 2);
    List<String> atomlist = Arrays.asList("de[0]", "de[1]", "de[2]", "de[3]", "dir[0]", "dir[1]", "dir[2]", "dir[3]");
    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("de[0]"));
    x5_upper.add(factory.tuple("de[1]"));
    x5_upper.add(factory.tuple("de[2]"));
    x5_upper.add(factory.tuple("de[3]"));
    bounds.bound(x5, x5_upper);
    TupleSet x6_upper = factory.noneOf(1);
    x6_upper.add(factory.tuple("dir[0]"));
    x6_upper.add(factory.tuple("dir[1]"));
    x6_upper.add(factory.tuple("dir[2]"));
    x6_upper.add(factory.tuple("dir[3]"));
    bounds.bound(x6, x6_upper);
    TupleSet x7_upper = factory.noneOf(2);
    x7_upper.add(factory.tuple("de[0]").product(factory.tuple("dir[0]")));
    x7_upper.add(factory.tuple("de[0]").product(factory.tuple("dir[1]")));
    x7_upper.add(factory.tuple("de[0]").product(factory.tuple("dir[2]")));
    x7_upper.add(factory.tuple("de[0]").product(factory.tuple("dir[3]")));
    x7_upper.add(factory.tuple("de[1]").product(factory.tuple("dir[0]")));
    x7_upper.add(factory.tuple("de[1]").product(factory.tuple("dir[1]")));
    x7_upper.add(factory.tuple("de[1]").product(factory.tuple("dir[2]")));
    x7_upper.add(factory.tuple("de[1]").product(factory.tuple("dir[3]")));
    x7_upper.add(factory.tuple("de[2]").product(factory.tuple("dir[0]")));
    x7_upper.add(factory.tuple("de[2]").product(factory.tuple("dir[1]")));
    x7_upper.add(factory.tuple("de[2]").product(factory.tuple("dir[2]")));
    x7_upper.add(factory.tuple("de[2]").product(factory.tuple("dir[3]")));
    x7_upper.add(factory.tuple("de[3]").product(factory.tuple("dir[0]")));
    x7_upper.add(factory.tuple("de[3]").product(factory.tuple("dir[1]")));
    x7_upper.add(factory.tuple("de[3]").product(factory.tuple("dir[2]")));
    x7_upper.add(factory.tuple("de[3]").product(factory.tuple("dir[3]")));
    bounds.bound(x7, x7_upper);
    TupleSet x8_upper = factory.noneOf(2);
    x8_upper.add(factory.tuple("dir[0]").product(factory.tuple("de[0]")));
    x8_upper.add(factory.tuple("dir[0]").product(factory.tuple("de[1]")));
    x8_upper.add(factory.tuple("dir[0]").product(factory.tuple("de[2]")));
    x8_upper.add(factory.tuple("dir[0]").product(factory.tuple("de[3]")));
    x8_upper.add(factory.tuple("dir[1]").product(factory.tuple("de[0]")));
    x8_upper.add(factory.tuple("dir[1]").product(factory.tuple("de[1]")));
    x8_upper.add(factory.tuple("dir[1]").product(factory.tuple("de[2]")));
    x8_upper.add(factory.tuple("dir[1]").product(factory.tuple("de[3]")));
    x8_upper.add(factory.tuple("dir[2]").product(factory.tuple("de[0]")));
    x8_upper.add(factory.tuple("dir[2]").product(factory.tuple("de[1]")));
    x8_upper.add(factory.tuple("dir[2]").product(factory.tuple("de[2]")));
    x8_upper.add(factory.tuple("dir[2]").product(factory.tuple("de[3]")));
    x8_upper.add(factory.tuple("dir[3]").product(factory.tuple("de[0]")));
    x8_upper.add(factory.tuple("dir[3]").product(factory.tuple("de[1]")));
    x8_upper.add(factory.tuple("dir[3]").product(factory.tuple("de[2]")));
    x8_upper.add(factory.tuple("dir[3]").product(factory.tuple("de[3]")));
    bounds.bound(x8, x8_upper);
    TupleSet x9_upper = factory.noneOf(2);
    x9_upper.add(factory.tuple("dir[0]").product(factory.tuple("dir[0]")));
    x9_upper.add(factory.tuple("dir[0]").product(factory.tuple("dir[1]")));
    x9_upper.add(factory.tuple("dir[0]").product(factory.tuple("dir[2]")));
    x9_upper.add(factory.tuple("dir[0]").product(factory.tuple("dir[3]")));
    x9_upper.add(factory.tuple("dir[1]").product(factory.tuple("dir[0]")));
    x9_upper.add(factory.tuple("dir[1]").product(factory.tuple("dir[1]")));
    x9_upper.add(factory.tuple("dir[1]").product(factory.tuple("dir[2]")));
    x9_upper.add(factory.tuple("dir[1]").product(factory.tuple("dir[3]")));
    x9_upper.add(factory.tuple("dir[2]").product(factory.tuple("dir[0]")));
    x9_upper.add(factory.tuple("dir[2]").product(factory.tuple("dir[1]")));
    x9_upper.add(factory.tuple("dir[2]").product(factory.tuple("dir[2]")));
    x9_upper.add(factory.tuple("dir[2]").product(factory.tuple("dir[3]")));
    x9_upper.add(factory.tuple("dir[3]").product(factory.tuple("dir[0]")));
    x9_upper.add(factory.tuple("dir[3]").product(factory.tuple("dir[1]")));
    x9_upper.add(factory.tuple("dir[3]").product(factory.tuple("dir[2]")));
    x9_upper.add(factory.tuple("dir[3]").product(factory.tuple("dir[3]")));
    bounds.bound(x9, x9_upper);
    Expression x39 = x5.union(Expression.INTS);
    Expression x38 = x6.union(x39);
    Expression x37 = x38.product(Expression.UNIV);
    Expression x35 = Expression.IDEN.intersection(x37);
    Expression x34 = x35.intersection(x7);
    Formula x33 = x34.no();
    Variable x44 = Variable.nary("functional_x", 1);
    Decls x43 = x44.oneOf(x5);
    Expression x48 = x44.join(x7);
    Formula x47 = x48.lone();
    Formula x45 = Formula.TRUE.implies(x47);
    Formula x42 = x45.forAll(x43);
    Formula x32 = x33.and(x42);
    Variable x51 = Variable.nary("total_x", 1);
    Decls x50 = x51.oneOf(x5);
    Expression x54 = x51.join(x7);
    Formula x53 = x54.some();
    Formula x52 = Formula.TRUE.implies(x53);
    Formula x49 = x52.forAll(x50);
    Formula x31 = x32.and(x49);
    Variable x57 = Variable.nary("injective_x", 1);
    Decls x56 = x57.oneOf(x6);
    Expression x60 = x7.join(x57);
    Formula x59 = x60.lone();
    Formula x58 = Formula.TRUE.implies(x59);
    Formula x55 = x58.forAll(x56);
    Formula x30 = x31.and(x55);
    Expression x63 = x7.join(x8);
    Expression x62 = x63.transpose();
    Formula x61 = x62.in(x63);
    Formula x29 = x30.and(x61);
    Variable x66 = Variable.nary("acyclic_x", 1);
    Decls x65 = x66.oneOf(x5);
    Expression x72 = x7.join(x8);
    Expression x71 = x72.closure();
    Expression x70 = x66.join(x71);
    Formula x69 = x66.in(x70);
    Formula x68 = x69.not();
    Formula x67 = Formula.TRUE.implies(x68);
    Formula x64 = x67.forAll(x65);
    Formula x28 = x29.and(x64);
    Variable x75 = Variable.nary("surjective_x", 1);
    Decls x74 = x75.oneOf(x5);
    Expression x78 = x8.join(x75);
    Formula x77 = x78.some();
    Formula x76 = Formula.TRUE.implies(x77);
    Formula x73 = x76.forAll(x74);
    Formula x27 = x28.and(x73);
    Variable x81 = Variable.nary("functional_x", 1);
    Decls x80 = x81.oneOf(x6);
    Expression x84 = x81.join(x8);
    Formula x83 = x84.lone();
    Formula x82 = Formula.TRUE.implies(x83);
    Formula x79 = x82.forAll(x80);
    Formula x26 = x27.and(x79);
    Variable x87 = Variable.nary("acyclic_x", 1);
    Decls x86 = x87.oneOf(x6);
    Expression x93 = x8.join(x7);
    Expression x92 = x93.closure();
    Expression x91 = x87.join(x92);
    Formula x90 = x87.in(x91);
    Formula x89 = x90.not();
    Formula x88 = Formula.TRUE.implies(x89);
    Formula x85 = x88.forAll(x86);
    Formula x25 = x26.and(x85);
    Expression x96 = x9.transpose();
    Expression x95 = x96.intersection(x9);
    Expression x98 = x38.product(Expression.UNIV);
    Expression x97 = Expression.IDEN.intersection(x98);
    Formula x94 = x95.in(x97);
    Formula x24 = x25.and(x94);
    Expression x102 = x38.product(Expression.UNIV);
    Expression x101 = Expression.IDEN.intersection(x102);
    Expression x100 = x101.intersection(x9);
    Formula x99 = x100.no();
    Formula x23 = x24.and(x99);
    Expression x106 = x38.product(Expression.UNIV);
    Expression x105 = Expression.IDEN.intersection(x106);
    Expression x104 = x105.intersection(x8);
    Formula x103 = x104.no();
    Formula x22 = x23.and(x103);
    Variable x109 = Variable.nary("injective_x", 1);
    Decls x108 = x109.oneOf(x5);
    Expression x112 = x8.join(x109);
    Formula x111 = x112.lone();
    Formula x110 = Formula.TRUE.implies(x111);
    Formula x107 = x110.forAll(x108);
    Formula x21 = x22.and(x107);
    Variable x115 = Variable.nary("acyclic_x", 1);
    Decls x114 = x115.oneOf(x6);
    Expression x120 = x9.closure();
    Expression x119 = x115.join(x120);
    Formula x118 = x115.in(x119);
    Formula x117 = x118.not();
    Formula x116 = Formula.TRUE.implies(x117);
    Formula x113 = x116.forAll(x114);
    Formula x20 = x21.and(x113);
    Variable x123 = Variable.nary("functional_x", 1);
    Decls x122 = x123.oneOf(x6);
    Expression x126 = x123.join(x9);
    Formula x125 = x126.lone();
    Formula x124 = Formula.TRUE.implies(x125);
    Formula x121 = x124.forAll(x122);
    Formula x19 = x20.and(x121);
    Variable x129 = Variable.nary("injective_x", 1);
    Decls x128 = x129.oneOf(x6);
    Expression x132 = x9.join(x129);
    Formula x131 = x132.lone();
    Formula x130 = Formula.TRUE.implies(x131);
    Formula x127 = x130.forAll(x128);
    Formula x18 = x19.and(x127);
    Variable x137 = Variable.nary("rootedOne_root", 1);
    Decls x136 = x137.oneOf(x6);
    Variable x139 = Variable.nary("rootedOne_root", 1);
    Decls x138 = x139.oneOf(x6);
    Decls x135 = x136.and(x138);
    Expression x146 = x9.closure();
    Expression x148 = x38.product(Expression.UNIV);
    Expression x147 = Expression.IDEN.intersection(x148);
    Expression x145 = x146.union(x147);
    Expression x144 = x137.join(x145);
    Formula x143 = x6.in(x144);
    Expression x152 = x9.closure();
    Expression x154 = x38.product(Expression.UNIV);
    Expression x153 = Expression.IDEN.intersection(x154);
    Expression x151 = x152.union(x153);
    Expression x150 = x139.join(x151);
    Formula x149 = x6.in(x150);
    Formula x142 = x143.and(x149);
    Formula x156 = x137.eq(x139);
    Formula x155 = x156.and(Formula.TRUE);
    Formula x141 = x142.implies(x155);
    Formula x140 = Formula.TRUE.implies(x141);
    Formula x134 = x140.forAll(x135);
    Variable x159 = Variable.nary("rootedOne_root", 1);
    Decls x158 = x159.oneOf(x6);
    Expression x164 = x9.closure();
    Expression x166 = x38.product(Expression.UNIV);
    Expression x165 = Expression.IDEN.intersection(x166);
    Expression x163 = x164.union(x165);
    Expression x162 = x159.join(x163);
    Formula x161 = x6.in(x162);
    Formula x160 = Formula.TRUE.and(x161);
    Formula x157 = x160.forSome(x158);
    Formula x133 = x134.and(x157);
    Formula x17 = x18.and(x133);
    Variable x170 = Variable.nary("weaklyConnected_d", 1);
    Decls x169 = x170.oneOf(x6);
    Variable x172 = Variable.nary("weaklyConnected_g", 1);
    Decls x171 = x172.oneOf(x6);
    Decls x168 = x169.and(x171);
    Formula x177 = x170.eq(x172);
    Formula x176 = x177.not();
    Formula x175 = x176.not();
    Expression x182 = x9.transpose();
    Expression x181 = x9.union(x182);
    Expression x180 = x181.closure();
    Expression x179 = x172.join(x180);
    Formula x178 = x170.in(x179);
    Formula x174 = x175.or(x178);
    Formula x173 = Formula.TRUE.implies(x174);
    Formula x167 = x173.forAll(x168);
    Formula x16 = x17.and(x167);
    Expression x187 = x8.join(x7);
    Expression x188 = Expression.UNIV.product(x6);
    Expression x186 = x187.intersection(x188);
    Expression x185 = x9.union(x186);
    Expression x184 = x185.transpose();
    Formula x183 = x184.in(x185);
    Formula x15 = x16.and(x183);
    Variable x191 = Variable.nary("inner_injective_x", 1);
    Variable x197 = Variable.nary("ternary_a", 1);
    Expression x198 = x7.join(x38);
    Decls x196 = x197.oneOf(x198);
    Variable x200 = Variable.nary("ternary_b", 1);
    Expression x202 = x38.join(x7);
    Expression x203 = x8.join(x38);
    Expression x201 = x202.intersection(x203);
    Decls x199 = x200.oneOf(x201);
    Variable x205 = Variable.nary("ternary_c", 1);
    Expression x206 = x38.join(x8);
    Decls x204 = x205.oneOf(x206);
    Decls x195 = x196.and(x199).and(x204);
    Expression x209 = x197.product(x200);
    Formula x208 = x209.in(x7);
    Expression x211 = x200.product(x205);
    Formula x210 = x211.in(x8);
    Formula x207 = x208.and(x210);
    Expression x194 = x207.comprehension(x195);
    Expression x193 = x194.join(x38);
    Expression x192 = x193.join(x38);
    Decls x190 = x191.oneOf(x192);
    Variable x215 = Variable.nary("injective_x", 1);
    Expression x217 = x191.join(x194);
    Expression x216 = x38.join(x217);
    Decls x214 = x215.oneOf(x216);
    Expression x221 = x191.join(x194);
    Expression x220 = x221.join(x215);
    Formula x219 = x220.lone();
    Formula x218 = Formula.TRUE.implies(x219);
    Formula x213 = x218.forAll(x214);
    Formula x212 = Formula.TRUE.implies(x213);
    Formula x189 = x212.forAll(x190);
    Formula x14 = x15.and(x189);
    Variable x224 = Variable.nary("inner_injective_x", 1);
    Variable x230 = Variable.nary("ternary_a", 1);
    Expression x231 = x8.join(x38);
    Decls x229 = x230.oneOf(x231);
    Variable x233 = Variable.nary("ternary_b", 1);
    Expression x235 = x38.join(x8);
    Expression x236 = x7.join(x38);
    Expression x234 = x235.intersection(x236);
    Decls x232 = x233.oneOf(x234);
    Variable x238 = Variable.nary("ternary_c", 1);
    Expression x239 = x38.join(x7);
    Decls x237 = x238.oneOf(x239);
    Decls x228 = x229.and(x232).and(x237);
    Expression x242 = x230.product(x233);
    Formula x241 = x242.in(x8);
    Expression x244 = x233.product(x238);
    Formula x243 = x244.in(x7);
    Formula x240 = x241.and(x243);
    Expression x227 = x240.comprehension(x228);
    Expression x226 = x227.join(x38);
    Expression x225 = x226.join(x38);
    Decls x223 = x224.oneOf(x225);
    Variable x248 = Variable.nary("injective_x", 1);
    Expression x250 = x224.join(x227);
    Expression x249 = x38.join(x250);
    Decls x247 = x248.oneOf(x249);
    Expression x254 = x224.join(x227);
    Expression x253 = x254.join(x248);
    Formula x252 = x253.lone();
    Formula x251 = Formula.TRUE.implies(x252);
    Formula x246 = x251.forAll(x247);
    Formula x245 = Formula.TRUE.implies(x246);
    Formula x222 = x245.forAll(x223);
    Formula x13 = x14.and(x222);
    Variable x259 = Variable.nary("rootedOne_root", 1);
    Decls x258 = x259.oneOf(x6);
    Variable x261 = Variable.nary("rootedOne_root", 1);
    Decls x260 = x261.oneOf(x6);
    Decls x257 = x258.and(x260);
    Variable x272 = Variable.nary("rootedOne_a", 1);
    Decls x271 = x272.oneOf(x6);
    Variable x274 = Variable.nary("rootedOne_b", 1);
    Decls x273 = x274.oneOf(x6);
    Decls x270 = x271.and(x273);
    Variable x277 = Variable.nary("rootedOne_c", 1);
    Decls x276 = x277.oneOf(x38);
    Expression x281 = x277.product(x274);
    Expression x280 = x272.product(x281);
    Variable x285 = Variable.nary("ternary_a", 1);
    Expression x286 = x8.join(x38);
    Decls x284 = x285.oneOf(x286);
    Variable x288 = Variable.nary("ternary_b", 1);
    Expression x290 = x38.join(x8);
    Expression x291 = x7.join(x38);
    Expression x289 = x290.intersection(x291);
    Decls x287 = x288.oneOf(x289);
    Variable x293 = Variable.nary("ternary_c", 1);
    Expression x294 = x38.join(x7);
    Decls x292 = x293.oneOf(x294);
    Decls x283 = x284.and(x287).and(x292);
    Expression x297 = x285.product(x288);
    Formula x296 = x297.in(x8);
    Expression x299 = x288.product(x293);
    Formula x298 = x299.in(x7);
    Formula x295 = x296.and(x298);
    Expression x282 = x295.comprehension(x283);
    Formula x279 = x280.in(x282);
    Formula x278 = Formula.TRUE.and(x279);
    Formula x275 = x278.forSome(x276);
    Expression x269 = x275.comprehension(x270);
    Expression x268 = x269.closure();
    Expression x301 = x38.product(Expression.UNIV);
    Expression x300 = Expression.IDEN.intersection(x301);
    Expression x267 = x268.union(x300);
    Expression x266 = x259.join(x267);
    Formula x265 = x6.in(x266);
    Variable x309 = Variable.nary("rootedOne_a", 1);
    Decls x308 = x309.oneOf(x6);
    Variable x311 = Variable.nary("rootedOne_b", 1);
    Decls x310 = x311.oneOf(x6);
    Decls x307 = x308.and(x310);
    Variable x314 = Variable.nary("rootedOne_c", 1);
    Decls x313 = x314.oneOf(x38);
    Expression x318 = x314.product(x311);
    Expression x317 = x309.product(x318);
    Formula x316 = x317.in(x282);
    Formula x315 = Formula.TRUE.and(x316);
    Formula x312 = x315.forSome(x313);
    Expression x306 = x312.comprehension(x307);
    Expression x305 = x306.closure();
    Expression x320 = x38.product(Expression.UNIV);
    Expression x319 = Expression.IDEN.intersection(x320);
    Expression x304 = x305.union(x319);
    Expression x303 = x261.join(x304);
    Formula x302 = x6.in(x303);
    Formula x264 = x265.and(x302);
    Formula x322 = x259.eq(x261);
    Formula x321 = x322.and(Formula.TRUE);
    Formula x263 = x264.implies(x321);
    Formula x262 = Formula.TRUE.implies(x263);
    Formula x256 = x262.forAll(x257);
    Variable x325 = Variable.nary("rootedOne_root", 1);
    Decls x324 = x325.oneOf(x6);
    Variable x334 = Variable.nary("rootedOne_a", 1);
    Decls x333 = x334.oneOf(x6);
    Variable x336 = Variable.nary("rootedOne_b", 1);
    Decls x335 = x336.oneOf(x6);
    Decls x332 = x333.and(x335);
    Variable x339 = Variable.nary("rootedOne_c", 1);
    Decls x338 = x339.oneOf(x38);
    Expression x343 = x339.product(x336);
    Expression x342 = x334.product(x343);
    Formula x341 = x342.in(x282);
    Formula x340 = Formula.TRUE.and(x341);
    Formula x337 = x340.forSome(x338);
    Expression x331 = x337.comprehension(x332);
    Expression x330 = x331.closure();
    Expression x345 = x38.product(Expression.UNIV);
    Expression x344 = Expression.IDEN.intersection(x345);
    Expression x329 = x330.union(x344);
    Expression x328 = x325.join(x329);
    Formula x327 = x6.in(x328);
    Formula x326 = Formula.TRUE.and(x327);
    Formula x323 = x326.forSome(x324);
    Formula x255 = x256.and(x323);
    Formula x12 = x13.and(x255);
    Expression x348 = x9.join(x9);
    Formula x347 = x348.in(x9);
    Formula x346 = x347.not();
    Formula x11 = x12.and(x346);
    Expression x352 = x6.product(x6);
    Formula x351 = x9.in(x352);
    Expression x355 = x6.product(x5);
    Formula x354 = x8.in(x355);
    Expression x359 = x5.product(x6);
    Formula x358 = x7.in(x359);
    Formula x363 = Formula.TRUE.and(Formula.TRUE);
    Formula x362 = Formula.TRUE.and(x363);
    Formula x361 = Formula.TRUE.and(x362);
    Formula x360 = Formula.TRUE.and(x361);
    Formula x357 = x358.and(x360);
    Formula x356 = Formula.TRUE.and(x357);
    Formula x353 = x354.and(x356);
    Formula x350 = x351.and(x353);
    Formula x349 = Formula.TRUE.and(x350);
    Formula x10 = x11.and(x349);
    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(x10, bounds);
    // System.out.println(sol.toString());
    Proof proof = sol.proof();
    proof.minimize(new RCEStrategy(proof.log()));
    Set<Formula> core = Nodes.minRoots(x10, sol.proof().highLevelCore().values());
    // final Set<Formula> minCore = new LinkedHashSet<Formula>(core);
    // for(Iterator<Formula> itr = minCore.iterator(); itr.hasNext();) {
    // Formula f = itr.next();
    // Formula noF = Formula.TRUE;
    // for( Formula f1 : minCore ) {
    // if (f!=f1)
    // noF = noF.and(f1);
    // }
    // if (solver.solve(noF, bounds).instance()==null) {
    // itr.remove();
    // }
    // }
    // assertTrue(minCore.size()==core.size());
    assertTrue(isMinimal(solver, bounds, core));
}
Also used : TupleSet(kodkod.instance.TupleSet) Solver(kodkod.engine.Solver) Variable(kodkod.ast.Variable) Decls(kodkod.ast.Decls) Bounds(kodkod.instance.Bounds) TupleFactory(kodkod.instance.TupleFactory) Universe(kodkod.instance.Universe) Formula(kodkod.ast.Formula) Relation(kodkod.ast.Relation) RCEStrategy(kodkod.engine.ucore.RCEStrategy) IntExpression(kodkod.ast.IntExpression) Expression(kodkod.ast.Expression) Proof(kodkod.engine.Proof) Solution(kodkod.engine.Solution)

Example 84 with Relation

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

the class BugTests method testGreg_11232005.

public final void testGreg_11232005() {
    final List<String> atoms = new ArrayList<String>(3);
    atoms.add("-1");
    atoms.add("0");
    atoms.add("1");
    final Universe u = new Universe(atoms);
    final TupleFactory t = u.factory();
    final Relation inc = Relation.binary("inc"), add = Relation.ternary("add"), one = Relation.unary("1"), param0 = Relation.unary("param0"), ints = Relation.unary("int");
    // (one param0 && ((1 . (param0 . add)) in (param0 . ^inc)))
    final Formula f = param0.one().and((one.join(param0.join(add))).in(param0.join(inc.closure())));
    final Bounds b = new Bounds(u);
    b.bound(param0, t.allOf(1));
    b.boundExactly(one, t.setOf(t.tuple("1")));
    b.boundExactly(ints, t.allOf(1));
    b.boundExactly(inc, t.setOf(t.tuple("-1", "0"), t.tuple("0", "1")));
    // [1, 1, -1], [1, -1, 0], [1, 0, 1], [-1, 1, 0], [-1, -1, 1],
    // [-1, 0, -1], [0, 1, 1], [0, -1, -1], [0, 0, 0]]
    b.boundExactly(add, t.setOf(t.tuple("1", "1", "-1"), t.tuple("1", "-1", "0"), t.tuple("1", "0", "1"), t.tuple("-1", "1", "0"), t.tuple("-1", "-1", "1"), t.tuple("-1", "0", "-1"), t.tuple("0", "1", "1"), t.tuple("0", "-1", "-1"), t.tuple("0", "0", "0")));
    // System.out.println(f);
    // System.out.println(b);
    final Instance instance = solver.solve(f, b).instance();
    assertTrue((new Evaluator(instance)).evaluate(f));
// System.out.println(instance);
// System.out.println((new Evaluator(instance)).evaluate(f ));
}
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) Evaluator(kodkod.engine.Evaluator)

Example 85 with Relation

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

the class BugTests method testFelix_03162009.

public final void testFelix_03162009() {
    Relation x = Relation.unary("X");
    Relation y = Relation.unary("Y");
    Relation q = Relation.unary("Q");
    Relation f = Relation.nary("f", 2);
    List<String> atomlist = Arrays.asList("X", "Y");
    Universe universe = new Universe(atomlist);
    TupleFactory factory = universe.factory();
    Bounds bounds = new Bounds(universe);
    TupleSet x_upper = factory.noneOf(1);
    x_upper.add(factory.tuple("X"));
    bounds.boundExactly(x, x_upper);
    TupleSet y_upper = factory.noneOf(1);
    y_upper.add(factory.tuple("Y"));
    bounds.boundExactly(y, y_upper);
    TupleSet q_upper = factory.noneOf(1);
    q_upper.add(factory.tuple("X"));
    q_upper.add(factory.tuple("Y"));
    bounds.bound(q, q_upper);
    TupleSet f_upper = factory.noneOf(2);
    f_upper.add(factory.tuple("X").product(factory.tuple("X")));
    f_upper.add(factory.tuple("X").product(factory.tuple("Y")));
    f_upper.add(factory.tuple("Y").product(factory.tuple("X")));
    f_upper.add(factory.tuple("Y").product(factory.tuple("Y")));
    bounds.bound(f, f_upper);
    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);
    Expression test = f.override(q.product(y));
    TupleSet approx = factory.setOf(test.arity(), Translator.approximate(test, bounds, solver.options()).denseIndices());
    assertEquals(f_upper, approx);
}
Also used : TupleSet(kodkod.instance.TupleSet) Relation(kodkod.ast.Relation) Solver(kodkod.engine.Solver) IntExpression(kodkod.ast.IntExpression) Expression(kodkod.ast.Expression) Bounds(kodkod.instance.Bounds) TupleFactory(kodkod.instance.TupleFactory) Universe(kodkod.instance.Universe)

Aggregations

Relation (kodkod.ast.Relation)87 Bounds (kodkod.instance.Bounds)49 Formula (kodkod.ast.Formula)45 TupleFactory (kodkod.instance.TupleFactory)45 Universe (kodkod.instance.Universe)45 TupleSet (kodkod.instance.TupleSet)43 Solution (kodkod.engine.Solution)30 Expression (kodkod.ast.Expression)26 IntExpression (kodkod.ast.IntExpression)24 Solver (kodkod.engine.Solver)24 ArrayList (java.util.ArrayList)23 Variable (kodkod.ast.Variable)23 Instance (kodkod.instance.Instance)15 Decls (kodkod.ast.Decls)13 Evaluator (kodkod.engine.Evaluator)9 Tuple (kodkod.instance.Tuple)8 IntSet (kodkod.util.ints.IntSet)7 BinaryExpression (kodkod.ast.BinaryExpression)6 Decl (kodkod.ast.Decl)6 LinkedHashSet (java.util.LinkedHashSet)4