use of kodkod.instance.TupleSet in project org.alloytools.alloy by AlloyTools.
the class OverflowSigTest method createBounds.
protected void createBounds() {
Collection<String> atoms = new ArrayList<String>(sAtoms.size() + xAtoms.size());
atoms.addAll(sAtoms);
atoms.addAll(xAtoms);
final Universe universe = new Universe(atoms);
this.factory = universe.factory();
this.bounds = new Bounds(universe);
TupleSet sTs = factory.setOf(sAtoms.toArray());
TupleSet xTs = factory.setOf(xAtoms.toArray());
bounds.bound(s, sTs);
bounds.bound(x, xTs);
bounds.bound(sa, sTs.product(xTs));
bounds.bound(sb, sTs.product(xTs));
bounds.bound(sc, sTs.product(xTs));
}
use of kodkod.instance.TupleSet in project org.alloytools.alloy by AlloyTools.
the class SymmetryBreakingTest method testAcyclic.
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());
}
use of kodkod.instance.TupleSet in project org.alloytools.alloy by AlloyTools.
the class BenchmarkSymmStats method toNauty.
private static void toNauty(Bounds bounds, PrintStream stream) {
int size = bounds.universe().size() + bounds.ints().size();
for (Relation r : bounds.relations()) {
final int upsize = bounds.upperBound(r).size(), lowsize = bounds.lowerBound(r).size();
size += (upsize == lowsize ? upsize : upsize + lowsize) * r.arity();
}
stream.println("n=" + size + " $0 *=13 k = 0 " + size + " +d -a -m g");
int v = bounds.universe().size();
final IntVector vec = new ArrayIntVector();
vec.add(v);
for (Relation r : bounds.relations()) {
final int arity = r.arity();
final TupleSet up = bounds.upperBound(r), down = bounds.lowerBound(r);
final TupleSet[] sets = up.size() == down.size() || down.size() == 0 ? new TupleSet[] { up } : new TupleSet[] { down, up };
for (TupleSet s : sets) {
for (Tuple t : s) {
for (int i = 0, max = arity - 1; i < max; i++) {
stream.println(v + " : " + (v + 1) + " " + t.atomIndex(i) + ";");
v++;
}
stream.println(v + " : " + t.atomIndex(arity - 1) + ";");
v++;
}
vec.add(v);
}
}
for (TupleSet s : bounds.intBounds().values()) {
stream.println(v + " : " + s.iterator().next().atomIndex(0) + ";");
v++;
vec.add(v);
}
// stream.println(".");
stream.print("f = [ 0:" + (vec.get(0) - 1));
for (int i = 1; i < vec.size(); i++) {
stream.print(" | " + vec.get(i - 1) + ":" + (vec.get(i) - 1));
}
stream.println(" ]");
stream.println("x");
// stream.println("o");
stream.println("q");
}
use of kodkod.instance.TupleSet in project org.alloytools.alloy by AlloyTools.
the class Translation method interpret.
public Instance interpret(Bounds bounds) {
final SATSolver solver = cnf();
final Instance instance = new Instance(bounds.universe());
final TupleFactory f = bounds.universe().factory();
for (IndexedEntry<TupleSet> entry : bounds.intBounds()) {
instance.add(entry.index(), entry.value());
}
for (Relation r : bounds.relations()) {
// if (bnds != bounds && bnds.findRelByName(r.name()) == null)
// continue;
TupleSet lower = bounds.lowerBound(r);
IntSet indices = Ints.bestSet(lower.capacity());
indices.addAll(lower.indexView());
IntSet vars = primaryVariables(r);
if (!vars.isEmpty()) {
// System.out.println(r + ": [" + vars.min() + ", " + vars.max()
// + "]");
int lit = vars.min();
for (IntIterator iter = bounds.upperBound(r).indexView().iterator(); iter.hasNext(); ) {
final int index = iter.next();
if (!indices.contains(index) && solver.valueOf(lit++))
indices.add(index);
}
}
instance.add(r, f.setOf(r.arity(), indices));
}
return instance;
}
use of kodkod.instance.TupleSet in project org.alloytools.alloy by AlloyTools.
the class Translator method completeBounds.
/**
* Completes {@code this.bounds} using the bindings from
* {@code this.originalBounds} so that the result satisfies the
* {@linkplain Translation} invariants. This involves updating
* {@code this.bounds} with bindings from {@code this.originalBounds}, if any,
* that had been discarded in the {@link #translate() first step} of the
* translation. The first step of a non-incremental translation is to discard
* bounds for relations that are not constrained by
* {@code this.originalFormula}, and to discard all integer bounds if
* {@code this.originalFormula} contains no integer expressions. This is sound
* since any instance of {@code this.originalFormula} with respect to
* {@code this.originalBounds} only needs to satisfy the lower bound constraint
* on each discarded relation/integer. By updating {@code this.bounds} with the
* bindings for discarded relations/integers for which no variables were
* allocated, we ensure that any instance returned by
* {@linkplain Translation#interpret()} will bind those relations/integers to
* their lower bound, therefore satisfying the original problem
* {@code (this.originalFormula, this.originalBounds, this.options)}.
*
* @requires no this.bounds.intBound or this.bounds.intBound =
* this.originalBounds.intBound
* @ensures this.bounds.relations' = this.bounds.relations +
* this.originalBounds.relations && this.bounds.intBound' =
* this.originalBounds.intBound && this.bounds.lowerBound' =
* this.bounds.lowerBound + (this.originalBounds.relations -
* this.bounds.relations)<:(this.originalBounds.lowerBound) &&
* this.bounds.upperBound' = bounds.upperBound +
* (this.originalBounds.relations -
* this.bounds.relations)<:(this.originalBounds.upperBound)
* @return this.bounds
*/
private Bounds completeBounds() {
final Bounds optimized = this.bounds;
final Bounds original = this.originalBounds;
if (optimized.ints().isEmpty()) {
for (IndexedEntry<TupleSet> entry : original.intBounds()) {
optimized.boundExactly(entry.index(), entry.value());
}
} else {
assert optimized.intBounds().equals(original.intBounds());
}
final Set<Relation> rels = optimized.relations();
for (Relation r : original.relations()) {
if (!rels.contains(r)) {
optimized.bound(r, original.lowerBound(r), original.upperBound(r));
}
}
return optimized;
}
Aggregations