Search in sources :

Example 16 with Instance

use of kodkod.instance.Instance in project org.alloytools.alloy by AlloyTools.

the class BugTests method testEmina_01232006.

public final void testEmina_01232006() {
    final List<String> atoms = new ArrayList<String>(5);
    for (int i = 0; i < 5; i++) atoms.add("a" + i);
    final Universe u = new Universe(atoms);
    final TupleFactory tf = u.factory();
    final Relation r1 = Relation.unary("r1"), r2 = Relation.binary("r2"), r3 = Relation.ternary("r3");
    final Bounds b = new Bounds(u);
    final TupleSet r2Bound = tf.noneOf(2);
    for (int i = 0; i < 4; i++) r2Bound.add(tf.tuple(atoms.get(i), atoms.get(i)));
    r2Bound.add(tf.tuple("a4", "a1"));
    r2Bound.add(tf.tuple("a4", "a2"));
    b.bound(r2, r2Bound);
    b.bound(r1, tf.setOf("a0", "a3"), tf.setOf("a0", "a3", "a4"));
    b.bound(r3, tf.setOf(tf.tuple("a0", "a0", "a0"), tf.tuple("a3", "a3", "a3")));
    final Formula f = r1.product(r2).in(r3);
    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 : TupleSet(kodkod.instance.TupleSet) 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)

Example 17 with Instance

use of kodkod.instance.Instance in project org.alloytools.alloy by AlloyTools.

the class BugTests method testVincent_02172006.

public final void testVincent_02172006() {
    // set ups universe of atoms [1..257]
    final List<Integer> atoms = new ArrayList<Integer>();
    // change this to 256, and the program works
    for (int i = 0; i < 257; i++) {
        atoms.add(i + 1);
    }
    final Universe universe = new Universe(atoms);
    final Bounds bounds = new Bounds(universe);
    final TupleFactory factory = universe.factory();
    final Relation oneRel = Relation.unary("oneRel");
    final Relation pCourses = Relation.binary("pCourses");
    final Relation prev = Relation.binary("prev");
    final Relation sCourses = Relation.binary("sCourses");
    final Relation prereqs = Relation.binary("prereqs");
    final Relation rel = Relation.unary("rel");
    bounds.bound(oneRel, factory.setOf(factory.tuple(atoms.get(0))), factory.setOf(factory.tuple(atoms.get(0))));
    bounds.bound(rel, factory.allOf(1));
    // list1 and list2 are temp lists for creating bounds for binary
    // relations below
    // list1 = [1, 2]
    // list2 = [3, 2]
    // ts = [ [1, 2], [2, 2], [3, 2] ]
    List<Integer> list1 = new ArrayList<Integer>();
    list1.add(atoms.get(0));
    list1.add(atoms.get(1));
    List<Integer> list2 = new ArrayList<Integer>();
    list2.add(atoms.get(2));
    list2.add(atoms.get(1));
    TupleSet ts = factory.area(factory.tuple(list1), factory.tuple(list2));
    bounds.bound(pCourses, ts);
    bounds.bound(prev, ts);
    bounds.bound(sCourses, ts);
    bounds.bound(prereqs, ts);
    // all s: futureSemesters | all c: s.courses | no c.prereqs or some p:
    // c.prereqs | p.courses in s.prev^.courses
    final Variable s = Variable.unary("s"), c = Variable.unary("c"), p = Variable.unary("p");
    Formula formula = (p.join(pCourses).in(s.join(prev.closure()).join(sCourses)).forAll(p.oneOf(c.join(prereqs)))).forAll(c.oneOf(s.join(sCourses))).forAll(s.oneOf(rel));
    // System.out.println(formula);
    // solve
    final Instance instance = solver.solve(formula, bounds).instance();
    assertNotNull(instance);
}
Also used : TupleSet(kodkod.instance.TupleSet) Formula(kodkod.ast.Formula) Relation(kodkod.ast.Relation) Variable(kodkod.ast.Variable) Instance(kodkod.instance.Instance) Bounds(kodkod.instance.Bounds) ArrayList(java.util.ArrayList) TupleFactory(kodkod.instance.TupleFactory) Universe(kodkod.instance.Universe)

Example 18 with Instance

use of kodkod.instance.Instance in project org.alloytools.alloy by AlloyTools.

the class InstanceCreator method getInstance.

/**
 * Fills the instance with the relations specified in this.document; if an error
 * occurs during processing, the instance remains null
 */
private Instance getInstance() {
    initAtomsAndRelations();
    final Universe u = new Universe(atoms);
    final TupleFactory f = u.factory();
    final Instance instance = new Instance(u);
    for (Map.Entry<Relation, Set<List<String>>> entry : relations.entrySet()) {
        Relation r = entry.getKey();
        TupleSet s = f.noneOf(r.arity());
        for (List<?> atoms : entry.getValue()) {
            s.add(f.tuple(atoms));
        }
        instance.add(r, s);
    }
    return instance;
}
Also used : TupleSet(kodkod.instance.TupleSet) Relation(kodkod.ast.Relation) LinkedHashSet(java.util.LinkedHashSet) TupleSet(kodkod.instance.TupleSet) Set(java.util.Set) Instance(kodkod.instance.Instance) TupleFactory(kodkod.instance.TupleFactory) Universe(kodkod.instance.Universe) HashMap(java.util.HashMap) Map(java.util.Map)

Example 19 with Instance

use of kodkod.instance.Instance in project org.alloytools.alloy by AlloyTools.

the class SkolemizationTest method testNoSkolems.

private final void testNoSkolems(Decls d, Formula f) {
    Instance inst = solve(f.not());
    assertEquals(bounds.relations(), inst.relations());
    inst = solve(f.or(r2a.in(r2b)));
    assertEquals(bounds.relations(), inst.relations());
    inst = solve(f.iff(r2a.in(r2b)));
    assertEquals(bounds.relations(), inst.relations());
    inst = solve(r2a.in(r2b).implies(f));
    assertEquals(bounds.relations(), inst.relations());
}
Also used : Instance(kodkod.instance.Instance)

Example 20 with Instance

use of kodkod.instance.Instance in project org.alloytools.alloy by AlloyTools.

the class SkolemizationTest method testSkolems.

private final void testSkolems(Multiplicity mult) {
    final Variable va = Variable.unary("va");
    final Variable vb = Variable.unary("vb");
    final Set<String> skolems = new HashSet<String>(4);
    Decl da = va.declare(mult, r1a);
    Decl db = vb.declare(mult, r1b);
    skolems.add("$" + va.name());
    Instance inst = solve(va.in(r1b.join(r2b)).forAll(da).not());
    assertSkolems(bounds, inst, skolems);
    inst = solve((r2b.some().implies(va.in(r1b.join(r2b)).forAll(da))).not());
    assertSkolems(bounds, inst, skolems);
    inst = solve(va.in(r1b.join(r2b)).forSome(da));
    assertSkolems(bounds, inst, skolems);
    inst = solve(va.in(r1b.join(r2b)).forSome(da).and(va.in(r1b).not().forAll(mult == Multiplicity.ONE ? da : va.oneOf(r1a))));
    assertSkolems(bounds, inst, skolems);
    final Expression e0 = va.join(r2a);
    final Formula f0 = e0.some().forSome(va.oneOf(r1a));
    final Formula f1 = e0.no().forAll(va.oneOf(r2a.join(r1b)));
    inst = solve(f0.and(f1));
    assertSkolems(bounds, inst, skolems);
    skolems.add("$" + vb.name());
    inst = solve(va.in(vb.join(r2b)).forSome(da.and(vb.oneOf(va.join(r2a)))));
    assertSkolems(bounds, inst, skolems);
    inst = solve((va.in(vb.join(r2b)).forAll(vb.oneOf(va.join(r2a))).forAll(da)).not());
    assertSkolems(bounds, inst, skolems);
    inst = solve(va.in(vb.join(r2b)).forAll(da.and(db)).not());
    assertSkolems(bounds, inst, skolems);
    inst = solve(va.in(vb.join(r2b)).forSome(da.and(db)));
    assertSkolems(bounds, inst, skolems);
    inst = solve(va.in(r1b.join(r2b)).forSome(da).and(r1b.in(vb).forAll(db).not()));
    assertSkolems(bounds, inst, skolems);
}
Also used : Formula(kodkod.ast.Formula) Variable(kodkod.ast.Variable) Instance(kodkod.instance.Instance) Expression(kodkod.ast.Expression) Decl(kodkod.ast.Decl) HashSet(java.util.HashSet)

Aggregations

Instance (kodkod.instance.Instance)25 Formula (kodkod.ast.Formula)17 Relation (kodkod.ast.Relation)15 TupleFactory (kodkod.instance.TupleFactory)15 Universe (kodkod.instance.Universe)14 TupleSet (kodkod.instance.TupleSet)13 Bounds (kodkod.instance.Bounds)12 ArrayList (java.util.ArrayList)8 Variable (kodkod.ast.Variable)8 Evaluator (kodkod.engine.Evaluator)8 IntExpression (kodkod.ast.IntExpression)6 Solution (kodkod.engine.Solution)6 Expression (kodkod.ast.Expression)5 Tuple (kodkod.instance.Tuple)5 Decl (kodkod.ast.Decl)4 HashSet (java.util.HashSet)3 Solver (kodkod.engine.Solver)3 A4Reporter (edu.mit.csail.sdg.alloy4.A4Reporter)1 Err (edu.mit.csail.sdg.alloy4.Err)1 UniqueNameGenerator (edu.mit.csail.sdg.alloy4.UniqueNameGenerator)1