use of kodkod.engine.Evaluator in project org.alloytools.alloy by AlloyTools.
the class EvaluatorTest method setUp.
/*
* @see TestCase#setUp()
*/
@Override
protected void setUp() throws Exception {
super.setUp();
URL resource = getClass().getResource(SOLUTION);
evaluator = new Evaluator(InstanceCreator.getInstance(resource.openStream()));
Map<String, Relation> nameToRelation = new HashMap<String, Relation>();
for (Relation r : evaluator.instance().relations()) {
nameToRelation.put(r.name(), r);
}
univ = relation(nameToRelation, UNIV_PATH, "univ");
hilary = relation(nameToRelation, PATH, "Hilary");
jocelyn = relation(nameToRelation, PATH, "Jocelyn");
person = relation(nameToRelation, PATH, "Person");
spouse = relation(nameToRelation, PATH, "spouse");
shaken = relation(nameToRelation, PATH, "shaken");
}
use of kodkod.engine.Evaluator in project org.alloytools.alloy by AlloyTools.
the class OverflowEnumTest method runTestForAll.
@Override
protected void runTestForAll(Tester t) {
GenericTester gt = (GenericTester) t;
this.op1 = Relation.unary("a");
this.op2 = Relation.unary("b");
bounds = superBounds.clone();
bounds.bound(op1, factory.noneOf(1), factory.allOf(1));
bounds.bound(op2, factory.noneOf(1), factory.allOf(1));
Formula goal = op1.one().and(op2.one()).and(ret.one());
// goal = goal.and(ret.sum().eq(gt.kodkodOpExpr(op1.sum(), op2.sum())));
goal = goal.and(ret.eq(gt.kodkodOpExpr(op1.sum(), op2.sum()).toExpression()));
Set<Res> kkRes = new HashSet<Res>();
Iterator<Solution> sols = solveAll(goal);
while (sols.hasNext()) {
Solution sol = sols.next();
if (sol.unsat())
break;
Evaluator evaluator = new Evaluator(sol.instance());
int ia = evalInt(evaluator, op1);
int ib = evalInt(evaluator, op2);
int ir = evalInt(evaluator, ret);
kkRes.add(new Res(ia, ib, ir));
}
Set<Res> jRes = new HashSet<Res>();
int min = min();
int max = max();
for (int i = min; i <= max; i++) {
for (int j = min; j <= max; j++) {
if (gt.skip(i, j))
continue;
int res = gt.exeJava(i, j);
if (res < min || res > max)
continue;
jRes.add(new Res(i, j, res));
}
}
assertEquals(kkRes, jRes);
}
use of kodkod.engine.Evaluator in project org.alloytools.alloy by AlloyTools.
the class BugTests method testGreg_11232005.
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 ));
}
Aggregations