Java Code Examples for kodkod.instance.TupleSet#add()
The following examples show how to use
kodkod.instance.TupleSet#add() .
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: HamiltonianCycle.java From kodkod with MIT License | 6 votes |
/** * Returns Bounds extracted from the graph * definition in the given file. * @requires file is in the specified format * @return Bounds extracted from the graph * definition in the given file. */ public Bounds bounds(String file, Graph.Format format) { final Graph<?> graph = format.parse(file); final Universe u = new Universe(graph.nodes()); final TupleFactory f = u.factory(); final Bounds b = new Bounds(u); b.boundExactly(vertex, f.allOf(1)); b.boundExactly(start, f.setOf(graph.start()==null ? u.atom(0) : graph.start())); final TupleSet edgeBound = f.noneOf(2); for(Object from : graph.nodes()) { for (Object to : graph.edges(from)) edgeBound.add(f.tuple(from, to)); } b.boundExactly(edges, edgeBound); b.bound(cycle, edgeBound); return b; }
Example 2
Source File: BugTests.java From org.alloytools.alloy with Apache License 2.0 | 6 votes |
public final void testEmina_01232006() { final List<String> atoms = new ArrayList<String>(5); for (int i = 0; i < 5; i++) atoms.add("a" + i); final Universe u = new Universe(atoms); final TupleFactory tf = u.factory(); final Relation r1 = Relation.unary("r1"), r2 = Relation.binary("r2"), r3 = Relation.ternary("r3"); final Bounds b = new Bounds(u); final TupleSet r2Bound = tf.noneOf(2); for (int i = 0; i < 4; i++) r2Bound.add(tf.tuple(atoms.get(i), atoms.get(i))); r2Bound.add(tf.tuple("a4", "a1")); r2Bound.add(tf.tuple("a4", "a2")); b.bound(r2, r2Bound); b.bound(r1, tf.setOf("a0", "a3"), tf.setOf("a0", "a3", "a4")); b.bound(r3, tf.setOf(tf.tuple("a0", "a0", "a0"), tf.tuple("a3", "a3", "a3"))); final Formula f = r1.product(r2).in(r3); 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 )); }
Example 3
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 4
Source File: Bigconfig.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** * Returns a bounds with the given number of hqs and subs, constructed using the * given universe. * * @requires hqNum > 0 && subNum > 0 * @requires u contains at least (hqNum+sub) Router atoms and as many Site atoms * @return bounds */ private Bounds bounds(int hqNum, int subNum, Universe u) { final TupleFactory f = u.factory(); final Bounds b = new Bounds(u); final int siteMax = hqNum + subNum - 1; final String site0 = "Site0"; final String siteN = "Site" + siteMax; final String siteHQ = "Site" + (hqNum - 1); final String siteSub = "Site" + hqNum; final String router0 = "Router0"; final String routerN = "Router" + siteMax; final TupleSet sites = f.range(f.tuple(site0), f.tuple(siteN)); b.boundExactly(Site, sites); b.boundExactly(HQ, f.range(f.tuple(site0), f.tuple(siteHQ))); b.boundExactly(Sub, f.range(f.tuple(siteSub), f.tuple(siteN))); final TupleSet routers = f.range(f.tuple(router0), f.tuple(routerN)); b.boundExactly(Router, routers); b.bound(link, routers.product(routers)); // b.bound(site, routers.product(sites)); final TupleSet routerLocations = f.noneOf(2); for (int i = 0; i <= siteMax; i++) { routerLocations.add(f.tuple("Router" + i, "Site" + i)); } b.boundExactly(site, routerLocations); return b; }
Example 5
Source File: A4SolutionReader.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** Parse tuples. */ private TupleSet parseTuples(XMLNode tuples, int arity) throws Err { TupleSet ans = factory.noneOf(arity); for (XMLNode sub : tuples) if (sub.is("tuple")) ans.add(parseTuple(sub, arity)); return ans; }
Example 6
Source File: IntTest.java From kodkod with MIT License | 5 votes |
private IntExpression[] nonConstants() { final Options options = solver.options(); final IntRange range = options.integers(); final int min = range.min(), max = range.max(); final int size = range.size(); final Relation[] r = new Relation[size]; final TupleFactory f = bounds.universe().factory(); for(int i = 0; i < size; i++) { int arity = i%3 + 1; r[i] = Relation.nary("r"+i, arity); TupleSet b = f.noneOf(arity); for(int j = (i/3)*((int)Math.pow(SIZE, arity-1)), jmax = j+size; j < jmax; j++ ) { b.add(f.tuple(arity, j%b.capacity())); } bounds.bound(r[i], b); } final IntExpression[] vals = new IntExpression[max-min+1]; for(int i = 0; i < size; i++) { vals[i] = i+min < 0 ? r[i].count().negate() : r[i].count(); } return vals; }
Example 7
Source File: BugTests.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
public final void testFelix_01062007() { Relation x1 = Relation.nary("A", 1); List<String> atomlist = Arrays.asList("A"); Universe universe = new Universe(atomlist); TupleFactory factory = universe.factory(); Bounds bounds = new Bounds(universe); TupleSet x1_upper = factory.noneOf(1); x1_upper.add(factory.tuple("A")); bounds.bound(x1, x1_upper); Solver solver = new Solver(); solver.options().setSolver(SATFactory.MiniSat); Iterator<Solution> sols = solver.solveAll(Formula.TRUE, bounds); assertNotNull(sols.next().instance()); assertNotNull(sols.next().instance()); assertNull(sols.next().instance()); // Solution sol1=sols.next(); // System.out.println("Solution1:"+sol1.instance()); // // Solution sol2=sols.next(); // System.out.println("Solution2:"+sol2.instance()); // // Solution sol3=sols.next(); // System.out.println("Solution3:"+sol3.instance()); }
Example 8
Source File: TranslateAlloyToKodkod.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
private TupleSet convert(TupleFactory factory, Expr f) throws Err { TupleSet old = ((A4TupleSet) (partial.eval(f))).debugGetKodkodTupleset(); TupleSet ans = factory.noneOf(old.arity()); for (Tuple oldT : old) { Tuple newT = null; for (int i = 0; i < oldT.arity(); i++) { if (newT == null) newT = factory.tuple(oldT.atom(i)); else newT = newT.product(factory.tuple(oldT.atom(i))); } ans.add(newT); } return ans; }
Example 9
Source File: BasicUniverse.java From quetzal with Eclipse Public License 2.0 | 5 votes |
public TupleSet predicatesTableTuples(final TupleFactory tf) { TupleSet tuples = tf.noneOf(1); for(URI bn : predicates) { tuples.add(tf.tuple(bn)); } return tuples; }
Example 10
Source File: ALG195.java From kodkod with MIT License | 5 votes |
/** * Returns the bounds the problem (axioms 1, 4, 9-13, second formula of 14-15, and first formula of 16-22). * @return the bounds for the problem */ public final Bounds bounds() { final Bounds b = super.bounds(); final TupleFactory f = b.universe().factory(); final TupleSet op1h = b.upperBound(op1).clone(); final TupleSet op2h = b.upperBound(op2).clone(); for(int i = 0; i < 7; i++) { op1h.remove(f.tuple("e1"+i, "e1"+i, "e1"+i)); // axiom 12 op2h.remove(f.tuple("e2"+i, "e2"+i, "e2"+i)); // axiom 13 } final TupleSet op1l = f.setOf(f.tuple("e15", "e15", "e11")); // axiom 14, line 2 final TupleSet op2l = f.setOf(f.tuple("e25", "e25", "e21")); // axiom 15, line 2 op1h.removeAll(f.area(f.tuple("e15", "e15", "e10"), f.tuple("e15", "e15", "e16"))); op1h.addAll(op1l); op2h.removeAll(f.area(f.tuple("e25", "e25", "e20"), f.tuple("e25", "e25", "e26"))); op2h.addAll(op2l); b.bound(op1, op1l, op1h); b.bound(op2, op2l, op2h); final TupleSet high = f.area(f.tuple("e10", "e20"), f.tuple("e14", "e26")); high.addAll(f.area(f.tuple("e16", "e20"), f.tuple("e16", "e26"))); // first line of axioms 16-22 for(int i = 0; i < 7; i++) { Tuple t = f.tuple("e15", "e2"+i); high.add(t); b.bound(h[i], f.setOf(t), high); high.remove(t); } return b; }
Example 11
Source File: MagicSeries.java From kodkod with MIT License | 5 votes |
/** * Bounds for a series with the given maximum. * @return bounds for a series with the given maximum. */ public final Bounds bounds(int max) { if (max<1) throw new IllegalArgumentException("max must be 1 or greater: " + max); final List<Integer> atoms = new ArrayList<Integer>(max); for(int i = 0; i <= max; i++) { atoms.add(i); } final Universe u = new Universe(atoms); final TupleFactory f = u.factory(); final Bounds b = new Bounds(u); b.boundExactly(num, f.allOf(1)); final int numBits = 32-Integer.numberOfLeadingZeros(max); final TupleSet bitAtoms = f.noneOf(1); for(int i = 0; i < numBits; i++) { bitAtoms.add(f.tuple(1<<i)); b.boundExactly(1<<i, f.setOf(1<<i)); } b.bound(el, f.allOf(1).product(bitAtoms)); final TupleSet num2bits = f.noneOf(2); for(int i = 0; i <= max; i++) { for(int j = 0; j < numBits; j++) { final int bit = 1<<j; if ((i&bit)!=0) num2bits.add(f.tuple((Object)i, bit)); } } b.boundExactly(bits, num2bits); // b.bound(el, f.allOf(2)); // for(int i = 0; i<=max; i++) { // b.boundExactly(i, f.setOf(i)); // } return b; }
Example 12
Source File: NQueens.java From kodkod with MIT License | 5 votes |
/** * Returns the bounds for relational encoding of the problem. * @return the bounds for relational encoding of the problem. */ public Bounds bounds() { final List<Object> atoms = new ArrayList<Object>(n*2); for(int i =0; i < n; i++) { atoms.add("Q"+i); } for(int i =0; i < n; i++) { atoms.add(Integer.valueOf(i)); } final Universe u = new Universe(atoms); final Bounds b = new Bounds(u); final TupleFactory f = u.factory(); final TupleSet qbound = f.range(f.tuple("Q0"), f.tuple("Q"+(n-1))); final TupleSet nbound = f.range(f.tuple(Integer.valueOf(0)), f.tuple(Integer.valueOf(n-1))); b.boundExactly(queen, qbound); b.boundExactly(num, nbound); b.bound(x, qbound.product(nbound)); b.bound(y, qbound.product(nbound)); final TupleSet obound = f.noneOf(2); for(int i = 1; i < n; i++) { obound.add(f.tuple((Object)Integer.valueOf(i-1), Integer.valueOf(i))); } b.boundExactly(ord, obound); for(int i = 0; i < n; i++) { b.boundExactly(i, f.setOf(Integer.valueOf(i))); } return b; }
Example 13
Source File: ALG197.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** * Returns the bounds the problem (axioms 1, 4, 9-11, last formula of 14-15, and * first formula of 16-22). * * @return the bounds for the problem */ @Override public final Bounds bounds() { final Bounds b = super.bounds(); final TupleFactory f = b.universe().factory(); final TupleSet op1h = b.upperBound(op1).clone(); final TupleSet op2h = b.upperBound(op2).clone(); final TupleSet op1l = f.setOf(f.tuple("e16", "e16", "e15")); // axiom // 14, // line // 6 final TupleSet op2l = f.setOf(f.tuple("e26", "e26", "e25")); // axiom // 15, // line // 6 op1h.removeAll(f.area(f.tuple("e16", "e16", "e10"), f.tuple("e16", "e16", "e16"))); op1h.addAll(op1l); op2h.removeAll(f.area(f.tuple("e26", "e26", "e20"), f.tuple("e26", "e26", "e26"))); op2h.addAll(op2l); b.bound(op1, op1l, op1h); b.bound(op2, op2l, op2h); final TupleSet high = f.area(f.tuple("e10", "e20"), f.tuple("e15", "e26")); // first line of axioms 16-22 for (int i = 0; i < 7; i++) { Tuple t = f.tuple("e16", "e2" + i); high.add(t); b.bound(h[i], f.setOf(t), high); high.remove(t); } return b; }
Example 14
Source File: ALG197.java From kodkod with MIT License | 5 votes |
/** * Returns the bounds the problem (axioms 1, 4, 9-11, last formula of 14-15, and first formula of 16-22). * @return the bounds for the problem */ public final Bounds bounds() { final Bounds b = super.bounds(); final TupleFactory f = b.universe().factory(); final TupleSet op1h = b.upperBound(op1).clone(); final TupleSet op2h = b.upperBound(op2).clone(); final TupleSet op1l = f.setOf(f.tuple("e16", "e16", "e15")); // axiom 14, line 6 final TupleSet op2l = f.setOf(f.tuple("e26", "e26", "e25")); // axiom 15, line 6 op1h.removeAll(f.area(f.tuple("e16", "e16", "e10"), f.tuple("e16", "e16", "e16"))); op1h.addAll(op1l); op2h.removeAll(f.area(f.tuple("e26", "e26", "e20"), f.tuple("e26", "e26", "e26"))); op2h.addAll(op2l); b.bound(op1, op1l, op1h); b.bound(op2, op2l, op2h); final TupleSet high = f.area(f.tuple("e10", "e20"), f.tuple("e15", "e26")); // first line of axioms 16-22 for(int i = 0; i < 7; i++) { Tuple t = f.tuple("e16", "e2"+i); high.add(t); b.bound(h[i], f.setOf(t), high); high.remove(t); } return b; }
Example 15
Source File: BugTests.java From org.alloytools.alloy with Apache License 2.0 | 4 votes |
public final void testFelix_06192008() { Relation x5 = Relation.unary("R"); List<String> atomlist = Arrays.asList("X"); 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("X")); bounds.bound(x5, x5_upper); Variable x10 = Variable.unary("a"); Expression x11 = x5.difference(x5); Decls x9 = x10.oneOf(x11); Variable x14 = Variable.nary("b", 2); Expression x15 = x5.product(x5); Decls x13 = x14.setOf(x15); Expression x19 = x5.product(x5); Formula x17 = x14.in(x19); Expression x22 = x10.product(x10); Formula x21 = x22.eq(x14); Formula x16 = x17.and(x21); Formula x12 = x16.forSome(x13); Formula x7 = x12.forAll(x9); // System.out.println(x7); 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); // System.out.println("Depth=0..."); System.out.flush(); solver.options().setSkolemDepth(0); assertEquals(Solution.Outcome.TRIVIALLY_SATISFIABLE, solver.solve(x7, bounds).outcome()); // System.out.println("Depth=1..."); System.out.flush(); solver.options().setSkolemDepth(1); final Solution sol = solver.solve(x7, bounds); assertEquals(Solution.Outcome.SATISFIABLE, sol.outcome()); assertEquals(2, sol.instance().relations().size()); for (Relation r : sol.instance().relations()) { assertTrue(sol.instance().tuples(r).isEmpty()); } }
Example 16
Source File: BugTests.java From org.alloytools.alloy with Apache License 2.0 | 4 votes |
public final void testFelix_03062008_2() { Relation x5 = Relation.unary("Role"); Relation x6 = Relation.unary("Session"); List<String> atomlist = Arrays.asList("Role$0", "Session$0", "Session$1"); 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("Role$0")); bounds.bound(x5, x5_upper); TupleSet x6_upper = factory.noneOf(1); x6_upper.add(factory.tuple("Session$0")); x6_upper.add(factory.tuple("Session$1")); bounds.bound(x6, x6_upper); Variable x11 = Variable.unary("x_a"); Decls x10 = x11.oneOf(x6); Variable x15 = Variable.unary("x_b"); Decls x14 = x15.oneOf(x5); Variable x17 = Variable.unary("x_c"); Decls x16 = x17.oneOf(x5); Decls x13 = x14.and(x16); Expression x20 = x15.product(x17); Expression x19 = x11.product(x20); Formula x18 = x19.some(); Formula x12 = x18.forSome(x13); Formula x9 = x12.forAll(x10); Formula x24 = x5.some(); Formula x23 = x24.not(); Formula x28 = x5.eq(x5); Formula x29 = x6.eq(x6); Formula x25 = x28.and(x29); Formula x22 = x23.and(x25); Formula x8 = x9.and(x22).and(x5.no()).and(x6.no()); Solver solver = new Solver(); solver.options().setSolver(SATFactory.DefaultSAT4J); solver.options().setBitwidth(2); // solver.options().setFlatten(false); solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT); solver.options().setSymmetryBreaking(20); solver.options().setSkolemDepth(2); System.out.flush(); Solution sol = solver.solve(x8, bounds); Instance inst = sol.instance(); assertNotNull(inst); for (Relation rel : inst.relations()) { if (rel != x5 && rel != x6) { final TupleSet range = inst.tuples(x6).product(inst.tuples(x5)); assertTrue(range.containsAll(inst.tuples(rel))); } } }
Example 17
Source File: RegressionTests.java From kodkod with MIT License | 4 votes |
@Test public final void testBGP_03172011() { Relation x5 = Relation.unary("s012"); Relation x8 = Relation.unary("zero"); Relation x9 = Relation.unary("one"); Relation x12 = Relation.nary("next", 2); Universe universe = new Universe(Arrays.asList( "0", "1", "2", "3")); TupleFactory factory = universe.factory(); Bounds bounds = new Bounds(universe); bounds.boundExactly(x5, factory.setOf("0","1","2")); bounds.boundExactly(x8, factory.setOf("0")); bounds.bound(x9, factory.setOf("1"), factory.setOf("1","2")); TupleSet x12_upper = factory.noneOf(2); x12_upper.add(factory.tuple("1","2")); x12_upper.add(factory.tuple("2","3")); bounds.boundExactly(x12, x12_upper); Variable x714 = Variable.unary("x714"); Decls x713 = x714.oneOf(x8.union(x9)); Variable x720 = Variable.unary("x720"); Expression x723 = x8.union(x9); Expression x724 = x9.join(x12); Expression x722 = x723.union(x724); Expression x721 = x722.difference(x714); Decls x719 = x720.oneOf(x721); Variable x727 = Variable.unary("x727"); Expression x732 = x714.union(x720); Expression x728 = x5.difference(x732); Decls x726 = x727.oneOf(x728); Variable x735 = Variable.unary("x735"); Decls x734 = x735.oneOf(x8); Variable x893 = Variable.unary("x893"); Decls x892 = x893.oneOf(x727); Formula x894 = x720.no(); Formula x891 = x894.forAll(x892); Formula x712 = x891.forSome(x713.and(x719).and(x726).and(x734)); Formula x267 = Formula.FALSE.or(x712); Solver solver = new Solver(); solver.options().setSolver(SATFactory.MiniSat); solver.options().setBitwidth(4); solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT); solver.options().setSymmetryBreaking(20); solver.options().setSkolemDepth(0); final Solution sol = solver.solve(x267, bounds); assertEquals(sol.outcome(), Solution.Outcome.TRIVIALLY_UNSATISFIABLE); }
Example 18
Source File: BugTests.java From org.alloytools.alloy with Apache License 2.0 | 4 votes |
public final void testBGP_03172011() { Relation x5 = Relation.unary("s012"); Relation x8 = Relation.unary("zero"); Relation x9 = Relation.unary("one"); Relation x12 = Relation.nary("next", 2); Universe universe = new Universe(Arrays.asList("0", "1", "2", "3")); TupleFactory factory = universe.factory(); Bounds bounds = new Bounds(universe); bounds.boundExactly(x5, factory.setOf("0", "1", "2")); bounds.boundExactly(x8, factory.setOf("0")); bounds.bound(x9, factory.setOf("1"), factory.setOf("1", "2")); TupleSet x12_upper = factory.noneOf(2); x12_upper.add(factory.tuple("1", "2")); x12_upper.add(factory.tuple("2", "3")); bounds.boundExactly(x12, x12_upper); Variable x714 = Variable.unary("x714"); Decls x713 = x714.oneOf(x8.union(x9)); Variable x720 = Variable.unary("x720"); Expression x723 = x8.union(x9); Expression x724 = x9.join(x12); Expression x722 = x723.union(x724); Expression x721 = x722.difference(x714); Decls x719 = x720.oneOf(x721); Variable x727 = Variable.unary("x727"); Expression x732 = x714.union(x720); Expression x728 = x5.difference(x732); Decls x726 = x727.oneOf(x728); Variable x735 = Variable.unary("x735"); Decls x734 = x735.oneOf(x8); Variable x893 = Variable.unary("x893"); Decls x892 = x893.oneOf(x727); Formula x894 = x720.no(); Formula x891 = x894.forAll(x892); Formula x712 = x891.forSome(x713.and(x719).and(x726).and(x734)); Formula x267 = Formula.FALSE.or(x712); 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(20); solver.options().setSkolemDepth(0); final Solution sol = solver.solve(x267, bounds); assertEquals(sol.outcome(), Solution.Outcome.TRIVIALLY_UNSATISFIABLE); }
Example 19
Source File: RegressionTests.java From kodkod with MIT License | 4 votes |
@Test public final void testFelix_06192008() { Relation x5 = Relation.unary("R"); List<String> atomlist = Arrays.asList("X"); 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("X")); bounds.bound(x5, x5_upper); Variable x10=Variable.unary("a"); Expression x11=x5.difference(x5); Decls x9=x10.oneOf(x11); Variable x14=Variable.nary("b",2); Expression x15=x5.product(x5); Decls x13=x14.setOf(x15); Expression x19=x5.product(x5); Formula x17=x14.in(x19); Expression x22=x10.product(x10); Formula x21=x22.eq(x14); Formula x16=x17.and(x21); Formula x12=x16.forSome(x13); Formula x7= x12.forAll(x9); // System.out.println(x7); Solver solver = new Solver(); solver.options().setSolver(SATFactory.DefaultSAT4J); solver.options().setBitwidth(4); solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT); solver.options().setSymmetryBreaking(20); // System.out.println("Depth=0..."); System.out.flush(); solver.options().setSkolemDepth(0); assertEquals(Solution.Outcome.TRIVIALLY_SATISFIABLE, solver.solve(x7, bounds).outcome()); // System.out.println("Depth=1..."); System.out.flush(); solver.options().setSkolemDepth(1); final Solution sol = solver.solve(x7, bounds); assertEquals(Solution.Outcome.SATISFIABLE, sol.outcome()); assertEquals(2, sol.instance().relations().size()); for(Relation r : sol.instance().relations()) { assertTrue(sol.instance().tuples(r).isEmpty()); } }
Example 20
Source File: BugTests.java From org.alloytools.alloy with Apache License 2.0 | 4 votes |
public final void testFelix_11122006() { Relation x0 = Relation.nary("Q", 1); Relation x1 = Relation.nary("B", 1); Relation x2 = Relation.nary("A", 1); Relation x3 = Relation.nary("QQ", 3); List<String> atomlist = Arrays.asList("A", "B", "Q"); 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("Q")); bounds.boundExactly(x0, x0_upper); TupleSet x1_upper = factory.noneOf(1); x1_upper.add(factory.tuple("B")); bounds.boundExactly(x1, x1_upper); TupleSet x2_upper = factory.noneOf(1); x2_upper.add(factory.tuple("A")); bounds.boundExactly(x2, x2_upper); TupleSet x3_upper = factory.noneOf(3); x3_upper.add(factory.tuple("Q").product(factory.tuple("A")).product(factory.tuple("A"))); x3_upper.add(factory.tuple("Q").product(factory.tuple("B")).product(factory.tuple("B"))); bounds.bound(x3, x3_upper); Expression x7 = x2.product(x2); Expression x8 = x0.join(x3); Formula x6 = x7.in(x8); Formula x5 = x6.not(); Expression x18 = x1.product(x1); Expression x17 = x7.union(x18); Expression x16 = x0.product(x17); Formula x15 = x3.in(x16); Formula x4 = x5.and(x15); Solver solver = new Solver(); solver.options().setSolver(SATFactory.DefaultSAT4J); solver.options().setBitwidth(4); solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT); // System.out.println(bounds); // System.out.println(x4); Solution sol = solver.solve(x4, bounds); assertEquals(sol.outcome(), Solution.Outcome.SATISFIABLE); // System.out.println(sol.toString()); }