Java Code Examples for kodkod.ast.Relation#arity()
The following examples show how to use
kodkod.ast.Relation#arity() .
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: SymmetryBreaker.java From org.alloytools.alloy with Apache License 2.0 | 6 votes |
/** * If all columns of the upper bound of r are symmetric partitions, those * partitions are returned. Otherwise null is returned. * * @return (all i: [0..r.arity) | some s: symmetries[int] | * bounds.upperBound[r].project(i).indexView() = s) => {colParts: * [0..r.arity)->IntSet | all i: [0..r.arity()) | colParts[i] = * bounds.upperBound[r].project(i).indexView() }, null */ private final IntSet[] symmetricColumnPartitions(Relation r) { final IntSet upper = bounds.upperBound(r).indexView(); if (upper.isEmpty()) return null; final IntSet[] colParts = new IntSet[r.arity()]; for (int i = r.arity() - 1, min = upper.min(); i >= 0; i--, min /= usize) { for (IntSet part : symmetries) { if (part.contains(min % usize)) { colParts[i] = part; break; } } if (colParts[i] == null) return null; } for (IntIterator tuples = upper.iterator(); tuples.hasNext();) { for (int i = r.arity() - 1, tuple = tuples.next(); i >= 0; i--, tuple /= usize) { if (!colParts[i].contains(tuple % usize)) return null; } } return colParts; }
Example 2
Source File: SymmetryBreaker.java From kodkod with MIT License | 6 votes |
/** * If all columns of the upper bound of r are symmetric partitions, * those partitions are returned. Otherwise null is returned. * @return (all i: [0..r.arity) | some s: symmetries[int] | * bounds.upperBound[r].project(i).indexView() = s) => * {colParts: [0..r.arity)->IntSet | * all i: [0..r.arity()) | colParts[i] = bounds.upperBound[r].project(i).indexView() }, * null */ private final IntSet[] symmetricColumnPartitions(Relation r) { final IntSet upper = bounds.upperBound(r).indexView(); if (upper.isEmpty()) return null; final IntSet[] colParts = new IntSet[r.arity()]; for(int i = r.arity()-1, min = upper.min(); i >= 0; i--, min /= usize) { for(IntSet part : symmetries) { if (part.contains(min%usize)) { colParts[i] = part; break; } } if (colParts[i]==null) return null; } for(IntIterator tuples = upper.iterator(); tuples.hasNext(); ) { for(int i = r.arity()-1, tuple = tuples.next(); i >= 0; i--, tuple /= usize) { if (!colParts[i].contains(tuple%usize)) return null; } } return colParts; }
Example 3
Source File: BasicUniverse.java From quetzal with Eclipse Public License 2.0 | 5 votes |
@Override public Bounds boundUniverse(Set<Relation> liveRelations) throws URISyntaxException { Universe u = new Universe(universe()); TupleFactory tf = u.factory(); Bounds b = new Bounds(u); Set<Object> liveAtoms; // if (! (this instanceof BoundedUniverse)) { // liveAtoms = basicBounds(liveRelations, u, tf, b); // u = new Universe(liveAtoms); // tf = u.factory(); // b = new Bounds(u); // basicBounds(liveRelations, u, tf, b); // } else { liveAtoms = universe(); basicBounds(liveRelations, u, tf, b); // } b.boundExactly(QuadTableRelations.NULL, tf.setOf(tf.tuple(QuadTableRelations.NULL_atom))); for(Relation r : nodeRelations) { int arity = r.arity(); TupleSet rb = nodesTableBound(tf, liveAtoms, true, true, true).tuples(); rb.add(tf.tuple(QuadTableRelations.NULL_atom)); for(int i = 1; i < arity; i++) { TupleSet rbi = nodesTableBound(tf, liveAtoms, true, true, true).tuples(); rbi.add(tf.tuple(QuadTableRelations.NULL_atom)); rb = rb.product(rbi); } b.bound(r, rb); } return b; }
Example 4
Source File: BugTests.java From org.alloytools.alloy with Apache License 2.0 | 4 votes |
public final void testFelix_02222008() { List<String> atomlist = Arrays.asList("X1", "X2", "X3"); Universe universe = new Universe(atomlist); TupleFactory factory = universe.factory(); Bounds bounds = new Bounds(universe); Relation x = Relation.unary("X"); TupleSet x_upper = factory.noneOf(1); x_upper.add(factory.tuple("X1")); x_upper.add(factory.tuple("X2")); x_upper.add(factory.tuple("X3")); bounds.bound(x, x_upper); Variable a = Variable.unary("a"); Variable b = Variable.unary("b"); Variable c = Variable.unary("c"); Formula goal = x.lone().not().and(b.union(c).eq(a).forSome(c.oneOf(x)).forAll(b.oneOf(x)).forSome(a.setOf(x))); Solver solver = new Solver(); solver.options().setSolver(SATFactory.DefaultSAT4J); solver.options().setBitwidth(4); solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT); solver.options().setSymmetryBreaking(0); solver.options().setSkolemDepth(2); Iterator<Solution> itr = solver.solveAll(goal, bounds); int sols = 0; while (itr.hasNext()) { Solution sol = itr.next(); Instance inst = sol.instance(); if (inst == null) break; sols++; for (Relation rel : inst.relations()) { if (rel != x) { if (rel.arity() == 1) { // rel = a assertEquals(inst.tuples(x), inst.tuples(rel)); } else { // rel = c final TupleSet dom = factory.noneOf(1); for (Tuple t : inst.tuples(rel)) { dom.add(factory.tuple(t.atom(0))); } assertEquals(inst.tuples(x), dom); } } } } assertEquals(3, sols); }
Example 5
Source File: RegressionTests.java From kodkod with MIT License | 4 votes |
@Test public final void testFelix_02222008() { List<String> atomlist = Arrays.asList("X1", "X2", "X3"); Universe universe = new Universe(atomlist); TupleFactory factory = universe.factory(); Bounds bounds = new Bounds(universe); Relation x = Relation.unary("X"); TupleSet x_upper = factory.noneOf(1); x_upper.add(factory.tuple("X1")); x_upper.add(factory.tuple("X2")); x_upper.add(factory.tuple("X3")); bounds.bound(x, x_upper); Variable a = Variable.unary("a"); Variable b = Variable.unary("b"); Variable c = Variable.unary("c"); Formula goal = x.lone().not().and(b.union(c).eq(a).forSome(c.oneOf(x)).forAll(b.oneOf(x)).forSome(a.setOf(x))); Solver solver = new Solver(); solver.options().setSolver(SATFactory.DefaultSAT4J); solver.options().setBitwidth(4); solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT); solver.options().setSymmetryBreaking(0); solver.options().setSkolemDepth(2); Iterator<Solution> itr = solver.solveAll(goal, bounds); int sols = 0; while(itr.hasNext()) { Solution sol = itr.next(); Instance inst = sol.instance(); if (inst==null) break; sols++; for(Relation rel : inst.relations()) { if (rel!=x) { if( rel.arity()==1) { // rel = a assertEquals(inst.tuples(x), inst.tuples(rel)); } else { // rel = c final TupleSet dom = factory.noneOf(1); for(Tuple t : inst.tuples(rel)) { dom.add(factory.tuple(t.atom(0))); } assertEquals(inst.tuples(x), dom); } } } } assertEquals(3, sols); }
Example 6
Source File: Instance.java From org.alloytools.alloy with Apache License 2.0 | 3 votes |
/** * Maps the given relation to the given tuple set. * * @ensures this.tuples' = this.tuples ++ relation->s * @throws NullPointerException relation = null || s = null * @throws IllegalArgumentException relation.arity != s.arity * @throws IllegalArgumentException s.universe != this.universe * @throws UnsupportedOperationException this is an unmodifiable instance */ public void add(final Relation relation, TupleSet s) { if (!s.universe().equals(universe)) throw new IllegalArgumentException("s.universe!=this.universe"); if (relation.arity() != s.arity()) throw new IllegalArgumentException("relation.arity!=s.arity"); TupleSet val = s.clone().unmodifiableView(); tuples.put(relation, val); }
Example 7
Source File: Instance.java From kodkod with MIT License | 3 votes |
/** * Maps the given relation to the given tuple set. * @ensures this.tuples' = this.tuples ++ relation->s * @throws NullPointerException relation = null || s = null * @throws IllegalArgumentException relation.arity != s.arity * @throws IllegalArgumentException s.universe != this.universe * @throws UnsupportedOperationException this is an unmodifiable instance */ public void add(final Relation relation, TupleSet s) { if (!s.universe().equals(universe)) throw new IllegalArgumentException("s.universe!=this.universe"); if (relation.arity()!=s.arity()) throw new IllegalArgumentException("relation.arity!=s.arity"); tuples.put(relation, s.clone().unmodifiableView()); }