use of kodkod.instance.TupleFactory in project org.alloytools.alloy by AlloyTools.
the class EvaluatorTest method testEvalTransitiveClosure.
public final void testEvalTransitiveClosure() {
// // ^(Hilary->Jocelyn) = Hilary->Jocelyn
// assertEquals(eval(hilary.product(jocelyn).closure()),
// eval(hilary.product(jocelyn)));
// // ^spouse = spouse + spouse.spouse
// assertEquals(eval(spouse.closure()),
// eval(spouse.union(spouse.join(spouse))));
// // Hilary.^shaken = univ - (univ - Person.shaken)
// assertEquals(eval(hilary.join(shaken.closure())),
// eval(univ.difference(univ.difference(person.join(shaken)))));
// try {
// eval(person.closure());
// fail("Expected IllegalArgumentException");
// } catch (IllegalArgumentException iae) {}
// ^r = value(^r)
final Relation r = Relation.binary("r");
final Universe u = evaluator.instance().universe();
final TupleFactory f = u.factory();
final Instance instance = new Instance(u);
// value(r) = u[0]->u[1] + u[1]->u[2] + u[2]->u[3] + u[3]->u[4]
TupleSet s = f.noneOf(r.arity());
for (int i = 0; i < 4; i++) s.add(f.tuple(u.atom(i), u.atom(i + 1)));
instance.add(r, s);
// value(^r) = value(r) + u[0]->u[2] + u[0]->u[3] + u[0]->u[4] +
// u[1]->u[3] u[1]->u[4] + u[2]->u[4]
Set<Tuple> result = new HashSet<Tuple>();
for (int i = 0; i < 4; i++) {
for (int j = i + 1; j < 5; j++) {
result.add(f.tuple(u.atom(i), u.atom(j)));
}
}
assertEquals((new Evaluator(instance)).evaluate(r.closure()), result);
// value(*r) = value(^r) + iden
for (int i = 0; i < 10; i++) {
result.add(f.tuple(u.atom(i), u.atom(i)));
}
assertEquals((new Evaluator(instance)).evaluate(r.reflexiveClosure()), result);
}
use of kodkod.instance.TupleFactory in project org.alloytools.alloy by AlloyTools.
the class Netconfig method bounds.
/**
* Returns a bounds object that constructs the 'scope' for analyzing the
* commands, using the given values for the number of sites, routers, and the
* length of time.
*
* @requires all arguments are positive and hqNum <= siteNum
* @return a bounds for the model
*/
public Bounds bounds(int siteNum, int hqNum, int routerNum, int timeLength) {
assert siteNum > 0 && hqNum > 0 && hqNum <= siteNum && routerNum > 0 && timeLength > 0;
final List<String> atoms = new ArrayList<String>(siteNum + routerNum + timeLength);
for (int i = 0; i < siteNum; i++) {
atoms.add("Site" + i);
}
for (int i = 0; i < routerNum; i++) {
atoms.add("Router" + i);
}
for (int i = 0; i < timeLength; i++) {
atoms.add("Time" + i);
}
final Universe u = new Universe(atoms);
final TupleFactory f = u.factory();
final Bounds b = new Bounds(u);
final String site0 = "Site0";
final String siteN = "Site" + (siteNum - 1);
final TupleSet sBound = f.range(f.tuple(site0), f.tuple(siteN));
b.boundExactly(Site, sBound);
b.boundExactly(HQ, f.range(f.tuple(site0), f.tuple("Site" + (hqNum - 1))));
if (hqNum < siteNum) {
b.boundExactly(Sub, f.range(f.tuple("Site" + hqNum), f.tuple(siteN)));
} else {
b.bound(Sub, f.noneOf(1));
}
final TupleSet tBound = f.range(f.tuple("Time0"), f.tuple("Time" + (timeLength - 1)));
b.bound(Time, tBound);
b.bound(start, tBound);
b.bound(end, tBound);
b.bound(tick, tBound.product(tBound));
final TupleSet rBound = f.range(f.tuple("Router0"), f.tuple("Router" + (routerNum - 1)));
b.boundExactly(Router, rBound);
// b.bound(site, rBound.product(sBound));
b.bound(satellite, rBound.product(rBound).product(tBound));
b.bound(lineOfSight, b.upperBound(satellite));
assert siteNum == routerNum;
final TupleSet siteBound = f.noneOf(2);
for (int i = 0; i < siteNum; i++) siteBound.add(f.tuple("Router" + i, "Site" + i));
// rBound.product(sBound));
b.boundExactly(site, siteBound);
return b;
}
use of kodkod.instance.TupleFactory in project org.alloytools.alloy by AlloyTools.
the class ALG195_1 method bounds.
/**
* Returns the partial bounds the problem (axioms 1, 4, 9-11).
*
* @return the partial bounds for the problem
*/
public Bounds bounds() {
final List<String> atoms = new ArrayList<String>(14);
for (int i = 0; i < 7; i++) atoms.add("e1" + i);
for (int i = 0; i < 7; i++) atoms.add("e2" + i);
final Universe u = new Universe(atoms);
final Bounds b = new Bounds(u);
final TupleFactory f = u.factory();
final TupleSet s1bound = f.range(f.tuple("e10"), f.tuple("e16"));
final TupleSet s2bound = f.range(f.tuple("e20"), f.tuple("e26"));
b.boundExactly(s1, s1bound);
b.boundExactly(s2, s2bound);
// axioms 9, 10, 11
for (int i = 0; i < 7; i++) {
b.boundExactly(e1[i], f.setOf("e1" + i));
b.boundExactly(e2[i], f.setOf("e2" + i));
}
// axom 1
b.bound(op1, f.area(f.tuple("e10", "e10", "e10"), f.tuple("e16", "e16", "e16")));
// axiom 4
b.bound(op2, f.area(f.tuple("e20", "e20", "e20"), f.tuple("e26", "e26", "e26")));
final TupleSet hbound = s1bound.product(s2bound);
for (Relation r : h) {
b.bound(r, hbound);
}
return b;
}
use of kodkod.instance.TupleFactory in project org.alloytools.alloy by AlloyTools.
the class ALG195 method bounds.
/**
* Returns the bounds the problem (axioms 1, 4, 9-13, second formula of 14-15,
* and first formula of 16-22).
*
* @return the bounds for the problem
*/
@Override
public final Bounds bounds() {
final Bounds b = super.bounds();
final TupleFactory f = b.universe().factory();
final TupleSet op1h = b.upperBound(op1).clone();
final TupleSet op2h = b.upperBound(op2).clone();
for (int i = 0; i < 7; i++) {
// axiom 12
op1h.remove(f.tuple("e1" + i, "e1" + i, "e1" + i));
// axiom 13
op2h.remove(f.tuple("e2" + i, "e2" + i, "e2" + i));
}
// axiom
final TupleSet op1l = f.setOf(f.tuple("e15", "e15", "e11"));
// 14,
// line
// 2
// axiom
final TupleSet op2l = f.setOf(f.tuple("e25", "e25", "e21"));
// 15,
// line
// 2
op1h.removeAll(f.area(f.tuple("e15", "e15", "e10"), f.tuple("e15", "e15", "e16")));
op1h.addAll(op1l);
op2h.removeAll(f.area(f.tuple("e25", "e25", "e20"), f.tuple("e25", "e25", "e26")));
op2h.addAll(op2l);
b.bound(op1, op1l, op1h);
b.bound(op2, op2l, op2h);
final TupleSet high = f.area(f.tuple("e10", "e20"), f.tuple("e14", "e26"));
high.addAll(f.area(f.tuple("e16", "e20"), f.tuple("e16", "e26")));
// first line of axioms 16-22
for (int i = 0; i < 7; i++) {
Tuple t = f.tuple("e15", "e2" + i);
high.add(t);
b.bound(h[i], f.setOf(t), high);
high.remove(t);
}
return b;
}
use of kodkod.instance.TupleFactory 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;
}
Aggregations