Java Code Examples for kodkod.instance.TupleFactory#area()

The following examples show how to use kodkod.instance.TupleFactory#area() . 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: ALG197.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * 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 2
Source File: Quasigroups7.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();

    b.boundExactly(s1, f.range(f.tuple("e10"), f.tuple("e16")));
    b.boundExactly(s2, f.range(f.tuple("e20"), f.tuple("e26")));

    // 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
    final TupleSet op1h = f.area(f.tuple("e10", "e10", "e10"), f.tuple("e16", "e16", "e16"));
    // axiom 4
    final TupleSet op2h = f.area(f.tuple("e20", "e20", "e20"), f.tuple("e26", "e26", "e26"));

    b.bound(op1, op1h);
    b.bound(op2, op2h);

    return b;
}
 
Example 3
Source File: ALG197.java    From kodkod with MIT License 5 votes vote down vote up
/**
 * 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 4
Source File: ALG195.java    From kodkod with MIT License 5 votes vote down vote up
/**
 * 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 5
Source File: Quasigroups7.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();
	
	b.boundExactly(s1, f.range(f.tuple("e10"), f.tuple("e16")));
	b.boundExactly(s2, f.range(f.tuple("e20"), f.tuple("e26")));
	
	// 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
	final TupleSet op1h = f.area(f.tuple("e10", "e10", "e10"), f.tuple("e16", "e16", "e16"));
	// axiom 4
	final TupleSet op2h = f.area(f.tuple("e20", "e20", "e20"), f.tuple("e26", "e26", "e26"));
	
	b.bound(op1, op1h);
	b.bound(op2, op2h);
	
	return b;
}
 
Example 6
Source File: ALG195.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
/**
 * 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
 */
@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();

    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 7
Source File: BugTests.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
public final void testVincent_02172006() {
    // 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();

    final Relation oneRel = Relation.unary("oneRel");
    final Relation pCourses = Relation.binary("pCourses");
    final Relation prev = Relation.binary("prev");
    final Relation sCourses = Relation.binary("sCourses");
    final Relation prereqs = Relation.binary("prereqs");
    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));

    // list1 and list2 are temp lists for creating bounds for binary
    // relations below
    // list1 = [1, 2]
    // list2 = [3, 2]
    // ts = [ [1, 2], [2, 2], [3, 2] ]
    List<Integer> list1 = new ArrayList<Integer>();
    list1.add(atoms.get(0));
    list1.add(atoms.get(1));
    List<Integer> list2 = new ArrayList<Integer>();
    list2.add(atoms.get(2));
    list2.add(atoms.get(1));
    TupleSet ts = factory.area(factory.tuple(list1), factory.tuple(list2));

    bounds.bound(pCourses, ts);
    bounds.bound(prev, ts);
    bounds.bound(sCourses, ts);
    bounds.bound(prereqs, ts);

    // all s: futureSemesters | all c: s.courses | no c.prereqs or some p:
    // c.prereqs | p.courses in s.prev^.courses
    final Variable s = Variable.unary("s"), c = Variable.unary("c"), p = Variable.unary("p");
    Formula formula = (p.join(pCourses).in(s.join(prev.closure()).join(sCourses)).forAll(p.oneOf(c.join(prereqs)))).forAll(c.oneOf(s.join(sCourses))).forAll(s.oneOf(rel));

    // System.out.println(formula);
    // solve

    final Instance instance = solver.solve(formula, bounds).instance();
    assertNotNull(instance);

}
 
Example 8
Source File: RegressionTests.java    From kodkod with MIT License 4 votes vote down vote up
@Test
public final void testVincent_02172006() {
	// 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();

	final Relation oneRel = Relation.unary("oneRel");
	final Relation pCourses = Relation.binary("pCourses");
	final Relation prev = Relation.binary("prev");
	final Relation sCourses = Relation.binary("sCourses");
	final Relation prereqs = Relation.binary("prereqs");
	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));

	// list1 and list2 are temp lists for creating bounds for binary relations below
	// list1 = [1, 2]
	// list2 = [3, 2]
	// ts = [ [1, 2], [2, 2], [3, 2] ]
	List<Integer> list1 = new ArrayList<Integer>();
	list1.add(atoms.get(0));
	list1.add(atoms.get(1));                       
	List<Integer> list2 = new ArrayList<Integer>();
	list2.add(atoms.get(2));
	list2.add(atoms.get(1));                
	TupleSet ts = factory.area(factory.tuple(list1),
			factory.tuple(list2));

	bounds.bound(pCourses, ts);
	bounds.bound(prev, ts);
	bounds.bound(sCourses, ts);
	bounds.bound(prereqs, ts);                       


	// all s: futureSemesters | all c: s.courses | no c.prereqs or some p: c.prereqs | p.courses in s.prev^.courses 
	final Variable s = Variable.unary("s"), c = Variable.unary("c"), p =
		Variable.unary("p");        
	Formula formula = 
		(p.join(pCourses).in(s.join(prev.closure()).join(sCourses)).
				forAll(p.oneOf(c.join(prereqs)))).
				forAll(c.oneOf(s.join(sCourses))).
				forAll(s.oneOf(rel));

	//        System.out.println(formula);
	// solve   

	final Instance instance = solver.solve(formula, bounds).instance();
	assertNotNull(instance);



}