Search in sources :

Example 46 with Universe

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

the class FileSystem 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 * 3;
    final List<String> atoms = new ArrayList<String>(n);
    for (int i = 0; i < scope; i++) atoms.add("Object" + i);
    for (int i = 0; i < scope; i++) atoms.add("Name" + i);
    for (int i = 0; i < scope; i++) atoms.add("DirEntry" + 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(Obj, f.range(f.tuple("Object0"), f.tuple("Object" + max)));
    b.boundExactly(Root, f.setOf("Object0"));
    b.bound(Cur, b.upperBound(Obj));
    b.bound(File, b.upperBound(Obj));
    b.bound(Dir, b.upperBound(Obj));
    b.bound(Name, f.range(f.tuple("Name0"), f.tuple("Name" + max)));
    b.bound(DirEntry, f.range(f.tuple("DirEntry0"), f.tuple("DirEntry" + max)));
    b.bound(entries, b.upperBound(Dir).product(b.upperBound(DirEntry)));
    b.bound(parent, b.upperBound(Dir).product(b.upperBound(Dir)));
    b.bound(name, b.upperBound(DirEntry).product(b.upperBound(Name)));
    b.bound(contents, b.upperBound(DirEntry).product(b.upperBound(Obj)));
    return b;
}
Also used : Bounds(kodkod.instance.Bounds) ArrayList(java.util.ArrayList) TupleFactory(kodkod.instance.TupleFactory) Universe(kodkod.instance.Universe)

Example 47 with Universe

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

the class Pigeonhole method bounds.

/**
 * Returns the bounds for the given number of pigeons and holes.
 *
 * @return bounds
 */
public Bounds bounds(int pigeons, int holes) {
    final List<String> atoms = new ArrayList<String>(pigeons + holes);
    for (int i = 0; i < pigeons; i++) {
        atoms.add("Pigeon" + i);
    }
    for (int i = 0; i < holes; i++) {
        atoms.add("Hole" + i);
    }
    final Universe u = new Universe(atoms);
    final TupleFactory f = u.factory();
    final Bounds b = new Bounds(u);
    final TupleSet pbound = f.range(f.tuple("Pigeon0"), f.tuple("Pigeon" + (pigeons - 1)));
    final TupleSet hbound = f.range(f.tuple("Hole0"), f.tuple("Hole" + (holes - 1)));
    b.boundExactly(Pigeon, pbound);
    b.boundExactly(Hole, hbound);
    b.bound(hole, pbound.product(hbound));
    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 48 with Universe

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

the class Toughnut method bounds.

/**
 * Returns bounds for an nxn board.
 *
 * @return bounds for an nxn board.
 */
public Bounds bounds(int n) {
    assert n > 0;
    final List<String> atoms = new ArrayList<String>(n);
    for (int i = 0; i < n; i++) {
        atoms.add(String.valueOf(i));
    }
    final Universe u = new Universe(atoms);
    final Bounds b = new Bounds(u);
    final TupleFactory f = u.factory();
    b.boundExactly(Cell, f.allOf(1));
    final TupleSet ordBound = f.noneOf(2);
    for (int i = 0; i < n - 1; i++) {
        ordBound.add(f.tuple(String.valueOf(i), String.valueOf(i + 1)));
    }
    b.boundExactly(ord, ordBound);
    final TupleSet board = f.allOf(2);
    board.remove(f.tuple(String.valueOf(0), String.valueOf(0)));
    board.remove(f.tuple(String.valueOf(n - 1), String.valueOf(n - 1)));
    b.bound(covered, board.product(board));
    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 49 with Universe

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

the class Viktor method bounds.

/**
 * Returns the bounds for the problem.
 *
 * @return bounds
 */
public final Bounds bounds() {
    List<String> atoms = new ArrayList<String>(cols + 1);
    for (int i = 0; i < cols; i++) {
        atoms.add(String.valueOf(i));
    }
    atoms.add("a");
    final Universe u = new Universe(atoms);
    final TupleFactory f = u.factory();
    final Bounds b = new Bounds(u);
    final TupleSet abound = f.setOf("a");
    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < cols; j++) {
            b.bound(a[i][j], abound);
        }
    }
    final TupleSet xbound = f.range(f.tuple(String.valueOf(0)), f.tuple(String.valueOf(cols - 1)));
    for (int j = 0; j < cols; j++) {
        b.bound(x[j], xbound);
        b.boundExactly(j, f.setOf(String.valueOf(j)));
    }
    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 50 with Universe

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

the class ConfigAssure method bounds.

/**
 * Returns the bounds corresponding to the given ip address and subnet files.
 *
 * @return bounds corresponding to the given ip address and subnet files.
 * @throws IOException if either of the files cannot be found or accessed
 * @throws IllegalArgumentException if either of the files cannot be parsed
 */
public Bounds bounds(String ipAddrsFile, String subnetsFile) throws IOException {
    final Map<String, NetNode> nodes = parseAddresses(ipAddrsFile);
    final Map<NetNode, Subnet> subnets = parseSubnets(subnetsFile, nodes);
    final Universe universe = universe(nodes.keySet());
    final Bounds bounds = new Bounds(universe);
    final TupleFactory factory = universe.factory();
    // bind the integers
    for (int i = 0; i < 32; i++) {
        bounds.boundExactly(1 << i, factory.setOf(Integer.valueOf(1 << i)));
    }
    // bind the port relation exactly to the port names
    bounds.boundExactly(port, factory.range(factory.tuple(universe.atom(0)), factory.tuple(universe.atom(nodes.keySet().size() - 1))));
    // bind the unknown relation exactly to the port names of ports with
    // unknown addresses or masks
    final TupleSet unknownBound = factory.noneOf(1);
    for (NetNode n : nodes.values()) {
        if (!n.known()) {
            unknownBound.add(factory.tuple(n.port));
        }
    }
    bounds.boundExactly(unknown, unknownBound);
    // bind the subnet relation exactly, choosing the first element of each
    // subnet as the representative
    final TupleSet subnetBound = factory.noneOf(2);
    for (Map.Entry<NetNode, Subnet> entry : subnets.entrySet()) {
        final NetNode rep = entry.getKey();
        for (NetNode member : entry.getValue().members) {
            subnetBound.add(factory.tuple(rep.port, member.port));
        }
    }
    bounds.boundExactly(subnet, subnetBound);
    // bind the addr relation so that each address is guaranteed to be
    // between minAddr (121.96.0.0) and maxAddr (121.96.255.255), inclusive
    final TupleSet lAddr = factory.noneOf(2), uAddr = factory.noneOf(2);
    for (NetNode node : nodes.values()) {
        if (node.varAddress) {
            // unknown address
            lAddr.addAll(portToBits(factory, node.port, minAddr));
            uAddr.addAll(portToBits(factory, node.port, maxAddr));
        } else {
            // known address
            final TupleSet portToAddrBits = portToBits(factory, node.port, node.address);
            lAddr.addAll(portToAddrBits);
            uAddr.addAll(portToAddrBits);
        }
    }
    bounds.bound(addr, lAddr, uAddr);
    // bind the group and groupMask relations so that all ports with the
    // same interface on the same subnet are guaranteed to have the same
    // mask
    final TupleSet lMask = factory.noneOf(2), uMask = factory.noneOf(2), groupBound = factory.noneOf(2);
    for (Subnet sub : subnets.values()) {
        for (Map.Entry<NetNode, Set<NetNode>> entry : sub.groups.entrySet()) {
            final NetNode rep = entry.getKey();
            for (NetNode member : entry.getValue()) {
                groupBound.add(factory.tuple(member.port, rep.port));
                // remove a grouped member out of
                nodes.remove(member.port);
            // the addresses set
            }
            if (rep.varMask) {
                // unknown mask for the representative
                uMask.addAll(portToBits(factory, rep.port, 31));
            } else {
                // known mask for the representative
                final TupleSet portToMaskBits = portToBits(factory, rep.port, rep.mask);
                lMask.addAll(portToMaskBits);
                uMask.addAll(portToMaskBits);
            }
        }
    }
    // of any subnet
    for (NetNode ungrouped : nodes.values()) {
        groupBound.add(factory.tuple(ungrouped.port, ungrouped.port));
        if (ungrouped.varMask) {
            // unknown mask for the representative
            uMask.addAll(portToBits(factory, ungrouped.port, 31));
        } else {
            // known mask for the representative
            final TupleSet portToMaskBits = portToBits(factory, ungrouped.port, ungrouped.mask);
            lMask.addAll(portToMaskBits);
            uMask.addAll(portToMaskBits);
        }
    }
    bounds.bound(groupMask, lMask, uMask);
    bounds.boundExactly(group, groupBound);
    // ", unknown.size: " + unknownBound.size());
    return bounds;
}
Also used : TupleSet(kodkod.instance.TupleSet) LinkedHashSet(java.util.LinkedHashSet) TupleSet(kodkod.instance.TupleSet) Set(java.util.Set) Bounds(kodkod.instance.Bounds) TupleFactory(kodkod.instance.TupleFactory) Universe(kodkod.instance.Universe) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

Universe (kodkod.instance.Universe)83 Bounds (kodkod.instance.Bounds)79 TupleFactory (kodkod.instance.TupleFactory)77 TupleSet (kodkod.instance.TupleSet)50 ArrayList (java.util.ArrayList)46 Relation (kodkod.ast.Relation)45 Formula (kodkod.ast.Formula)37 Solution (kodkod.engine.Solution)32 Solver (kodkod.engine.Solver)26 Variable (kodkod.ast.Variable)21 Expression (kodkod.ast.Expression)20 IntExpression (kodkod.ast.IntExpression)20 Instance (kodkod.instance.Instance)14 Decls (kodkod.ast.Decls)11 Evaluator (kodkod.engine.Evaluator)9 LinkedList (java.util.LinkedList)4 Tuple (kodkod.instance.Tuple)4 LinkedHashSet (java.util.LinkedHashSet)3 Map (java.util.Map)2 Set (java.util.Set)2