Search in sources :

Example 11 with TupleFactory

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

the class LAT258 method bounds.

/**
 * Returns the bounds for the given scope.
 *
 * @return the 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("n" + i);
    final Universe univ = new Universe(atoms);
    final TupleFactory f = univ.factory();
    final Bounds b = new Bounds(univ);
    b.bound(goal, f.setOf("n0"));
    final TupleSet all1 = f.allOf(1);
    b.bound(p, all1);
    b.bound(t, all1);
    b.bound(v, all1);
    b.bound(w, all1);
    b.bound(u, all1);
    b.bound(x, all1);
    b.bound(y, all1);
    b.bound(z, all1);
    b.bound(lessThan, f.allOf(2));
    final TupleSet all3 = f.allOf(3);
    b.bound(join, all3);
    b.bound(meet, all3);
    return b;
}
Also used : TupleSet(kodkod.instance.TupleSet) Bounds(kodkod.instance.Bounds) ArrayList(java.util.ArrayList) TupleFactory(kodkod.instance.TupleFactory) Universe(kodkod.instance.Universe)

Example 12 with TupleFactory

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

the class DiffEg method bounds.

/**
 * Returns the bounds for the given alloy scope.
 *
 * @return bounds for the given alloy scope
 */
public final Bounds bounds(int scope) {
    assert scope > 0;
    final List<String> atoms = new ArrayList<String>(4 * scope + 1);
    // Subject, Resource, Action, Conflicted
    for (int i = 0; i < scope; i++) atoms.add("Subject" + i);
    for (int i = 0; i < scope; i++) atoms.add("Resource" + i);
    for (int i = 0; i < scope; i++) atoms.add("Action" + i);
    for (int i = 0; i < scope; i++) atoms.add("Conflicted" + i);
    for (int i = 0; i < scope; i++) atoms.add("Request" + i);
    final Universe u = new Universe(atoms);
    final TupleFactory f = u.factory();
    final Bounds b = new Bounds(u);
    final int max = scope - 1;
    b.bound(Subject, f.range(f.tuple("Subject0"), f.tuple("Subject" + max)));
    b.bound(Resource, f.range(f.tuple("Resource0"), f.tuple("Resource" + max)));
    b.bound(Action, f.range(f.tuple("Action0"), f.tuple("Action" + max)));
    b.bound(Conflicted, f.range(f.tuple("Conflicted0"), f.tuple("Conflicted" + max)));
    b.bound(Request, f.range(f.tuple("Request0"), f.tuple("Request" + max)));
    // sRequest, rRequest, action, sConflicted, rConflicted;
    b.bound(sRequest, b.upperBound(Request).product(b.upperBound(Subject)));
    b.bound(rRequest, b.upperBound(Request).product(b.upperBound(Resource)));
    b.bound(action, b.upperBound(Request).product(b.upperBound(Action)));
    b.bound(sConflicted, b.upperBound(Conflicted).product(b.upperBound(Subject)));
    b.bound(rConflicted, b.upperBound(Conflicted).product(b.upperBound(Resource)));
    return b;
}
Also used : Bounds(kodkod.instance.Bounds) ArrayList(java.util.ArrayList) TupleFactory(kodkod.instance.TupleFactory) Universe(kodkod.instance.Universe)

Example 13 with TupleFactory

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

the class Hotel method bounds.

/**
 * Returns bounds for the given number of times, events, rooms, cards, keys and
 * guests.
 *
 * @return bounds for the given scopes.
 */
public Bounds bounds(int t, int e, int r, int c, int k, int g) {
    final Relation[] tops = { Time, Event, Room, Card, Key, Guest };
    final int[] scopes = { t, e, r, c, k, g };
    final List<String> atoms = new ArrayList<String>();
    for (int i = 0; i < tops.length; i++) {
        Relation top = tops[i];
        for (int j = 0, scope = scopes[i]; j < scope; j++) atoms.add(top.name() + j);
    }
    final Universe u = new Universe(atoms);
    final TupleFactory f = u.factory();
    final Bounds b = new Bounds(u);
    for (int i = 0; i < tops.length; i++) {
        Relation top = tops[i];
        b.bound(top, f.range(f.tuple(top.name() + 0), f.tuple(top.name() + (scopes[i] - 1))));
    }
    b.bound(first, b.upperBound(Time));
    b.bound(last, b.upperBound(Time));
    b.bound(next, b.upperBound(Time).product(b.upperBound(Time)));
    b.bound(pre, b.upperBound(Event).product(b.upperBound(Time)));
    b.bound(post, b.upperBound(Event).product(b.upperBound(Time)));
    b.bound(HotelEvent, b.upperBound(Event));
    b.bound(RoomCardEvent, b.upperBound(Event));
    b.bound(Enter, b.upperBound(Event));
    b.bound(NormalEnter, b.upperBound(Event));
    b.bound(RecodeEnter, b.upperBound(Event));
    b.bound(Checkin, b.upperBound(Event));
    b.bound(Checkout, b.upperBound(Event));
    b.bound(k1, b.upperBound(Card).product(b.upperBound(Key)));
    b.bound(k2, b.upperBound(Card).product(b.upperBound(Key)));
    b.bound(key, b.upperBound(Room).product(b.upperBound(Key)).product(b.upperBound(Time)));
    b.bound(prev, b.upperBound(Room).product(b.upperBound(Key)).product(b.upperBound(Time)));
    b.bound(occ, b.upperBound(Room).product(b.upperBound(Guest)).product(b.upperBound(Time)));
    b.bound(holds, b.upperBound(Guest).product(b.upperBound(Card)).product(b.upperBound(Time)));
    b.bound(guest, b.upperBound(HotelEvent).product(b.upperBound(Guest)));
    b.bound(room, b.upperBound(RoomCardEvent).product(b.upperBound(Room)));
    b.bound(card, b.upperBound(RoomCardEvent).product(b.upperBound(Card)));
    return b;
}
Also used : Relation(kodkod.ast.Relation) Bounds(kodkod.instance.Bounds) ArrayList(java.util.ArrayList) TupleFactory(kodkod.instance.TupleFactory) Universe(kodkod.instance.Universe)

Example 14 with TupleFactory

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

the class ToyLists method bounds.

/**
 * Returns the bounds for the toy lists problem with the given number of lists
 * and things.
 *
 * @return bounds for the toy lists problem with the given number of lists and
 *         things.
 */
public Bounds bounds(int lists, int things) {
    final List<String> atoms = new ArrayList<String>(lists + things);
    for (int i = 0; i < lists; i++) {
        atoms.add("list" + i);
    }
    for (int i = 0; i < things; i++) {
        atoms.add("thing" + i);
    }
    final Universe univ = new Universe(atoms);
    final TupleFactory f = univ.factory();
    final Bounds b = new Bounds(univ);
    b.bound(list, f.range(f.tuple("list0"), f.tuple("list" + (lists - 1))));
    b.bound(nonEmptyList, b.upperBound(list));
    b.bound(emptyList, b.upperBound(list));
    b.bound(thing, f.range(f.tuple("thing0"), f.tuple("thing" + (things - 1))));
    b.bound(car, b.upperBound(nonEmptyList).product(b.upperBound(thing)));
    b.bound(cdr, b.upperBound(nonEmptyList).product(b.upperBound(list)));
    b.bound(equivTo, b.upperBound(list).product(b.upperBound(list)));
    b.bound(prefixes, b.upperBound(list).product(b.upperBound(list)));
    return b;
}
Also used : Bounds(kodkod.instance.Bounds) ArrayList(java.util.ArrayList) TupleFactory(kodkod.instance.TupleFactory) Universe(kodkod.instance.Universe)

Example 15 with TupleFactory

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

the class ConfigAssure method display.

/**
 * Displays an instance obtained with the given options.
 *
 * @requires inst != null and opt != null
 */
private final void display(Instance inst, Options opt) {
    final Universe univ = inst.universe();
    final Evaluator eval = new Evaluator(inst, opt);
    final TupleFactory factory = univ.factory();
    final List<TupleSet> subnets = new ArrayList<TupleSet>();
    System.out.println("address\t\tnetwork id\tmask\tdevice-interface");
    for (int i = 0, ports = univ.size() - 32; i < ports; i++) {
        final Object atom = univ.atom(i);
        final Relation p = Relation.unary(atom.toString());
        inst.add(p, factory.setOf(atom));
        System.out.print(toQuad(eval.evaluate(addr(p))) + "\t");
        System.out.print(toQuad(eval.evaluate(netid(p))) + "\t");
        System.out.print(eval.evaluate(implicitMask(p)) + "\t");
        System.out.println(p);
        final TupleSet members = eval.evaluate(subnet(p));
        if (!members.isEmpty())
            subnets.add(members);
    }
    System.out.println("\nsubnets:");
    for (TupleSet sub : subnets) {
        System.out.println(sub);
    }
}
Also used : TupleSet(kodkod.instance.TupleSet) Relation(kodkod.ast.Relation) TupleFactory(kodkod.instance.TupleFactory) ArrayList(java.util.ArrayList) Universe(kodkod.instance.Universe) Evaluator(kodkod.engine.Evaluator)

Aggregations

TupleFactory (kodkod.instance.TupleFactory)85 Universe (kodkod.instance.Universe)77 Bounds (kodkod.instance.Bounds)76 TupleSet (kodkod.instance.TupleSet)55 ArrayList (java.util.ArrayList)45 Relation (kodkod.ast.Relation)45 Formula (kodkod.ast.Formula)35 Solution (kodkod.engine.Solution)30 Solver (kodkod.engine.Solver)25 IntExpression (kodkod.ast.IntExpression)20 Expression (kodkod.ast.Expression)19 Variable (kodkod.ast.Variable)19 Instance (kodkod.instance.Instance)15 Decls (kodkod.ast.Decls)11 Evaluator (kodkod.engine.Evaluator)9 Tuple (kodkod.instance.Tuple)8 LinkedList (java.util.LinkedList)4 LinkedHashSet (java.util.LinkedHashSet)3 Map (java.util.Map)2 Set (java.util.Set)2