Search in sources :

Example 66 with Bounds

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

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

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

the class Trees method main.

/**
 * Usage: java examples.Trees [# vertices]
 */
public static void main(String[] args) {
    if (args.length < 1)
        usage();
    try {
        final int n = Integer.parseInt(args[0]);
        final Trees model = new Trees();
        final Bounds b = model.bounds(n);
        final Solver solver = new Solver();
        solver.options().setSolver(SATFactory.MiniSat);
        solver.options().setBitwidth(16);
        // System.out.println(solver.solve(model.checkEquivOfTreeDefns(),
        // b));
        final Formula[] statements = new Formula[5];
        statements[0] = model.statement1();
        statements[1] = model.statement2();
        statements[2] = model.statement3();
        statements[3] = model.statement4();
        statements[4] = model.statement5();
        long time = 0;
        for (int i = 0; i < 5; i++) {
            Formula f = model.declsAndFacts().and(statements[i]).and(statements[(i + 1) % 5].not());
            Solution s = solver.solve(f, b);
            time += s.stats().translationTime() + s.stats().solvingTime();
            System.out.println(s);
            if (s.instance() != null) {
                return;
            }
        }
        System.out.println("valid: " + time + " ms");
    } catch (NumberFormatException nfe) {
        usage();
    } catch (HigherOrderDeclException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (UnboundLeafException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : Formula(kodkod.ast.Formula) Solver(kodkod.engine.Solver) UnboundLeafException(kodkod.engine.fol2sat.UnboundLeafException) Bounds(kodkod.instance.Bounds) HigherOrderDeclException(kodkod.engine.fol2sat.HigherOrderDeclException) Solution(kodkod.engine.Solution)

Example 69 with Bounds

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

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

the class Bigconfig method main.

/**
 * Usage: java tests.Bigconfig [# hq] [# sub] [# closure unwindings, 0 for true
 * closure] [size of partial instance, 0 default]
 *
 * @throws InterruptedException
 */
public static void main(String[] args) {
    if (args.length < 3)
        usage();
    final Bigconfig model = new Bigconfig(Integer.parseInt(args[2]));
    final Solver solver = new Solver();
    // solver.options().setSolver(SATFactory.ZChaffMincost);
    solver.options().setSolver(SATFactory.MiniSat);
    try {
        final int hq = Integer.parseInt(args[0]);
        final int sub = Integer.parseInt(args[1]);
        final int partial = args.length > 3 ? Integer.parseInt(args[3]) : 0;
        final Formula show = model.show();
        if (partial > 0) {
            Bounds bounds = model.bounds(hq, sub - partial, hq + sub);
            Solution sol = solver.solve(show, bounds);
            System.out.println("Solved for " + hq + " hq and " + (sub - partial) + " subs.");
            System.out.println(sol.outcome());
            System.out.println(sol.stats());
            System.out.println("Solving again with a partial instance: " + hq + " hq and " + sub + " subs.");
            bounds = model.bounds(hq, sub, bounds.universe());
            bounds.bound(model.link, sol.instance().tuples(model.link), bounds.upperBound(model.link));
            sol = solver.solve(show, bounds);
            System.out.println(sol.outcome());
            System.out.println(sol.stats());
        } else {
            solver.options().setReporter(new ConsoleReporter());
            final Bounds bounds = model.bounds(hq, sub, hq + sub);
            final Solution sol = solver.solve(show, bounds);
            System.out.println(sol.outcome());
            System.out.println(sol.stats());
        }
    } catch (NumberFormatException nfe) {
        usage();
    }
}
Also used : Formula(kodkod.ast.Formula) Solver(kodkod.engine.Solver) ConsoleReporter(kodkod.engine.config.ConsoleReporter) Bounds(kodkod.instance.Bounds) Solution(kodkod.engine.Solution)

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