Search in sources :

Example 76 with Bounds

use of kodkod.instance.Bounds 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 77 with Bounds

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

the class Hotel method main.

/**
 * Usage: java examples.Hotel [scope]
 */
public static void main(String[] args) {
    if (args.length < 1)
        usage();
    try {
        final int n = Integer.parseInt(args[0]);
        if (n < 1)
            usage();
        final Hotel model = new Hotel();
        final Solver solver = new Solver();
        solver.options().setSolver(SATFactory.MiniSatProver);
        solver.options().setLogTranslation(1);
        final Formula f = model.checkNoBadEntry();
        final Bounds b = model.bounds(n);
        // System.out.println(PrettyPrinter.print(f, 2, 100));
        final Solution sol = solver.solve(f, b);
        System.out.println(sol);
        if (sol.instance() == null) {
            final Proof proof = sol.proof();
            System.out.println("top-level formulas: " + proof.log().roots().size());
            System.out.println("initial core: " + proof.highLevelCore().size());
            System.out.print("\nminimizing core ... ");
            final long start = System.currentTimeMillis();
            proof.minimize(new RCEStrategy(proof.log()));
            final Set<Formula> core = Nodes.minRoots(f, proof.highLevelCore().values());
            final long end = System.currentTimeMillis();
            System.out.println("done (" + (end - start) + " ms).");
            System.out.println("minimal core: " + core.size());
            for (Formula u : core) {
                System.out.println(PrettyPrinter.print(u, 2, 100));
            }
            checkMinimal(core, b);
        } else {
            System.out.println(sol);
        }
    } catch (NumberFormatException nfe) {
        usage();
    }
}
Also used : Formula(kodkod.ast.Formula) Solver(kodkod.engine.Solver) RCEStrategy(kodkod.engine.ucore.RCEStrategy) Bounds(kodkod.instance.Bounds) Proof(kodkod.engine.Proof) Solution(kodkod.engine.Solution)

Example 78 with Bounds

use of kodkod.instance.Bounds 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 79 with Bounds

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

the class Toughnut method main.

/**
 * Usage: java examples.Toughnut [size of one side of the board; optional]
 */
public static void main(String[] args) {
    try {
        int n = args.length == 0 ? 4 : Integer.parseInt(args[0]);
        final Toughnut nut = new Toughnut();
        final Solver solver = new Solver();
        solver.options().setSolver(SATFactory.MiniSat);
        final Formula covering = nut.checkBelowTooDoublePrime();
        final Bounds bounds = nut.bounds(n);
        // System.out.println(covering);
        // System.out.println(bounds);
        final Solution sol = solver.solve(covering, bounds);
        System.out.println(sol);
    } catch (NumberFormatException nfe) {
        System.out.println("Usage: java examples.Toughnut [size of one side of the board; optional]");
    }
}
Also used : Formula(kodkod.ast.Formula) Solver(kodkod.engine.Solver) Bounds(kodkod.instance.Bounds) Solution(kodkod.engine.Solution)

Example 80 with Bounds

use of kodkod.instance.Bounds 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)

Aggregations

Bounds (kodkod.instance.Bounds)140 Formula (kodkod.ast.Formula)83 Universe (kodkod.instance.Universe)79 TupleFactory (kodkod.instance.TupleFactory)76 Solution (kodkod.engine.Solution)75 Solver (kodkod.engine.Solver)67 TupleSet (kodkod.instance.TupleSet)55 Relation (kodkod.ast.Relation)49 ArrayList (java.util.ArrayList)45 Expression (kodkod.ast.Expression)21 Variable (kodkod.ast.Variable)21 IntExpression (kodkod.ast.IntExpression)20 Instance (kodkod.instance.Instance)12 Decls (kodkod.ast.Decls)11 Evaluator (kodkod.engine.Evaluator)8 HigherOrderDeclException (kodkod.engine.fol2sat.HigherOrderDeclException)7 UnboundLeafException (kodkod.engine.fol2sat.UnboundLeafException)7 ConsoleReporter (kodkod.engine.config.ConsoleReporter)6 Tuple (kodkod.instance.Tuple)6 LinkedHashSet (java.util.LinkedHashSet)5