Search in sources :

Example 41 with TupleFactory

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

the class Lists method bounds.

/**
 * Returns the bounds for the given scope.
 *
 * @return the bounds for the given scope.
 */
public final Bounds bounds(int scope) {
    assert scope > 0;
    final int n = scope * 2;
    final List<String> atoms = new ArrayList<String>(n);
    for (int i = 0; i < scope; i++) atoms.add("Thing" + i);
    for (int i = 0; i < scope; i++) atoms.add("List" + i);
    // private final Relation Thing, List, NonEmptyList, EmptyList;
    // private final Relation car, cdr, equivTo, prefixes;
    final Universe u = new Universe(atoms);
    final TupleFactory f = u.factory();
    final Bounds b = new Bounds(u);
    final int max = scope - 1;
    b.bound(Thing, f.range(f.tuple("Thing0"), f.tuple("Thing" + max)));
    b.bound(List, f.range(f.tuple("List0"), f.tuple("List" + max)));
    b.bound(EmptyList, b.upperBound(List));
    b.bound(NonEmptyList, b.upperBound(List));
    b.bound(car, b.upperBound(List).product(b.upperBound(Thing)));
    b.bound(cdr, b.upperBound(List).product(b.upperBound(List)));
    b.bound(equivTo, b.upperBound(cdr));
    b.bound(prefixes, b.upperBound(cdr));
    return b;
}
Also used : Bounds(kodkod.instance.Bounds) ArrayList(java.util.ArrayList) TupleFactory(kodkod.instance.TupleFactory) Universe(kodkod.instance.Universe)

Example 42 with TupleFactory

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

the class RingElection method bounds.

/**
 * Returns a bounds object that scopes Process, Time, and their fields according
 * to given values.
 *
 * @return bounds
 */
public Bounds bounds(int processes, int times) {
    final List<String> atoms = new ArrayList<String>(processes + times);
    for (int i = 0; i < processes; i++) {
        atoms.add("Process" + i);
    }
    for (int i = 0; i < times; i++) {
        atoms.add("Time" + i);
    }
    final Universe u = new Universe(atoms);
    final TupleFactory f = u.factory();
    final Bounds b = new Bounds(u);
    final TupleSet pb = f.range(f.tuple("Process0"), f.tuple("Process" + (processes - 1)));
    final TupleSet tb = f.range(f.tuple("Time0"), f.tuple("Time" + (times - 1)));
    b.bound(Process, pb);
    b.bound(succ, pb.product(pb));
    b.bound(toSend, pb.product(pb).product(tb));
    b.bound(elected, pb.product(tb));
    b.bound(pord, pb.product(pb));
    b.bound(pfirst, pb);
    b.bound(plast, pb);
    b.bound(Time, tb);
    b.bound(tord, tb.product(tb));
    b.bound(tfirst, tb);
    b.bound(tlast, tb);
    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 43 with TupleFactory

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

the class Trees method bounds.

/**
 * Returns the bounds for the Trees problem that uses the given number of
 * vertices.
 *
 * @return bounds for the Trees problem that uses the given number of vertices
 */
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("v" + i);
    final Universe u = new Universe(atoms);
    final TupleFactory f = u.factory();
    final Bounds b = new Bounds(u);
    b.bound(V, f.allOf(1));
    b.bound(E, f.allOf(2));
    return b;
}
Also used : Bounds(kodkod.instance.Bounds) ArrayList(java.util.ArrayList) TupleFactory(kodkod.instance.TupleFactory) Universe(kodkod.instance.Universe)

Example 44 with TupleFactory

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

the class Bigconfig method bounds.

/**
 * Returns a bounds with the given number of hqs and subs, constructed using the
 * given universe.
 *
 * @requires hqNum > 0 && subNum > 0
 * @requires u contains at least (hqNum+sub) Router atoms and as many Site atoms
 * @return bounds
 */
private Bounds bounds(int hqNum, int subNum, Universe u) {
    final TupleFactory f = u.factory();
    final Bounds b = new Bounds(u);
    final int siteMax = hqNum + subNum - 1;
    final String site0 = "Site0";
    final String siteN = "Site" + siteMax;
    final String siteHQ = "Site" + (hqNum - 1);
    final String siteSub = "Site" + hqNum;
    final String router0 = "Router0";
    final String routerN = "Router" + siteMax;
    final TupleSet sites = f.range(f.tuple(site0), f.tuple(siteN));
    b.boundExactly(Site, sites);
    b.boundExactly(HQ, f.range(f.tuple(site0), f.tuple(siteHQ)));
    b.boundExactly(Sub, f.range(f.tuple(siteSub), f.tuple(siteN)));
    final TupleSet routers = f.range(f.tuple(router0), f.tuple(routerN));
    b.boundExactly(Router, routers);
    b.bound(link, routers.product(routers));
    // b.bound(site, routers.product(sites));
    final TupleSet routerLocations = f.noneOf(2);
    for (int i = 0; i <= siteMax; i++) {
        routerLocations.add(f.tuple("Router" + i, "Site" + i));
    }
    b.boundExactly(site, routerLocations);
    return b;
}
Also used : TupleSet(kodkod.instance.TupleSet) Bounds(kodkod.instance.Bounds) TupleFactory(kodkod.instance.TupleFactory)

Example 45 with TupleFactory

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

the class IntConstraints method bounds.

/**
 * Returns a bounds for the problem.
 */
public final Bounds bounds() {
    final List<Integer> atoms = new ArrayList<Integer>(14);
    for (int i = 0; i < 32; i++) {
        atoms.add(Integer.valueOf(1 << i));
    }
    final Universe u = new Universe(atoms);
    final TupleFactory f = u.factory();
    final Bounds b = new Bounds(u);
    // bound the integers
    for (int i = 0; i < 32; i++) {
        b.boundExactly(1 << i, f.setOf(Integer.valueOf(1 << i)));
    }
    // instance based on the low/high range for each variable.
    for (int i = 0; i < 1000; i++) {
        TupleSet lower = f.noneOf(1), upper = f.noneOf(1);
        int min = low + i * 10, max = min + 10, bit = 31;
        // constraints
        while (bit >= 0) {
            int bitVal = 1 << bit;
            if ((min & bitVal) == (max & bitVal)) {
                if ((min & bitVal) != 0) {
                    Tuple bitTuple = f.tuple(Integer.valueOf(bitVal));
                    lower.add(bitTuple);
                    upper.add(bitTuple);
                }
            } else {
                // get out of the loop as soon as patterns diverge
                break;
            }
            bit--;
        }
        // them into upper bound but not lower
        while (bit >= 0) {
            upper.add(f.tuple(Integer.valueOf(1 << bit)));
            bit--;
        }
        b.bound(var[i], lower, upper);
    }
    return b;
}
Also used : TupleSet(kodkod.instance.TupleSet) Bounds(kodkod.instance.Bounds) ArrayList(java.util.ArrayList) TupleFactory(kodkod.instance.TupleFactory) Universe(kodkod.instance.Universe) Tuple(kodkod.instance.Tuple)

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