kodkod.instance.Universe Java Examples
The following examples show how to use
kodkod.instance.Universe.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BugTests.java From org.alloytools.alloy with Apache License 2.0 | 6 votes |
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()); }
Example #2
Source File: RegressionTests.java From kodkod with MIT License | 6 votes |
@Test 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); final Solution s = solver.solve(f, bounds); // System.out.println(s); assertEquals(Solution.Outcome.SATISFIABLE, s.outcome()); }
Example #3
Source File: Pigeonhole.java From kodkod with MIT License | 6 votes |
/** * Returns the bounds for the given number of pigeons and holes. * @return bounds */ public Bounds bounds(int pigeons, int holes) { final List<String> atoms = new ArrayList<String>(pigeons + holes); for(int i = 0; i < pigeons; i++) { atoms.add("Pigeon"+i); } for(int i = 0; i < holes; i++) { atoms.add("Hole"+i); } final Universe u = new Universe(atoms); final TupleFactory f = u.factory(); final Bounds b = new Bounds(u); final TupleSet pbound = f.range(f.tuple("Pigeon0"), f.tuple("Pigeon" + (pigeons-1))); final TupleSet hbound = f.range(f.tuple("Hole0"), f.tuple("Hole" + (holes-1))); b.boundExactly(Pigeon, pbound); b.boundExactly(Hole, hbound); b.bound(hole, pbound.product(hbound)); return b; }
Example #4
Source File: Viktor.java From kodkod with MIT License | 6 votes |
/** * Returns the bounds for the problem. * @return bounds */ public final Bounds bounds() { List<String> atoms = new ArrayList<String>(cols+1); for(int i = 0; i < cols; i++) { atoms.add(String.valueOf(i)); } atoms.add("a"); final Universe u = new Universe(atoms); final TupleFactory f = u.factory(); final Bounds b = new Bounds(u); final TupleSet abound = f.setOf("a"); for(int i = 0; i < rows; i++) { for(int j = 0; j < cols; j++) { b.bound(a[i][j], abound); } } final TupleSet xbound = f.range(f.tuple(String.valueOf(0)), f.tuple(String.valueOf(cols-1))); for(int j = 0; j < cols; j++) { b.bound(x[j], xbound); b.boundExactly(j, f.setOf(String.valueOf(j))); } return b; }
Example #5
Source File: GRA013_026.java From kodkod with MIT License | 6 votes |
/** * Returns the bounds. * @return the bounds */ public final Bounds bounds() { final List<String> atoms = new ArrayList<String>(graphSize); for(int i = 1; i <= graphSize; i++) atoms.add("n"+i); atoms.add("goal"); final Universe u = new Universe(atoms); final TupleFactory f = u.factory(); final Bounds b = new Bounds(u); b.bound(goal, f.setOf("goal")); final TupleSet ns = f.range(f.tuple("n1"), f.tuple("n"+graphSize)); b.boundExactly(node, ns); final TupleSet s = f.noneOf(2); for(int i = 1; i < graphSize; i++) { for(int j = i+1; j < graphSize; j++) s.add(f.tuple("n"+i, "n"+j)); } b.boundExactly(lessThan, s); b.bound(red, s); b.bound(green, s); return b; }
Example #6
Source File: NUM378.java From org.alloytools.alloy with Apache License 2.0 | 6 votes |
/** * Returns bounds for the problem. * * @return bounds for the problem. */ public final Bounds bounds() { final int n = 21; final List<String> atoms = new ArrayList<String>(n); atoms.add("goal"); for (int i = 0; i < n; i++) atoms.add("n" + i); final Universe u = new Universe(atoms); final Bounds bound = new Bounds(u); final TupleFactory f = u.factory(); final TupleSet succBound = f.noneOf(2); for (int i = 0; i < n; i++) { succBound.add(f.tuple("n" + i, "n" + ((i + 1) % n))); } bound.boundExactly(succ, succBound); final TupleSet sumBound = f.noneOf(3); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { sumBound.add(f.tuple("n" + i, "n" + j, "n" + ((i + j) % n))); } } bound.boundExactly(sum, sumBound); return bound; }
Example #7
Source File: Viktor.java From org.alloytools.alloy with Apache License 2.0 | 6 votes |
/** * Returns the bounds for the problem. * * @return bounds */ public final Bounds bounds() { List<String> atoms = new ArrayList<String>(cols + 1); for (int i = 0; i < cols; i++) { atoms.add(String.valueOf(i)); } atoms.add("a"); final Universe u = new Universe(atoms); final TupleFactory f = u.factory(); final Bounds b = new Bounds(u); final TupleSet abound = f.setOf("a"); for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { b.bound(a[i][j], abound); } } final TupleSet xbound = f.range(f.tuple(String.valueOf(0)), f.tuple(String.valueOf(cols - 1))); for (int j = 0; j < cols; j++) { b.bound(x[j], xbound); b.boundExactly(j, f.setOf(String.valueOf(j))); } return b; }
Example #8
Source File: EnumerationTest.java From kodkod with MIT License | 6 votes |
@Test public final void testTrivial() { final Relation r = Relation.unary("r"); final Universe u = new Universe(Arrays.asList("a","b","c")); final TupleFactory f = u.factory(); final Bounds b = new Bounds(u); b.bound(r, f.setOf("a"), f.allOf(1)); final Formula someR = r.some(); Iterator<Solution> sol = solver.solveAll(someR, b); // has a trivial instance, followed by 2 non-trivial instances assertEquals(Solution.Outcome.TRIVIALLY_SATISFIABLE, sol.next().outcome()); assertEquals(Solution.Outcome.SATISFIABLE, sol.next().outcome()); assertEquals(Solution.Outcome.SATISFIABLE, sol.next().outcome()); assertEquals(Solution.Outcome.UNSATISFIABLE, sol.next().outcome()); assertFalse(sol.hasNext()); }
Example #9
Source File: Pigeonhole.java From org.alloytools.alloy with Apache License 2.0 | 6 votes |
/** * Returns the bounds for the given number of pigeons and holes. * * @return bounds */ public Bounds bounds(int pigeons, int holes) { final List<String> atoms = new ArrayList<String>(pigeons + holes); for (int i = 0; i < pigeons; i++) { atoms.add("Pigeon" + i); } for (int i = 0; i < holes; i++) { atoms.add("Hole" + i); } final Universe u = new Universe(atoms); final TupleFactory f = u.factory(); final Bounds b = new Bounds(u); final TupleSet pbound = f.range(f.tuple("Pigeon0"), f.tuple("Pigeon" + (pigeons - 1))); final TupleSet hbound = f.range(f.tuple("Hole0"), f.tuple("Hole" + (holes - 1))); b.boundExactly(Pigeon, pbound); b.boundExactly(Hole, hbound); b.bound(hole, pbound.product(hbound)); return b; }
Example #10
Source File: NUM378.java From kodkod with MIT License | 6 votes |
/** * Returns bounds for the problem. * @return bounds for the problem. */ public final Bounds bounds() { final int n = 21; final List<String> atoms = new ArrayList<String>(n); atoms.add("goal"); for(int i = 0; i < n; i++) atoms.add("n"+i); final Universe u = new Universe(atoms); final Bounds bound = new Bounds(u); final TupleFactory f = u.factory(); final TupleSet succBound = f.noneOf(2); for(int i = 0; i < n; i++) { succBound.add(f.tuple("n"+i,"n"+((i+1)%n))); } bound.boundExactly(succ, succBound); final TupleSet sumBound = f.noneOf(3); for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { sumBound.add(f.tuple("n"+i, "n"+j, "n"+((i+j)%n))); } } bound.boundExactly(sum, sumBound); return bound; }
Example #11
Source File: EnumerationTest.java From org.alloytools.alloy with Apache License 2.0 | 6 votes |
public final void testTrivial() { final Relation r = Relation.unary("r"); final Universe u = new Universe(Arrays.asList("a", "b", "c")); final TupleFactory f = u.factory(); final Bounds b = new Bounds(u); b.bound(r, f.setOf("a"), f.allOf(1)); final Formula someR = r.some(); Iterator<Solution> sol = solver.solveAll(someR, b); // has a trivial instance, followed by 2 non-trivial instances assertEquals(Solution.Outcome.TRIVIALLY_SATISFIABLE, sol.next().outcome()); assertEquals(Solution.Outcome.SATISFIABLE, sol.next().outcome()); assertEquals(Solution.Outcome.SATISFIABLE, sol.next().outcome()); assertEquals(Solution.Outcome.UNSATISFIABLE, sol.next().outcome()); assertFalse(sol.hasNext()); }
Example #12
Source File: ToyLists.java From kodkod with MIT License | 6 votes |
/** * Returns the bounds for the toy lists problem with the given number of lists and things. * @return bounds for the toy lists problem with the given number of lists and things. */ public Bounds bounds(int lists, int things) { final List<String> atoms = new ArrayList<String>(lists+things); for(int i = 0; i < lists; i++) { atoms.add("list"+i); } for(int i = 0; i < things; i++) { atoms.add("thing"+i); } final Universe univ = new Universe(atoms); final TupleFactory f = univ.factory(); final Bounds b = new Bounds(univ); b.bound(list, f.range(f.tuple("list0"), f.tuple("list"+(lists-1)))); b.bound(nonEmptyList, b.upperBound(list)); b.bound(emptyList, b.upperBound(list)); b.bound(thing, f.range(f.tuple("thing0"), f.tuple("thing"+(things-1)))); b.bound(car, b.upperBound(nonEmptyList).product(b.upperBound(thing))); b.bound(cdr, b.upperBound(nonEmptyList).product(b.upperBound(list))); b.bound(equivTo, b.upperBound(list).product(b.upperBound(list))); b.bound(prefixes, b.upperBound(list).product(b.upperBound(list))); return b; }
Example #13
Source File: BugTests.java From org.alloytools.alloy with Apache License 2.0 | 6 votes |
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); }
Example #14
Source File: BugTests.java From org.alloytools.alloy with Apache License 2.0 | 6 votes |
public final void testGreg_02192006() { Relation r1 = Relation.unary("r1"); Relation r2 = Relation.unary("r2"); Relation r3 = Relation.unary("r3"); Expression e = r1.in(r2).thenElse(r2, r1); Formula f = e.eq(r2).and(e.in(r3)); Object o1 = "o1"; Object o2 = "o2"; Universe univ = new Universe(Arrays.asList(o1, o2)); TupleFactory factory = univ.factory(); TupleSet set1 = factory.setOf(o1); TupleSet set2 = factory.setOf(o2); Bounds bounds = new Bounds(univ); bounds.bound(r1, set1); bounds.boundExactly(r2, set2); bounds.bound(r3, set1); assertEquals(Solution.Outcome.TRIVIALLY_UNSATISFIABLE, solver.solve(f, bounds).outcome()); }
Example #15
Source File: IncrementalSolverTest.java From kodkod with MIT License | 6 votes |
@Test public void testBadBounds() { final Bounds b = new Bounds(new Universe("A0", "A1", "A2")); final TupleFactory t = b.universe().factory(); final Relation r0 = Relation.unary("r0"); final Relation r1 = Relation.unary("r1"); b.bound(r0, t.setOf("A0")); final Solution sol = solver.solve(r0.some(), b); assertEquals(SATISFIABLE, sol.outcome()); b.bound(r1, t.setOf("A1")); try { solver.solve(r1.some(), b); fail("Expected an IllegalArgumentException when solving with bounds that do not induce a coarser set of symmetries than the initial bounds."); } catch (IllegalArgumentException iae) { // fine } assertFalse(solver.usable()); }
Example #16
Source File: RegressionTests.java From kodkod with MIT License | 6 votes |
@Test public final void testGreg_02192006() { Relation r1 = Relation.unary("r1"); Relation r2 = Relation.unary("r2"); Relation r3 = Relation.unary("r3"); Expression e = r1.in(r2).thenElse(r2, r1); Formula f = e.eq(r2).and(e.in(r3)); Object o1 = "o1"; Object o2 = "o2"; Universe univ = new Universe(Arrays.asList(o1, o2)); TupleFactory factory = univ.factory(); TupleSet set1 = factory.setOf(o1); TupleSet set2 = factory.setOf(o2); Bounds bounds = new Bounds(univ); bounds.bound(r1, set1); bounds.boundExactly(r2, set2); bounds.bound(r3, set1); assertEquals(Solution.Outcome.TRIVIALLY_UNSATISFIABLE, solver.solve(f, bounds).outcome()); }
Example #17
Source File: OverflowNumTest.java From org.alloytools.alloy with Apache License 2.0 | 6 votes |
public OverflowNumTest() { this.ret = Relation.unary("ret"); int min = min(); int max = max(); List<String> atoms = new ArrayList<String>(max - min + 1); for (int i = min; i <= max; i++) { atoms.add(String.valueOf(i)); } final Universe universe = new Universe(atoms); this.factory = universe.factory(); this.bounds = new Bounds(factory.universe()); for (int i = min; i <= max; i++) { bounds.boundExactly(i, factory.setOf(String.valueOf(i))); } bounds.bound(ret, factory.noneOf(1), factory.allOf(1)); }
Example #18
Source File: ReductionAndProofTest.java From org.alloytools.alloy with Apache License 2.0 | 6 votes |
public ReductionAndProofTest(String arg0) { super(arg0); this.solver = new Solver(); solver.options().setLogTranslation(2); solver.options().setSolver(SATFactory.MiniSatProver); List<String> atoms = new ArrayList<String>(USIZE); for (int i = 0; i < USIZE; i++) { atoms.add("" + i); } final Universe universe = new Universe(atoms); this.factory = universe.factory(); this.a = Relation.unary("a"); this.b = Relation.unary("b"); this.a2b = Relation.binary("a2b"); this.b2a = Relation.binary("b2a"); this.first = Relation.unary("first"); this.last = Relation.unary("last"); this.ordered = Relation.unary("ordered"); this.total = Relation.binary("total"); this.bounds = new Bounds(universe); }
Example #19
Source File: IncrementalOverflowNumTest.java From org.alloytools.alloy with Apache License 2.0 | 6 votes |
@Test public void testBasic() { Options opt = new Options(); opt.setNoOverflow(true); opt.setBitwidth(2); IncrementalSolver solver = IncrementalSolver.solver(opt); Universe univ = new Universe("-2", "-1", "0", "1"); Bounds b = new Bounds(univ); TupleFactory factory = univ.factory(); b.boundExactly(-2, factory.range(factory.tuple("-2"), factory.tuple("-2"))); b.boundExactly(-1, factory.range(factory.tuple("-1"), factory.tuple("-1"))); b.boundExactly(0, factory.range(factory.tuple("0"), factory.tuple("0"))); b.boundExactly(1, factory.range(factory.tuple("1"), factory.tuple("1"))); Variable n = Variable.unary("n"); Formula f = n.sum().plus(IntConstant.constant(1)).lte(n.sum()).forSome(n.oneOf(Expression.INTS)); Solution sol = solver.solve(f, b); assertNoInstance(sol); }
Example #20
Source File: SocialGolfer.java From kodkod with MIT License | 6 votes |
/** * Returns the bounds for the scheduling problem with the given number of players, groups and weeks, using * the specified group size. * @return bounds for the scheduling problem with the given number of players, groups and weeks, using * the specified group size. */ public final Bounds bounds(int players, int groups, int weeks, int size) { if (players<1 || groups<1 || weeks<1 || size<1) throw new IllegalArgumentException("invalid schedule parameters"); final List<Object> atoms = new ArrayList<Object>(players+groups+weeks+1); for(int i = 0; i < players; i++) { atoms.add("p" + i); } for(int i = 0; i < groups; i++) { atoms.add("g" + i); } for(int i = 0; i < weeks; i++) { atoms.add("w" + i); } atoms.add(size); final Universe u = new Universe(atoms); final TupleFactory f = u.factory(); final Bounds b = new Bounds(u); b.boundExactly(size, f.setOf(size)); b.boundExactly(this.size, f.setOf(size)); b.boundExactly(this.player, f.range(f.tuple("p0"), f.tuple("p"+(players-1)))); b.boundExactly(this.group, f.range(f.tuple("g0"), f.tuple("g"+(groups-1)))); b.boundExactly(this.week, f.range(f.tuple("w0"), f.tuple("w"+(weeks-1)))); b.bound(this.plays, b.upperBound(week).product(b.upperBound(group)).product(b.upperBound(player))); return b; }
Example #21
Source File: BugTests.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
public final void testFelix_10182006() { // (some x: one { y: one SIG | true } | true) Relation sig = Relation.unary("SIG"); final Variable x = Variable.unary("x"); final Variable y = Variable.unary("y"); final Expression e0 = Formula.TRUE.comprehension(y.oneOf(sig)); final Formula f0 = Formula.TRUE.forSome(x.oneOf(e0)); final Universe u = new Universe(Arrays.asList("a0")); final Bounds bounds = new Bounds(u); bounds.bound(sig, u.factory().allOf(1)); final Solution s = solver.solve(f0, bounds); assertEquals(Solution.Outcome.SATISFIABLE, s.outcome()); }
Example #22
Source File: ListSynth.java From kodkod with MIT License | 5 votes |
Universe universe(int size) { final ArrayList<Object> elts = new ArrayList<Object>(2 + size * 2); elts.add("l0"); for(int i = 0; i < size; i++) { elts.add("n" + i); } for(int i = 0; i < size; i++) { elts.add("s" + i); } elts.add("nil"); elts.add(headStx); // the syntax relations will represent themselves in the universe elts.add(nearNode0Stx); elts.add(midNode0Stx); elts.add(farNode0Stx); return new Universe(elts); }
Example #23
Source File: GroupScheduling.java From kodkod with MIT License | 5 votes |
public Bounds bounds() { final int p = ng*ng, r = ng + 1; final List<String> a = new ArrayList<String>((ng+1)*(ng+1)); for(int i = 0; i < p; i++) { a.add("p"+i); } for(int i = 0; i < ng; i++) { a.add("g"+i); } for(int i = 0; i < r; i++) { a.add("r"+i); } final Universe u = new Universe(a); final TupleFactory f = u.factory(); final Bounds b = new Bounds(u); b.boundExactly(person, f.range(f.tuple("p0"), f.tuple("p" + (p-1)))); b.boundExactly(group, f.range(f.tuple("g0"), f.tuple("g" + (ng-1)))); b.boundExactly(round, f.range(f.tuple("r0"), f.tuple("r" + (r-1)))); b.bound(assign, b.upperBound(person).product(b.upperBound(round)).product(b.upperBound(group))); final TupleSet low = f.noneOf(3); for(int i = 0; i < r; i++) { low.add(f.tuple("p0", "r"+i, "g0")); final int start = i*(ng-1) + 1, end = (i+1)*(ng-1); low.addAll(f.range(f.tuple("p"+start), f.tuple("p"+end)).product(f.setOf("r"+i)).product(f.setOf("g0"))); } final TupleSet high = f.noneOf(3); high.addAll(low); high.addAll(f.range(f.tuple("p1"), f.tuple("p" + (p-1))).product(b.upperBound(round)).product(b.upperBound(group))); b.bound(assign, low, high); return b; }
Example #24
Source File: IncrementalSolverTest.java From kodkod with MIT License | 5 votes |
@Test public void testIncrementalFullSymmetryBreaking() { final Bounds b = new Bounds(new Universe("A0", "A1", "A2", "A3", "A4", "A5", "A6", "A7", "A8", "A9")); final TupleFactory t = b.universe().factory(); final Relation ord = Relation.binary("ord"), univ03 = Relation.unary("univ[0..3]"), first = Relation.unary("first"), last = Relation.unary("last"); final Relation next47 = Relation.binary("next43"), univ47 = Relation.unary("univ[4..7]"); final Relation next09 = Relation.binary("next09"); b.bound(univ03, t.setOf("A0", "A1", "A2", "A3")); b.bound(first, b.upperBound(univ03)); b.bound(last, b.upperBound(univ03)); b.bound(ord, b.upperBound(univ03).product(b.upperBound(univ03))); b.boundExactly(univ47, t.setOf("A4", "A5", "A6", "A7")); final Formula[] f = { ord.totalOrder(univ03, first, last), ord.acyclic(), next47.acyclic(), next09.acyclic() }; checkOutcomeAndStats(checkModel(solver.solve(f[0], b), f[0]), TRIVIALLY_SATISFIABLE, 0); b.relations().clear(); checkOutcomeAndStats(checkModel(solver.solve(f[1], b), f[0], f[1]), TRIVIALLY_SATISFIABLE, 0); b.bound(next47, t.setOf("A4", "A5", "A6", "A7").product(t.setOf("A4", "A5", "A6", "A7"))); checkOutcomeAndStats(checkModel(solver.solve(f[2], b), f[0], f[1], f[2]), TRIVIALLY_SATISFIABLE, 0); b.relations().clear(); b.bound(next09, t.allOf(2)); // expecting 6 variables for the symmetry-reduced upper bound of next47 and 100 for the full upper bound of next09 checkOutcomeAndStats(checkModel(solver.solve(f[3], b), f[0], f[1], f[2], f[3]), SATISFIABLE, 100 + 6); }
Example #25
Source File: BugTests.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
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()); }
Example #26
Source File: RegressionTests.java From kodkod with MIT License | 5 votes |
@Test public final void testMarceloSimplified_041912() { final Relation d2 = Relation.unary("Domain_2"); final Relation a1 = Relation.unary("Address_1"); final Relation a2 = Relation.unary("Address_2"); final Relation a3 = Relation.unary("Address_3"); final Expression e = Expression.union(a1, a2, a3); final Expression dstBinding = Expression.union(Expression.product(d2, a1, a3), Expression.product(d2, a3, a3)); final Formula f = a3.in(e.product(a1).override(d2.join(dstBinding)).join(e)); final Universe u = new Universe("a1", "a2", "a3", "d2"); final TupleFactory tf = u.factory(); final Bounds b = new Bounds(u); b.boundExactly(a1, tf.setOf("a1")); b.boundExactly(a2, tf.setOf("a2")); b.boundExactly(a3, tf.setOf("a3")); b.bound(d2, tf.setOf("d2")); final Solver solver = new Solver(); solver.options().setSolver(SATFactory.MiniSat); // System.out.println(f); // System.out.println(b); final Solution sol = solver.solve(f, b); // System.out.println(sol); assertNotNull(sol.instance()); }
Example #27
Source File: RegressionTests.java From kodkod with MIT License | 5 votes |
@Test public final void testFelix_01032007() { List<String> atomlist = Arrays.asList( "-1", "-2", "-3", "-4", "-5", "-6", "-7", "-8", "0", "1", "2", "3", "4", "5", "6", "7"); Universe universe = new Universe(atomlist); TupleFactory factory = universe.factory(); Bounds bounds = new Bounds(universe); 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"))); Expression set=IntConstant.constant(8).toExpression(); Solver solver = new Solver(); solver.options().setSolver(SATFactory.DefaultSAT4J); solver.options().setBitwidth(4); solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT); Solution sol = solver.solve(set.some(), bounds); Evaluator eval = new Evaluator(sol.instance(), solver.options()); TupleSet ts = eval.evaluate(set); assertFalse(ts.size()==0); }
Example #28
Source File: BugTests.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
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); }
Example #29
Source File: IntTest.java From kodkod with MIT License | 5 votes |
public IntTest() { this.solver = new Solver(); List<String> atoms = new ArrayList<String>(SIZE); for (int i = 0; i < SIZE; i++) { atoms.add(String.valueOf(i)); } final Universe universe = new Universe(atoms); this.factory = universe.factory(); r1 = Relation.unary("r1"); }
Example #30
Source File: ALG195_1.java From kodkod with MIT License | 5 votes |
/** * Returns the partial bounds the problem (axioms 1, 4, 9-11). * @return the partial bounds for the problem */ public Bounds bounds() { final List<String> atoms = new ArrayList<String>(14); for(int i = 0; i < 7; i++) atoms.add("e1"+i); for(int i = 0; i < 7; i++) atoms.add("e2"+i); final Universe u = new Universe(atoms); final Bounds b = new Bounds(u); final TupleFactory f = u.factory(); final TupleSet s1bound = f.range(f.tuple("e10"), f.tuple("e16")); final TupleSet s2bound = f.range(f.tuple("e20"), f.tuple("e26")); b.boundExactly(s1, s1bound); b.boundExactly(s2, s2bound); // axioms 9, 10, 11 for(int i = 0; i < 7; i++) { b.boundExactly(e1[i], f.setOf("e1"+i)); b.boundExactly(e2[i], f.setOf("e2"+i)); } // axom 1 b.bound(op1, f.area(f.tuple("e10", "e10", "e10"), f.tuple("e16", "e16", "e16"))); // axiom 4 b.bound(op2, f.area(f.tuple("e20", "e20", "e20"), f.tuple("e26", "e26", "e26"))); final TupleSet hbound = s1bound.product(s2bound); for(Relation r : h) { b.bound(r, hbound); } return b; }