Search in sources :

Example 16 with Evaluator

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");
}
Also used : Relation(kodkod.ast.Relation) HashMap(java.util.HashMap) Evaluator(kodkod.engine.Evaluator) URL(java.net.URL)

Example 17 with Evaluator

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);
}
Also used : Formula(kodkod.ast.Formula) Evaluator(kodkod.engine.Evaluator) Solution(kodkod.engine.Solution) HashSet(java.util.HashSet)

Example 18 with Evaluator

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 ));
}
Also used : Formula(kodkod.ast.Formula) Relation(kodkod.ast.Relation) Instance(kodkod.instance.Instance) Bounds(kodkod.instance.Bounds) ArrayList(java.util.ArrayList) TupleFactory(kodkod.instance.TupleFactory) Universe(kodkod.instance.Universe) Evaluator(kodkod.engine.Evaluator)

Aggregations

Evaluator (kodkod.engine.Evaluator)18 Formula (kodkod.ast.Formula)12 Solution (kodkod.engine.Solution)10 Relation (kodkod.ast.Relation)9 TupleFactory (kodkod.instance.TupleFactory)9 Universe (kodkod.instance.Universe)9 Bounds (kodkod.instance.Bounds)8 Instance (kodkod.instance.Instance)8 TupleSet (kodkod.instance.TupleSet)7 IntExpression (kodkod.ast.IntExpression)6 ArrayList (java.util.ArrayList)4 Expression (kodkod.ast.Expression)3 Solver (kodkod.engine.Solver)3 Tuple (kodkod.instance.Tuple)3 HashSet (java.util.HashSet)2 Variable (kodkod.ast.Variable)2 A4Reporter (edu.mit.csail.sdg.alloy4.A4Reporter)1 UniqueNameGenerator (edu.mit.csail.sdg.alloy4.UniqueNameGenerator)1 Type (edu.mit.csail.sdg.ast.Type)1 File (java.io.File)1