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

The following examples show how to use kodkod.instance.Bounds#intBounds() . 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: 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 2
Source File: LeafInterpreter.java    From org.alloytools.alloy with Apache License 2.0 3 votes vote down vote up
/**
 * Returns an exact interpreter for the given bounds and options. If
 * {@code incremental} is <code>true</code>, then the resulting interpreter can
 * be {@linkplain #extend(Set, Map, Map) extended} with new bindings. Otherwise,
 * the interpreter will throw an exception if extension is attempted.
 *
 * @return some l: LeafInterpreter | l.universe = bounds.universe && l.relations
 *         = bounds.relations() && l.ints = bounds.ints() && l.lbounds =
 *         bounds.lowerBound && l.ubounds = bounds.upperBound && l.ibounds =
 *         bounds.intBound && l.factory = BooleanFactory.factory(sum(r:
 *         l.relations | #(l.ubounds[r]-l.lbounds[r]))-1, options) &&
 *         l.vars[relations] = l.factory & BooleanVariable
 */
static final LeafInterpreter exact(Bounds bounds, Options options, boolean incremental) {
    final Map<Relation,IntRange> vars = new LinkedHashMap<Relation,IntRange>();
    final Map<Relation,TupleSet> lowers = incremental ? new LinkedHashMap<Relation,TupleSet>(bounds.lowerBounds()) : bounds.lowerBounds();
    final Map<Relation,TupleSet> uppers = incremental ? new LinkedHashMap<Relation,TupleSet>(bounds.upperBounds()) : bounds.upperBounds();
    final int numVars = allocateVars(1, vars, bounds.relations(), lowers, uppers);
    return new LeafInterpreter(bounds.universe(), lowers, uppers, bounds.intBounds(), BooleanFactory.factory(numVars, options), vars);
}
 
Example 3
Source File: LeafInterpreter.java    From kodkod with MIT License 3 votes vote down vote up
/**  
 * Returns an exact interpreter for the given bounds and options. If {@code incremental}  is <code>true</code>, 
 * then the resulting interpreter can be {@linkplain #extend(Set, Map, Map) extended} with new bindings.  
 * Otherwise, the interpreter will throw an exception if extension is attempted.
 * @return some l: LeafInterpreter | l.universe = bounds.universe && l.relations = bounds.relations() && 
 *          l.ints = bounds.ints() && l.lbounds = bounds.lowerBound && l.ubounds = bounds.upperBound && 
 *          l.ibounds = bounds.intBound && 
 *          l.factory = BooleanFactory.factory(sum(r: l.relations | #(l.ubounds[r]-l.lbounds[r]))-1, options) &&
 *          l.vars[relations] = l.factory & BooleanVariable
 */
static final LeafInterpreter exact(Bounds bounds, Options options, boolean incremental) {
	final Map<Relation, IntRange> vars = new LinkedHashMap<Relation,IntRange>();
	final Map<Relation, TupleSet> lowers = incremental ? new LinkedHashMap<Relation, TupleSet>(bounds.lowerBounds()) : bounds.lowerBounds();
	final Map<Relation, TupleSet> uppers = incremental ? new LinkedHashMap<Relation, TupleSet>(bounds.upperBounds()) : bounds.upperBounds();
	final int numVars = allocateVars(1, vars, bounds.relations(), lowers, uppers);
	return new LeafInterpreter(bounds.universe(), lowers, uppers, bounds.intBounds(), BooleanFactory.factory(numVars, options), vars);
}
 
Example 4
Source File: LeafInterpreter.java    From org.alloytools.alloy with Apache License 2.0 2 votes vote down vote up
/**
 * Returns an overapproximating interpreter for the given bounds and options.
 *
 * @return some l: LeafInterpreter | l.universe = bounds.universe && l.relations
 *         = bounds.relations() && l.ints = bounds.ints() && l.lbounds =
 *         l.ubounds = bounds.upperBound && l.ibounds = bounds.intBound &&
 *         l.factory = BooleanFactory.constantFactory(options) && no l.vars
 */
static final LeafInterpreter overapproximating(Bounds bounds, Options options) {
    return new LeafInterpreter(bounds.universe(), bounds.upperBounds(), bounds.intBounds(), options);
}
 
Example 5
Source File: LeafInterpreter.java    From kodkod with MIT License 2 votes vote down vote up
/**
 * Returns an overapproximating interpreter for the given bounds and options.
 * @return some l: LeafInterpreter | l.universe = bounds.universe && l.relations = bounds.relations() && 
 *           l.ints = bounds.ints() && l.lbounds = l.ubounds = bounds.upperBound && 
 *           l.ibounds = bounds.intBound && l.factory = BooleanFactory.constantFactory(options) && no l.vars 
 */
static final LeafInterpreter overapproximating(Bounds bounds, Options options) {
	return new LeafInterpreter(bounds.universe(), bounds.upperBounds(), bounds.intBounds(), options);
}