Java Code Examples for kodkod.instance.TupleSet#product()

The following examples show how to use kodkod.instance.TupleSet#product() . 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: ALG195_1.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 2
Source File: SymmetryBreakingTest.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
public void testAcyclic() {
    bounds.bound(ac1, factory.area(factory.tuple("0", "0"), factory.tuple("4", "4")));
    assertNotNull(solve(ac1.some().and(ac1.acyclic())));
    assertPrimVarNum(10);

    bounds.bound(r1, factory.range(factory.tuple("0"), factory.tuple("4")));
    assertNotNull(solve(ac1.join(r1).some().and(ac1.acyclic())));
    assertPrimVarNum(10 + bounds.upperBound(r1).size());

    TupleSet ac2b = factory.setOf("5", "6", "7", "8");
    ac2b = ac2b.product(ac2b);
    bounds.bound(ac2, ac2b);
    assertNotNull(solve(ac1.difference(ac2).some().and(ac1.acyclic()).and(ac2.acyclic())));
    assertPrimVarNum(10 + 6);

    bounds.boundExactly(r2, factory.setOf(factory.tuple("5", "6")));
    assertNotNull(solve(ac2.join(r2).some().and(ac2.acyclic())));

    final TupleSet ac3Bound = factory.allOf(2);
    ac3Bound.remove(factory.tuple("9", "9"));
    bounds.bound(ac3, ac3Bound);

    assertNotNull(solve(ac1.difference(ac2).union(ac3).some().and(ac1.acyclic()).and(ac2.acyclic())));
    assertPrimVarNum(ac3Bound.size() + 10 + 6);

    bounds.bound(to3, factory.allOf(2));
    bounds.bound(ord3, factory.setOf("0", "1", "2"));
    bounds.bound(first3, bounds.upperBound(ord3));
    bounds.bound(last3, bounds.upperBound(ord3));
    assertNotNull(solve(to3.product(ac1).some().and(ac1.acyclic()).and(to3.totalOrder(ord3, first3, last3))));
    assertPrimVarNum(bounds.upperBound(ac1).size());
}
 
Example 3
Source File: ALG195_1.java    From kodkod with MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example 4
Source File: SymmetryBreakingTest.java    From kodkod with MIT License 5 votes vote down vote up
@Test
public final void testAcyclic() {
	bounds.bound(ac1, factory.area(factory.tuple("0","0"), factory.tuple("4","4")));
	assertNotNull(solve(ac1.some().and(ac1.acyclic())));
	assertPrimVarNum(10);
	
	bounds.bound(r1, factory.range(factory.tuple("0"), factory.tuple("4")));
	assertNotNull(solve(ac1.join(r1).some().and(ac1.acyclic())));
	assertPrimVarNum(10 + bounds.upperBound(r1).size());
	
	
	TupleSet ac2b = factory.setOf("5","6","7","8");
	ac2b = ac2b.product(ac2b);
	bounds.bound(ac2, ac2b);
	assertNotNull(solve(ac1.difference(ac2).some().and(ac1.acyclic()).and(ac2.acyclic())));
	assertPrimVarNum(10 + 6);
	
	bounds.boundExactly(r2, factory.setOf(factory.tuple("5", "6")));
	assertNotNull(solve(ac2.join(r2).some().and(ac2.acyclic())));
	
	final TupleSet ac3Bound = factory.allOf(2);
	ac3Bound.remove(factory.tuple("9", "9"));
	bounds.bound(ac3, ac3Bound);
	
	assertNotNull(solve(ac1.difference(ac2).union(ac3).some().and(ac1.acyclic()).and(ac2.acyclic())));
	assertPrimVarNum(ac3Bound.size() + 10 + 6);
	
	bounds.bound(to3, factory.allOf(2));
	bounds.bound(ord3, factory.setOf("0","1","2"));
	bounds.bound(first3, bounds.upperBound(ord3));
	bounds.bound(last3, bounds.upperBound(ord3));
	assertNotNull(solve(to3.product(ac1).some().and(ac1.acyclic()).and(to3.totalOrder(ord3,first3,last3))));
	assertPrimVarNum(bounds.upperBound(ac1).size());
}
 
Example 5
Source File: BasicUniverse.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
@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;
	}