Java Code Examples for kodkod.instance.Bounds#boundExactly()

The following examples show how to use kodkod.instance.Bounds#boundExactly() . 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: IncrementalOverflowNumTest.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
@Test
public void testBasic() {
    Options opt = new Options();
    opt.setNoOverflow(true);
    opt.setBitwidth(2);
    IncrementalSolver solver = IncrementalSolver.solver(opt);
    Universe univ = new Universe("-2", "-1", "0", "1");
    Bounds b = new Bounds(univ);
    TupleFactory factory = univ.factory();
    b.boundExactly(-2, factory.range(factory.tuple("-2"), factory.tuple("-2")));
    b.boundExactly(-1, factory.range(factory.tuple("-1"), factory.tuple("-1")));
    b.boundExactly(0, factory.range(factory.tuple("0"), factory.tuple("0")));
    b.boundExactly(1, factory.range(factory.tuple("1"), factory.tuple("1")));
    Variable n = Variable.unary("n");
    Formula f = n.sum().plus(IntConstant.constant(1)).lte(n.sum()).forSome(n.oneOf(Expression.INTS));
    Solution sol = solver.solve(f, b);
    assertNoInstance(sol);
}
 
Example 2
Source File: BugTests.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
public final void testGreg_02192006() {
    Relation r1 = Relation.unary("r1");
    Relation r2 = Relation.unary("r2");
    Relation r3 = Relation.unary("r3");
    Expression e = r1.in(r2).thenElse(r2, r1);
    Formula f = e.eq(r2).and(e.in(r3));
    Object o1 = "o1";
    Object o2 = "o2";
    Universe univ = new Universe(Arrays.asList(o1, o2));
    TupleFactory factory = univ.factory();
    TupleSet set1 = factory.setOf(o1);
    TupleSet set2 = factory.setOf(o2);
    Bounds bounds = new Bounds(univ);
    bounds.bound(r1, set1);
    bounds.boundExactly(r2, set2);
    bounds.bound(r3, set1);

    assertEquals(Solution.Outcome.TRIVIALLY_UNSATISFIABLE, solver.solve(f, bounds).outcome());

}
 
Example 3
Source File: Viktor.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the bounds for the problem.
 *
 * @return bounds
 */
public final Bounds bounds() {
    List<String> atoms = new ArrayList<String>(cols + 1);
    for (int i = 0; i < cols; i++) {
        atoms.add(String.valueOf(i));
    }
    atoms.add("a");
    final Universe u = new Universe(atoms);
    final TupleFactory f = u.factory();
    final Bounds b = new Bounds(u);

    final TupleSet abound = f.setOf("a");
    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < cols; j++) {
            b.bound(a[i][j], abound);
        }
    }
    final TupleSet xbound = f.range(f.tuple(String.valueOf(0)), f.tuple(String.valueOf(cols - 1)));
    for (int j = 0; j < cols; j++) {
        b.bound(x[j], xbound);
        b.boundExactly(j, f.setOf(String.valueOf(j)));
    }

    return b;
}
 
Example 4
Source File: FloatTestBase.java    From quetzal with Eclipse Public License 2.0 6 votes vote down vote up
private Instance instance(Formula f, Set<Relation> vars) {
	int msb = bitWidth - 1;

	Universe u = new Universe(atoms);
	TupleFactory tf = u.factory();
	Bounds b = new Bounds(u);

	for(int i = 0; i < msb; i++) {
		Integer v = Integer.valueOf(1<<i);
		b.boundExactly(v.intValue(), tf.setOf(v));
	}
	b.boundExactly(-(1<<msb), tf.setOf(Integer.valueOf(-(1<<msb))));

	Set<Tuple> digits = HashSetFactory.make();
	for(Object o : atoms) {
		digits.add(tf.tuple(o));
	}
	for(Relation r : vars) {
		b.bound(r, tf.setOf(digits));
	}
	
	Solver solver = new Solver(options);
	
	return solver.solve(f, b).instance();
}
 
Example 5
Source File: Handshake.java    From kodkod with MIT License 6 votes vote down vote up
/**
 * Returns a bounds for the given number of persons.
 * @return a bounds for the given number of persons.
 */
public Bounds bounds(int persons) {
	final List<String> atoms = new ArrayList<String>(persons);
	atoms.add("Hilary"); 
	atoms.add("Jocelyn");
	for(int i = 2; i < persons; i ++) {
		atoms.add("Person" + i);
	}
	final Universe u = new Universe(atoms);
	final TupleFactory f = u.factory();
	final Bounds b = new Bounds(u);
	b.boundExactly(Person, f.allOf(1));
	b.boundExactly(Hilary, f.setOf("Hilary"));
	b.boundExactly(Jocelyn, f.setOf("Jocelyn"));
	b.bound(spouse, f.allOf(2));
	b.bound(shaken, f.allOf(2));
	return b;
}
 
Example 6
Source File: Transpose4x4UnaryLR.java    From kodkod with MIT License 5 votes vote down vote up
/**
 * Returns relation bounds over a universe of interpretation consisting of integers 0 - 16, inclusive.
 * @return relation bounds over a universe of interpretation consisting of integers 0 - 16, 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, 16);
	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(sl[i], s12);
		b.bound(mx1[i], s12);
		b.bound(mx2[i], s12);	
		b.bound(tl[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);
		}
	}
	
	b.boundExactly(idx, f.setOf(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15));
	final TupleSet ord = f.noneOf(2);  				// { [0, 1], [1, 2], [2, 3], ..., [14, 15], [15, 16] }
	for(int i = 0; i < 16; i++)
		ord.add(f.tuple((Object)i, i+1));
	b.boundExactly(succ, ord);
	
	return b;
}
 
Example 7
Source File: BugTests.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
public final void testGreg_11232005() {
    final List<String> atoms = new ArrayList<String>(3);
    atoms.add("-1");
    atoms.add("0");
    atoms.add("1");
    final Universe u = new Universe(atoms);
    final TupleFactory t = u.factory();

    final Relation inc = Relation.binary("inc"), add = Relation.ternary("add"), one = Relation.unary("1"),
                    param0 = Relation.unary("param0"), ints = Relation.unary("int");

    // (one param0 && ((1 . (param0 . add)) in (param0 . ^inc)))
    final Formula f = param0.one().and((one.join(param0.join(add))).in(param0.join(inc.closure())));

    final Bounds b = new Bounds(u);

    b.bound(param0, t.allOf(1));
    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")));

    // System.out.println(f);
    // System.out.println(b);

    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 8
Source File: BasicUniverse.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
protected void boundExactly(Set<Relation> liveRelations, Set<Object> liveAtoms, Bounds b, Relation r, LazyTupleSet bound) throws URISyntaxException {
	if (liveRelations == null || liveRelations.contains(r)) {
		TupleSet ts = bound.tuples();
		b.boundExactly(r, ts);
		collectAtoms(liveAtoms, ts);
	}
}
 
Example 9
Source File: HOLSome4AllTest.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
private void createBounds() {
    universe = getUniverse();
    factory = universe.factory();
    bounds = new Bounds(universe);
    bounds.bound(Node, factory.setOf("Node1", "Node2", "Node3"));
    bounds.boundExactly(-1, factory.setOf(-1));
    bounds.boundExactly(0, factory.setOf(0));
    bounds.boundExactly(1, factory.setOf(1));
    bounds.boundExactly(2, factory.setOf(2));
    bounds.boundExactly(3, factory.setOf(3));
    bounds.bound(S, factory.noneOf(1), factory.setOf(-1, 0, 1, 2, 3));
}
 
Example 10
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;
	}
 
Example 11
Source File: ExamplesTestWithIncrementalSolver.java    From kodkod with MIT License 5 votes vote down vote up
protected Solution solve(Formula formula, Bounds bounds) {
	final Set<IntSet> parts = SymmetryDetector.partition(bounds);
	final Bounds inc = new Bounds(bounds.universe());
	final TupleFactory t = inc.universe().factory();
	for(IndexedEntry<TupleSet> e : inc.intBounds()) {
		inc.boundExactly(e.index(), e.value());
	}
	for(IntSet part : parts) {
		// dummy relations to set up initial symmetry classes
		inc.boundExactly(Relation.unary("r" + part.min()), t.setOf(1, part)); 
	}
	
	
	Solution sol = solver.solve(Formula.TRUE, inc);
	assertEquals(Solution.Outcome.TRIVIALLY_SATISFIABLE, sol.outcome());
	//System.out.println("FORMULAS: " + Nodes.roots(formula).size());
	for(Formula f : Nodes.roots(formula)) {
		inc.relations().clear();
		if (!bounds.relations().isEmpty()) {
			final Set<Relation> rels = AnnotatedNode.annotate(f).relations();
			rels.retainAll(bounds.relations());
			for(Relation r : rels) { 
				inc.bound(r, bounds.lowerBound(r), bounds.upperBound(r));
			}
			bounds.relations().removeAll(rels);
		}
		//System.out.println(f + ", " + inc.relations() + "\n");
		sol = solver.solve(f, inc);
		if (sol.unsat()) {
			break;
		}
	}
	return sol;
}
 
Example 12
Source File: RegressionTests.java    From kodkod with MIT License 5 votes vote down vote up
@Test
	public final void testMarceloSimplified_041912() {
		
		final Relation d2 = Relation.unary("Domain_2");
		final Relation a1 = Relation.unary("Address_1");
		final Relation a2 = Relation.unary("Address_2");
		final Relation a3 = Relation.unary("Address_3");
		
		final Expression e = Expression.union(a1, a2, a3);
		
		final Expression dstBinding = 
			Expression.union(Expression.product(d2, a1, a3), Expression.product(d2, a3, a3));
		final Formula f = a3.in(e.product(a1).override(d2.join(dstBinding)).join(e));
		
		final Universe u = new Universe("a1", "a2", "a3", "d2");
		final TupleFactory tf = u.factory();
		final Bounds b = new Bounds(u);
		b.boundExactly(a1, tf.setOf("a1"));
		b.boundExactly(a2, tf.setOf("a2"));
		b.boundExactly(a3, tf.setOf("a3"));
		b.bound(d2, tf.setOf("d2"));
		
		final Solver solver = new Solver();
		solver.options().setSolver(SATFactory.MiniSat);
		
//		System.out.println(f);
//		System.out.println(b);
		
		final Solution sol = solver.solve(f, b);

//		System.out.println(sol);
		assertNotNull(sol.instance());
	}
 
Example 13
Source File: RegressionTests.java    From kodkod with MIT License 5 votes vote down vote up
@Test
public final void testFelix_05072008() { 
	Relation A=Relation.unary("A"), first=Relation.unary("OrdFirst"), last=Relation.unary("OrdLast"), next=Relation.nary("OrdNext", 2);

	List<String> atomlist = Arrays.asList("A1", "A2", "A3");
	Universe universe = new Universe(atomlist);
	TupleFactory factory = universe.factory();
	Bounds bounds = new Bounds(universe);

	TupleSet all = factory.setOf("A1","A2","A3");
	bounds.boundExactly(A, all);
	bounds.bound(first, all);
	bounds.bound(last, all);
	bounds.bound(next, all.product(all));

	Formula form = next.totalOrder(A,first,last);

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

	Iterator<Solution> sol = solver.solveAll(form, bounds);
	assertTrue(sol.hasNext());
	assertEquals(sol.next().outcome(), Solution.Outcome.TRIVIALLY_SATISFIABLE);
	assertTrue(sol.hasNext());
	assertEquals(sol.next().outcome(), Solution.Outcome.TRIVIALLY_UNSATISFIABLE);
	assertFalse(sol.hasNext());

	//		int i=1;
	//		
	//		while (sol.hasNext()) {
	//			System.out.println("================================== "+i+" ===================================");
	//		  System.out.println(sol.next());
	//		  System.out.flush();
	//		  i++;
	//		}
}
 
Example 14
Source File: Bigconfig.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * 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 15
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 16
Source File: BugTests.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
public final void testMana_01132006() {
    // r0=[[], [[null], [DblLinkedList0]]],
    // null=[[[null]], [[null]]],
    // head=[[], [[DblLinkedList0, null], [DblLinkedList0,
    // DblLinkedListElem0]]],
    // next=[[], [[DblLinkedListElem0, null], [DblLinkedListElem0,
    // DblLinkedListElem0]]],
    // univ=[[[null], [DblLinkedList0], [1], [DblLinkedListElem0], [0]],
    // [[null], [DblLinkedList0], [1], [DblLinkedListElem0], [0]]]
    // r1=[[], [[null], [DblLinkedListElem0]]],
    final List<String> atoms = new ArrayList<String>(5);
    atoms.add("null");
    atoms.add("DblLinkedList0");
    atoms.add("1");
    atoms.add("DblLinkedListElem0");
    atoms.add("0");
    final Universe u = new Universe(atoms);
    final TupleFactory t = u.factory();

    // !((head . univ) in ((if (r1 in null) then (head ++ (r0 -> (r1 .
    // next))) else head) . univ))

    final Relation head = Relation.binary("head"), univ = Relation.unary("univ"), r0 = Relation.unary("r0"),
                    r1 = Relation.unary("r1"), next = Relation.binary("next"), nil = Relation.unary("null"),
                    none = Relation.unary("none");

    final Expression override = head.override(r0.product(r1.join(next)));
    final Expression ifElse = r1.in(nil).thenElse(override, head);
    final Formula f = head.join(univ).in(ifElse.join(univ)).not();

    final Bounds b = new Bounds(u);
    b.bound(r0, t.setOf("null", "DblLinkedList0"));
    b.bound(r1, t.setOf("null", "DblLinkedListElem0"));
    b.bound(head, t.setOf("DblLinkedList0").product(b.upperBound(r1)));

    b.bound(next, t.setOf(t.tuple("DblLinkedListElem0", "null"), t.tuple("DblLinkedListElem0", "DblLinkedListElem0")));
    b.boundExactly(univ, t.allOf(1));
    b.boundExactly(nil, t.setOf("null"));
    b.boundExactly(none, t.noneOf(1));

    // System.out.println(f);
    // System.out.println(b);

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

}
 
Example 17
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 18
Source File: BugTests.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
public final void testFelix_05072008() {
    Relation A = Relation.unary("A"), first = Relation.unary("OrdFirst"), last = Relation.unary("OrdLast"),
                    next = Relation.nary("OrdNext", 2);

    List<String> atomlist = Arrays.asList("A1", "A2", "A3");
    Universe universe = new Universe(atomlist);
    TupleFactory factory = universe.factory();
    Bounds bounds = new Bounds(universe);

    TupleSet all = factory.setOf("A1", "A2", "A3");
    bounds.boundExactly(A, all);
    bounds.bound(first, all);
    bounds.bound(last, all);
    bounds.bound(next, all.product(all));

    Formula form = next.totalOrder(A, first, last);

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

    Iterator<Solution> sol = solver.solveAll(form, bounds);
    assertTrue(sol.hasNext());
    assertEquals(sol.next().outcome(), Solution.Outcome.TRIVIALLY_SATISFIABLE);
    assertTrue(sol.hasNext());
    assertEquals(sol.next().outcome(), Solution.Outcome.TRIVIALLY_UNSATISFIABLE);
    assertFalse(sol.hasNext());

    // int i=1;
    //
    // while (sol.hasNext()) {
    // System.out.println("================================== "+i+"
    // ===================================");
    // System.out.println(sol.next());
    // System.out.flush();
    // i++;
    // }
}
 
Example 19
Source File: BugTests.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
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());
}
 
Example 20
Source File: BugTests.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
public final void testVincent_03182006() {
    final Relation cAttributes = Relation.binary("cAttributes"), Int = Relation.unary("Integer"),
                    c6001 = Relation.unary("6.001"), one = Relation.unary("ONE"),
                    prereqsetUsed = Relation.binary("prereqsetUsed"), Course = Relation.unary("Course"),
                    CardinalityGrouping = Relation.unary("CardinalityGrouping"), pCourses = Relation.binary("pCourses"),
                    dec = Relation.binary("dec"), c6002 = Relation.unary("6.002"), greater = Relation.binary("greater"),
                    size = Relation.binary("size"), less = Relation.binary("less"),
                    sAttributes = Relation.binary("sAttributes"), PrereqSet = Relation.unary("PrereqSet"),
                    inc = Relation.binary("inc"), next = Relation.binary("next"), equal = Relation.binary("equal"),
                    Semester = Relation.unary("Semester"), index = Relation.ternary("index"),
                    sCourses = Relation.binary("sCourses"), prev = Relation.binary("prev"),
                    prereqs = Relation.binary("prereqs");
    // [6.002, 8.02, 6.003, 6.001, Spring 2006, Fall 2006, [8.02], [6.001],
    // [], Spring, Even, Fall, 1, 2]
    final List<String> atoms = new ArrayList<String>(14);
    atoms.add("6.002");
    atoms.add("8.02");
    atoms.add("6.003");
    atoms.add("6.001");
    atoms.add("Spring 2006");
    atoms.add("Fall 2006");
    atoms.add("[8.02]");
    atoms.add("[6.001]");
    atoms.add("[]");
    atoms.add("Spring");
    atoms.add("Even");
    atoms.add("Fall");
    atoms.add("1");
    atoms.add("2");
    final Universe u = new Universe(atoms);
    final Bounds b = new Bounds(u);
    final TupleFactory f = u.factory();

    b.bound(cAttributes, f.noneOf(2));
    b.boundExactly(Int, f.range(f.tuple("1"), f.tuple("2")));
    b.boundExactly(c6001, f.setOf(f.tuple("6.001")));
    b.boundExactly(one, f.setOf(f.tuple("1")));
    b.bound(prereqsetUsed, f.setOf(f.tuple("6.002", "[8.02]"), f.tuple("8.02", "[]"), f.tuple("6.003", "[6.001]"), f.tuple("6.001", "[]")));
    b.bound(Course, f.range(f.tuple("6.002"), f.tuple("6.001")));
    b.bound(CardinalityGrouping, f.noneOf(1));
    b.boundExactly(pCourses, f.setOf(f.tuple("[8.02]", "8.02"), f.tuple("[6.001]", "6.001")));
    b.boundExactly(dec, f.setOf(f.tuple("2", "1")));
    b.boundExactly(greater, b.upperBound(dec));
    b.bound(size, f.noneOf(2));
    b.boundExactly(c6002, f.setOf(f.tuple("6.002")));
    b.boundExactly(less, f.setOf(f.tuple("1", "2")));
    b.boundExactly(sAttributes, f.setOf(f.tuple("Spring 2006", "Spring"), f.tuple("Spring 2006", "Even"), f.tuple("Fall 2006", "Even"), f.tuple("Fall 2006", "Fall")));
    b.boundExactly(PrereqSet, f.setOf("[8.02]", "[6.001]", "[]"));
    b.boundExactly(inc, b.upperBound(less));
    b.boundExactly(next, f.setOf(f.tuple("Spring 2006", "Fall 2006")));
    b.boundExactly(equal, f.setOf(f.tuple("1", "1"), f.tuple("2", "2")));
    b.boundExactly(Semester, f.setOf("Spring 2006", "Fall 2006"));
    b.bound(index, f.noneOf(3));
    b.bound(sCourses, f.range(f.tuple("Spring 2006"), f.tuple("Fall 2006")).product(f.range(f.tuple("6.002"), f.tuple("6.001"))));
    b.boundExactly(prev, f.setOf(f.tuple("Fall 2006", "Spring 2006")));
    b.boundExactly(prereqs, f.setOf(f.tuple("6.002", "[8.02]"), f.tuple("8.02", "[]"), f.tuple("6.003", "[6.001]"), f.tuple("6.001", "[]")));
    // for(Relation r : b.relations()) {
    // System.out.println(r + " " + r.arity() + " " + b.lowerBound(r) + " ;
    // " + b.upperBound(r));
    // }
    // System.out.println(u);

    final Formula f0 = sCourses.in(Semester.product(Course));
    final Formula f1 = size.function(CardinalityGrouping, Int);
    final Formula f2 = prereqsetUsed.function(Semester.join(sCourses), PrereqSet);
    final Formula f3 = prereqsetUsed.in(prereqs);
    final Variable s = Variable.unary("s");
    final Expression e0 = s.join(sCourses).join(prereqsetUsed).join(pCourses);
    final Expression e1 = s.join(prev.closure()).join(sCourses);
    final Formula f4 = e0.in(e1).forAll(s.oneOf(Semester));
    final Formula f5 = c6002.in(Semester.join(sCourses));
    final Variable e = Variable.unary("e");
    final Expression e3 = Semester.join(sCourses).difference(e);
    final Formula f60 = c6002.in(e3);
    final Formula f61 = e3.join(prereqsetUsed).join(pCourses).in(e3);
    final Formula f6 = (f60.and(f61)).not().forAll(e.oneOf(Semester.join(sCourses)));
    final Variable c = Variable.unary("c");
    final Formula f7 = c.join(cAttributes).in(s.join(sAttributes)).forAll(c.oneOf(s.join(sCourses))).forAll(s.oneOf(Semester));
    final Variable s1 = Variable.unary("s1"), s2 = Variable.unary("s2");
    final Formula f8 = s1.join(sCourses).intersection(s2.join(sCourses)).no().forAll(s2.oneOf(Semester.difference(s1))).forAll(s1.oneOf(Semester));
    final Formula f9 = c6001.intersection(Semester.join(sCourses)).no();

    final Formula x = f0.and(f1).and(f2).and(f3).and(f4).and(f5).and(f6).and(f7).and(f8);
    final Formula y = x.and(f9);

    // System.out.println(x);
    // System.out.println(y);

    solver.options().setSolver(SATFactory.DefaultSAT4J);
    Solution solution = solver.solve(x, b);
    // System.out.println(solution); // SATISFIABLE
    assertEquals(solution.outcome(), Solution.Outcome.SATISFIABLE);

    Solution solution2 = solver.solve(y, b);
    // System.out.println(solution2); // SATISFIABLE!!!???
    // System.out.println((new
    // Evaluator(solution2.instance())).evaluate(x));
    assertEquals(solution2.outcome(), Solution.Outcome.SATISFIABLE);

}