use of kodkod.instance.TupleSet in project org.alloytools.alloy by AlloyTools.
the class COM008 method bounds.
/**
* Returns bounds for the given scope.
*
* @return bounds for the given scope.
*/
public final Bounds bounds(int n) {
assert n > 0;
final List<String> atoms = new ArrayList<String>(n);
atoms.add("goal");
for (int i = 0; i < n; i++) atoms.add("a" + i);
final Universe u = new Universe(atoms);
final Bounds bound = new Bounds(u);
final TupleFactory f = u.factory();
final TupleSet d1 = f.range(f.tuple("a0"), f.tuple("a" + (n - 1)));
final TupleSet d2 = d1.product(d1);
bound.bound(rewrite, d2);
bound.bound(equalish, d2);
bound.bound(a, d1);
bound.bound(b, d1);
bound.bound(c, d1);
bound.boundExactly(Atom, d1);
bound.bound(trr, d2);
bound.bound(goal, f.setOf("goal"));
return bound;
}
use of kodkod.instance.TupleSet in project org.alloytools.alloy by AlloyTools.
the class MED001 method bounds.
/**
* Returns bounds for the given scope.
*
* @return bounds for the given scope.
*/
public final Bounds bounds(int n) {
assert n > 0;
final List<String> atoms = new ArrayList<String>(n);
for (int i = 0; i < n; i++) atoms.add("a" + i);
final Universe u = new Universe(atoms);
final Bounds b = new Bounds(u);
final TupleFactory f = u.factory();
final TupleSet s = f.allOf(1);
b.bound(bcapacityne, s);
b.bound(bcapacityex, s);
b.bound(bcapacitysn, s);
b.bound(conditionhyper, s);
b.bound(conditionhypo, s);
b.bound(conditionnormo, s);
b.bound(drugi, s);
b.bound(uptakelg, s);
b.bound(uptakepg, s);
b.bound(releaselg, s);
b.bound(bsecretioni, s);
b.bound(drugbg, s);
b.bound(qilt27, s);
b.bound(s0, s);
b.bound(s1, s);
b.bound(s2, s);
b.bound(s3, s);
b.bound(drugsu, s);
b.bound(n0, s);
b.bound(gt, f.allOf(2));
return b;
}
use of kodkod.instance.TupleSet in project org.alloytools.alloy by AlloyTools.
the class A4Solution method query.
/**
* Query the Bounds object to find the lower/upper bound; throws ErrorFatal if
* expr is not Relation, nor a {union, product} of Relations.
*/
TupleSet query(boolean findUpper, Expression expr, boolean makeMutable) throws ErrorFatal {
if (expr == Expression.NONE)
return factory.noneOf(1);
if (expr == Expression.INTS)
return makeMutable ? sigintBounds.clone() : sigintBounds;
if (expr == KK_SEQIDX)
return makeMutable ? seqidxBounds.clone() : seqidxBounds;
if (expr == KK_STRING)
return makeMutable ? stringBounds.clone() : stringBounds;
if (expr instanceof Relation) {
TupleSet ans = findUpper ? bounds.upperBound((Relation) expr) : bounds.lowerBound((Relation) expr);
if (ans != null)
return makeMutable ? ans.clone() : ans;
} else if (expr instanceof BinaryExpression) {
BinaryExpression b = (BinaryExpression) expr;
if (b.op() == ExprOperator.UNION) {
TupleSet left = query(findUpper, b.left(), true);
TupleSet right = query(findUpper, b.right(), false);
left.addAll(right);
return left;
} else if (b.op() == ExprOperator.PRODUCT) {
TupleSet left = query(findUpper, b.left(), true);
TupleSet right = query(findUpper, b.right(), false);
return left.product(right);
}
}
throw new ErrorFatal("Unknown expression encountered during bounds computation: " + expr);
}
use of kodkod.instance.TupleSet in project org.alloytools.alloy by AlloyTools.
the class A4Solution method eval.
/**
* Return the A4TupleSet for the given field (if solution not yet solved, or
* unsatisfiable, or field not found, then return an empty tupleset)
*/
public A4TupleSet eval(Field field) {
try {
if (!solved || eval == null)
return new A4TupleSet(factory.noneOf(field.type().arity()), this);
A4TupleSet ans = evalCache.get(field);
if (ans != null)
return ans;
TupleSet ts = eval.evaluate((Expression) TranslateAlloyToKodkod.alloy2kodkod(this, field));
ans = new A4TupleSet(ts, this);
evalCache.put(field, ans);
return ans;
} catch (Err er) {
return new A4TupleSet(factory.noneOf(field.type().arity()), this);
}
}
use of kodkod.instance.TupleSet in project org.alloytools.alloy by AlloyTools.
the class A4Solution method toString.
/**
* Dumps the Kodkod solution into String.
*/
@Override
public String toString() {
if (!solved)
return "---OUTCOME---\nUnknown.\n";
if (eval == null)
return "---OUTCOME---\nUnsatisfiable.\n";
String answer = toStringCache;
if (answer != null)
return answer;
Instance sol = eval.instance();
StringBuilder sb = new StringBuilder();
sb.append("---INSTANCE---\n" + "integers={");
boolean firstTuple = true;
for (IndexedEntry<TupleSet> e : sol.intTuples()) {
if (firstTuple)
firstTuple = false;
else
sb.append(", ");
// No need to print e.index() since we've ensured the Int atom's
// String representation is always equal to ""+e.index()
Object atom = e.value().iterator().next().atom(0);
sb.append(atom2name(atom));
}
sb.append("}\n");
try {
for (Sig s : sigs) {
sb.append(s.label).append("=").append(eval(s)).append("\n");
for (Field f : s.getFields()) sb.append(s.label).append("<:").append(f.label).append("=").append(eval(f)).append("\n");
}
for (ExprVar v : skolems) {
sb.append("skolem ").append(v.label).append("=").append(eval(v)).append("\n");
}
return toStringCache = sb.toString();
} catch (Err er) {
return toStringCache = ("<Evaluator error occurred: " + er + ">");
}
}
Aggregations