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

The following examples show how to use kodkod.instance.TupleFactory#noneOf() . 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 vote down vote up
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 2
Source File: ConfigAssure.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a tupleset that maps the given port atom to each non-zero bit in the
 * given bit string.
 *
 * @return a tupleset that maps the given port atom to each non-zero bit in the
 *         given bit string.
 */
private final TupleSet portToBits(TupleFactory factory, String port, int bits) {
    final TupleSet s = factory.noneOf(2);
    for (int i = 0, max = 32 - Integer.numberOfLeadingZeros(bits); i < max; i++) {
        if ((bits & (1 << i)) != 0)
            s.add(factory.tuple(port, Integer.valueOf(1 << i)));
    }
    return s;
}
 
Example 3
Source File: SudokuParser.java    From kodkod with MIT License 5 votes vote down vote up
/**
 * Returns the representation of the clues encoded in the given array as 
 * an NxNxN tuple set drawn from the given universe.  N is assumed
 * to be a perfect square, and the universe is assumed to consist of Integer objects in 
 * the range [1..N]. The  array is assumed to consist of N*N numbers, drawn 
 * from the set 0..N, inclusive, where a consecutive sequence of N
 * numbers represents one row of an NxN Sudoku grid.
 * Zeros stand for blank entries.  
 * @requires some r: int | puzzle.length = r * r * r * r
 * @requires universe.atoms[int] = {i: Integer | 1 <= i.intValue() <= puzzle.length} 
 * @return a tupleset representation of the clues in the puzzle specified by the given array.
 */
public static final TupleSet parse(String[] puzzle, Universe univ) { 
	final int n = (int)StrictMath.sqrt(puzzle.length);
	final int r = (int)StrictMath.sqrt(n);
	if (puzzle.length!=r*r*r*r)  throw new IllegalArgumentException("Not a valid puzzle spec: expected " + (r*r*r*r) + " numbers but found " + puzzle.length);
			
	final TupleFactory f = univ.factory();
	
	final TupleSet givens = f.noneOf(3);
	
	for(int i = 0; i < n; i++) { 
		for(int j = 0; j < n; j++) { 
			try {
				final int digit = Integer.parseInt(puzzle[i*n+j]);
				if (digit>0 && digit<=n) {
					final Tuple t = f.tuple(i+1, j+1, digit);
					givens.add(t);
				} else if (digit>n) { 
					throw new IllegalArgumentException("Not a valid puzzle spec: expected numbers from [0, " + n+"] but found "+digit);
				} 
			} catch (NumberFormatException nfe) { 
				throw new IllegalArgumentException("Not a valid puzzle spec: expected numbers from [0, " + n+"] but found "+puzzle[i*n+j]);
			}
		}
	}
	
	return givens;
}
 
Example 4
Source File: TranslateAlloyToKodkod.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
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 5
Source File: IntTest.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
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 6
Source File: RegressionTests.java    From kodkod with MIT License 5 votes vote down vote up
@Test
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 7
Source File: BugTests.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
public final void testFelix_05152007_1() {
    Relation x5 = Relation.nary("A", 1);

    List<String> atomlist = Arrays.asList("A0", "A1", "A2");

    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("A2"));
    x5_upper.add(factory.tuple("A1"));
    x5_upper.add(factory.tuple("A0"));

    bounds.bound(x5, x5_upper);

    Formula x7 = x5.some();
    Formula x8 = x5.no();

    Formula x6 = x7.and(x8);

    Solver solver = new Solver();
    solver.options().setLogTranslation(1);

    solver.options().setSolver(SATFactory.MiniSatProver);
    solver.options().setBitwidth(4);
    solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT);

    Solution sol = solver.solve(x6, bounds);

    // System.out.println("Sol="+sol);

    Set<Formula> core = Nodes.minRoots(x6, sol.proof().highLevelCore().values());
    assertEquals(2, core.size());
    assertTrue(core.contains(x7));
    assertTrue(core.contains(x8));

}
 
Example 8
Source File: BugTests.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
public final void testFelix_05152007_2() {
    Relation x5 = Relation.nary("A", 1);

    List<String> atomlist = Arrays.asList("A0", "A1", "A2");

    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("A2"));
    x5_upper.add(factory.tuple("A1"));
    x5_upper.add(factory.tuple("A0"));

    bounds.bound(x5, x5_upper);

    Formula x7 = x5.eq(x5).not();

    Solver solver = new Solver();

    solver.options().setLogTranslation(1);
    solver.options().setSolver(SATFactory.MiniSatProver);
    solver.options().setBitwidth(4);
    solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT);

    Solution sol = solver.solve(x7, bounds);
    Set<Formula> core = Nodes.minRoots(x7, sol.proof().highLevelCore().values());
    assertEquals(1, core.size());
    assertTrue(core.contains(x7));
}
 
Example 9
Source File: BugTests.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
public final void testFelix_05152007_3() {
    Relation x5 = Relation.nary("A", 1);

    List<String> atomlist = Arrays.asList("A[0]", "A[1]", "A[2]");

    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("A[0]"));
    x5_upper.add(factory.tuple("A[1]"));
    x5_upper.add(factory.tuple("A[2]"));

    bounds.bound(x5, x5_upper);

    Formula a = x5.some();
    Formula a1 = x5.no();
    Formula b = a1.and(Formula.TRUE.and(Formula.TRUE));
    Formula c = a.and(b);

    Solver solver = new Solver();

    solver.options().setLogTranslation(1);
    solver.options().setSolver(SATFactory.DefaultSAT4J);
    solver.options().setBitwidth(4);
    solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT);

    Solution sol = solver.solve(c, bounds);
    Set<Formula> core = Nodes.minRoots(c, sol.proof().highLevelCore().values());

    assertEquals(2, core.size());
    assertTrue(core.contains(a));
    assertTrue(core.contains(a1));

}
 
Example 10
Source File: GroupScheduling.java    From kodkod with MIT License 5 votes vote down vote up
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 11
Source File: RegressionTests.java    From kodkod with MIT License 5 votes vote down vote up
@Test
public final void testFelix_05152007_2() {
	Relation x5 = Relation.nary("A", 1);

	List<String> atomlist = Arrays.asList("A0", "A1", "A2");

	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("A2"));
	x5_upper.add(factory.tuple("A1"));
	x5_upper.add(factory.tuple("A0"));

	bounds.bound(x5, x5_upper);

	Formula x7=x5.eq(x5).not();

	Solver solver = new Solver();

	solver.options().setLogTranslation(1);
	solver.options().setSolver(SATFactory.MiniSatProver);
	solver.options().setBitwidth(4);
	solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT);

	Solution sol = solver.solve(x7,bounds);
	Set<Formula> core = Nodes.minRoots(x7, sol.proof().highLevelCore().values());
	assertEquals(1, core.size());
	assertTrue(core.contains(x7));
}
 
Example 12
Source File: BasicUniverse.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
public TupleSet objectsTableTuples(TupleFactory tf) {
	TupleSet tuples = tf.noneOf(1);
	for(Object bn : objects) {
		tuples.add(tf.tuple(bn));
	}

	return tuples;
}
 
Example 13
Source File: Transpose4x4UnaryL.java    From kodkod with MIT License 5 votes vote down vote up
/**
 * Returns relation bounds over a universe of interpretation consisting of integers 0 - 15, inclusive.
 * @return relation bounds over a universe of interpretation consisting of integers 0 - 15, inclusive.
 */
final Bounds bounds() {
	final Universe u = new Universe(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
	final TupleFactory f = u.factory();
	
	final Bounds b = new Bounds(u);
	
	// tell the solver to interpret integer objects as their corresponding integer values
	for (int i = 0; i < 16; i++)
		b.boundExactly(i, f.setOf(i));
	
	final TupleSet s3 = f.setOf(0, 1, 2, 3);        										// { 0, 1, 2, 3 }
	final TupleSet s12 = f.setOf(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12); 	// { 0, ..., 12 }
	for(int i = 0; i < 4; i++) {
		b.bound(mx1[i], s12);
		b.bound(mx2[i], s12);		
		b.bound(sx1[i], s12);
		b.bound(sx2[i], s12);
		for(int j = 0; j < 4; j++) {
			b.bound(mi[i][j], s3);
			b.bound(si[i][j], s3);
		}
	}
	
	final TupleSet ord = f.noneOf(2);  				// { [0, 1], [1, 2], [2, 3], ..., [14, 15] }
	for(int i = 0; i < 15; i++)
		ord.add(f.tuple((Object)i, i+1));
	b.boundExactly(succ, ord);
	
	return b;
}
 
Example 14
Source File: BugTests.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
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 15
Source File: BugTests.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
public final void testFelix_03162009() {
    Relation x = Relation.unary("X");
    Relation y = Relation.unary("Y");
    Relation q = Relation.unary("Q");
    Relation f = Relation.nary("f", 2);

    List<String> atomlist = Arrays.asList("X", "Y");

    Universe universe = new Universe(atomlist);
    TupleFactory factory = universe.factory();
    Bounds bounds = new Bounds(universe);

    TupleSet x_upper = factory.noneOf(1);
    x_upper.add(factory.tuple("X"));
    bounds.boundExactly(x, x_upper);

    TupleSet y_upper = factory.noneOf(1);
    y_upper.add(factory.tuple("Y"));
    bounds.boundExactly(y, y_upper);

    TupleSet q_upper = factory.noneOf(1);
    q_upper.add(factory.tuple("X"));
    q_upper.add(factory.tuple("Y"));
    bounds.bound(q, q_upper);

    TupleSet f_upper = factory.noneOf(2);
    f_upper.add(factory.tuple("X").product(factory.tuple("X")));
    f_upper.add(factory.tuple("X").product(factory.tuple("Y")));
    f_upper.add(factory.tuple("Y").product(factory.tuple("X")));
    f_upper.add(factory.tuple("Y").product(factory.tuple("Y")));
    bounds.bound(f, f_upper);

    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);
    solver.options().setSkolemDepth(0);

    Expression test = f.override(q.product(y));
    TupleSet approx = factory.setOf(test.arity(), Translator.approximate(test, bounds, solver.options()).denseIndices());
    assertEquals(f_upper, approx);
}
 
Example 16
Source File: BugTests.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
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 17
Source File: TranslatorTest.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
public final void testFlattening() {
    final List<String> atoms = new ArrayList<String>(9);
    atoms.add("-1");
    atoms.add("0");
    atoms.add("1");
    atoms.add("null");
    for (int i = 0; i < 5; i++) {
        atoms.add("m" + i);
    }
    final Universe u = new Universe(atoms);
    final TupleFactory t = u.factory();

    final Relation[] m = new Relation[5];
    for (int i = 0; i < 5; i++) {
        m[i] = Relation.unary("m" + i);
    }

    final Relation univ = Relation.unary("univ"), none = Relation.unary("none"), iden = Relation.binary("inden"),
                    mutant = Relation.unary("mutant"), inc = Relation.binary("inc"), add = Relation.ternary("add"),
                    i0 = Relation.unary("i0"), zero = Relation.unary("0"), one = Relation.unary("1"),
                    ints = Relation.unary("int");

    final Bounds b = new Bounds(u);

    b.boundExactly(univ, t.allOf(1));
    b.boundExactly(none, t.noneOf(1));
    TupleSet idenSet = t.noneOf(2);
    for (String atom : atoms) {
        idenSet.add(t.tuple(atom, atom));
    }
    b.boundExactly(iden, idenSet);

    b.bound(mutant, t.range(t.tuple("m0"), t.tuple("m4")));
    for (int i = 0; i < 5; i++) {
        b.boundExactly(m[i], t.setOf("m" + i));
    }

    b.bound(i0, t.range(t.tuple("-1"), t.tuple("1")));
    b.boundExactly(zero, t.setOf(t.tuple("0")));
    b.boundExactly(one, t.setOf(t.tuple("1")));
    b.boundExactly(ints, t.allOf(1));
    b.boundExactly(inc, t.setOf(t.tuple("-1", "0"), t.tuple("0", "1")));

    // [1, 1, -1], [1, -1, 0], [1, 0, 1], [-1, 1, 0], [-1, -1, 1],
    // [-1, 0, -1], [0, 1, 1], [0, -1, -1], [0, 0, 0]]
    b.boundExactly(add, t.setOf(t.tuple("1", "1", "-1"), t.tuple("1", "-1", "0"), t.tuple("1", "0", "1"), t.tuple("-1", "1", "0"), t.tuple("-1", "-1", "1"), t.tuple("-1", "0", "-1"), t.tuple("0", "1", "1"), t.tuple("0", "-1", "-1"), t.tuple("0", "0", "0")));

    /*
     * ((one i0 && one mutant) && !((if (i0 in (0 . ^~inc)) then ((add . 0) . i0)
     * else i0) = (if !((if (mutant in m4) then (if (i0 in 0) then 1 else 0) else
     * (if (mutant in m3) then (if ((i0 = 0) || (i0 in (0 . ^~inc))) then 1 else 0)
     * else (if (mutant in m2) then (if (i0 in (0 . ^inc)) then 1 else 0) else (if
     * (mutant in m1) then (if ((i0 = 0) || (i0 in (0 . ^inc))) then 1 else 0) else
     * (if (mutant in m0) then (if !(i0 in 0) then 1 else 0) else (if (i0 in (0 .
     * ^~inc)) then 1 else 0)))))) in 0) then ((add . 0) . i0) else i0)))
     */

    final Formula[] cm = new Formula[5];
    for (int i = 0; i < 5; i++) {
        cm[i] = mutant.in(m[i]);
    }

    // (i0 in (0 . ^~inc))
    final Formula fs0 = i0.in(zero.join(inc.transpose().closure()));
    // (i0 in (0 . ^inc))
    final Formula fs1 = i0.in(zero.join(inc.closure()));
    // (i0 = 0)
    final Formula fs2 = i0.eq(zero);

    final Expression em0 = cm[0].thenElse(i0.in(zero).not().thenElse(one, zero), fs0.thenElse(one, zero));
    final Expression em1 = cm[1].thenElse((fs2.or(fs1)).thenElse(one, zero), em0);
    final Expression em2 = cm[2].thenElse(fs1.thenElse(one, zero), em1);
    final Expression em3 = cm[3].thenElse(fs2.or(fs0).thenElse(one, zero), em2);
    final Expression em4 = cm[4].thenElse(i0.in(zero).thenElse(one, zero), em3);

    final Expression es1 = add.join(zero).join(i0);
    final Expression expr2 = em4.in(zero).not().thenElse(es1, i0);
    final Expression expr1 = fs0.thenElse(es1, i0);

    final Formula f = i0.one().and(mutant.one()).and(expr1.eq(expr2).not());

    final Instance instance = solver.solve(f, b).instance();
    assertNotNull(instance);

    // System.out.println(instance);

}
 
Example 18
Source File: RegressionTests.java    From kodkod with MIT License 4 votes vote down vote up
@Test
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().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 19
Source File: RegressionTests.java    From kodkod with MIT License 4 votes vote down vote up
@Test
public final void testFelix_03162009() {
	Relation x = Relation.unary("X");
	Relation y = Relation.unary("Y");
	Relation q = Relation.unary("Q");
	Relation f = Relation.nary("f", 2);

	List<String> atomlist = Arrays.asList("X", "Y");

	Universe universe = new Universe(atomlist);
	TupleFactory factory = universe.factory();
	Bounds bounds = new Bounds(universe);

	TupleSet x_upper = factory.noneOf(1);
	x_upper.add(factory.tuple("X"));
	bounds.boundExactly(x, x_upper);

	TupleSet y_upper = factory.noneOf(1);
	y_upper.add(factory.tuple("Y"));
	bounds.boundExactly(y, y_upper);

	TupleSet q_upper = factory.noneOf(1);
	q_upper.add(factory.tuple("X"));
	q_upper.add(factory.tuple("Y"));
	bounds.bound(q, q_upper);

	TupleSet f_upper = factory.noneOf(2);
	f_upper.add(factory.tuple("X").product(factory.tuple("X")));
	f_upper.add(factory.tuple("X").product(factory.tuple("Y")));
	f_upper.add(factory.tuple("Y").product(factory.tuple("X")));
	f_upper.add(factory.tuple("Y").product(factory.tuple("Y")));
	bounds.bound(f, f_upper);

	Solver solver = new Solver();
	solver.options().setSolver(SATFactory.DefaultSAT4J);
	solver.options().setBitwidth(4);
	solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT);
	solver.options().setSymmetryBreaking(20);
	solver.options().setSkolemDepth(0);

	Expression test = f.override(q.product(y));
	TupleSet approx = factory.setOf(test.arity(), Translator.approximate(test, bounds, solver.options()).denseIndices());
	assertEquals(f_upper, approx);
}
 
Example 20
Source File: RegressionTests.java    From kodkod with MIT License 3 votes vote down vote up
@Test
public final void testFelix_05152007_1() {
	Relation x5 = Relation.nary("A", 1);

	List<String> atomlist = Arrays.asList("A0", "A1", "A2");

	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("A2"));
	x5_upper.add(factory.tuple("A1"));
	x5_upper.add(factory.tuple("A0"));

	bounds.bound(x5, x5_upper);

	Formula x7=x5.some();
	Formula x8=x5.no();

	Formula x6=x7.and(x8);

	Solver solver = new Solver();
	solver.options().setLogTranslation(1);

	solver.options().setSolver(SATFactory.MiniSatProver);
	solver.options().setBitwidth(4);
	solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT);

	Solution sol = solver.solve(x6,bounds);

	//		System.out.println("Sol="+sol);

	Set<Formula> core = Nodes.minRoots(x6, sol.proof().highLevelCore().values());
	assertEquals(2, core.size());
	assertTrue(core.contains(x7));
	assertTrue(core.contains(x8));

}