Search in sources :

Example 91 with Bounds

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

the class GEO158 method bounds.

/**
 * Returns a bounds with the given number of maximum curves and points
 *
 * @return a bounds with the given number of maximum curves and points
 */
public Bounds bounds(int scope) {
    assert scope > 0;
    List<String> atoms = new ArrayList<String>(scope);
    for (int i = 0; i < scope; i++) atoms.add("c" + i);
    for (int i = 0; i < scope; i++) atoms.add("p" + i);
    final Universe u = new Universe(atoms);
    final TupleFactory f = u.factory();
    final Bounds b = new Bounds(u);
    final TupleSet c = f.range(f.tuple("c0"), f.tuple("c" + (scope - 1)));
    final TupleSet p = f.range(f.tuple("p0"), f.tuple("p" + (scope - 1)));
    final TupleSet cc = c.product(c), pc = p.product(c);
    b.bound(curve, c);
    b.bound(point, p);
    b.bound(partOf, cc);
    b.bound(incident, pc);
    b.bound(sum, c.product(cc));
    b.bound(endPoint, pc);
    b.bound(innerPoint, pc);
    b.bound(meet, pc.product(c));
    b.bound(closed, c);
    b.bound(open, c);
    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 92 with Bounds

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

the class GRA013_026 method main.

/**
 * Usage: java examples.tptp.GRA013_026 <graph size> <clique size>
 */
public static void main(String[] args) {
    if (args.length < 2)
        usage();
    try {
        final GRA013_026 model = new GRA013_026(Integer.parseInt(args[0]), Integer.parseInt(args[1]));
        final Bounds b = model.bounds();
        final Solver solver = new Solver();
        solver.options().setSolver(SATFactory.MiniSat);
        solver.options().setReporter(new ConsoleReporter());
        final Formula f = model.checkGoalToBeProved();
        System.out.println(PrettyPrinter.print(f, 2));
        // System.out.println(b);
        final Solution s = solver.solve(f, b);
        System.out.println(s);
    // System.out.println((new Evaluator(s.instance())).evaluate(f));
    } catch (HigherOrderDeclException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (UnboundLeafException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (NumberFormatException nfe) {
        usage();
    }
}
Also used : Formula(kodkod.ast.Formula) Solver(kodkod.engine.Solver) UnboundLeafException(kodkod.engine.fol2sat.UnboundLeafException) ConsoleReporter(kodkod.engine.config.ConsoleReporter) Bounds(kodkod.instance.Bounds) HigherOrderDeclException(kodkod.engine.fol2sat.HigherOrderDeclException) Solution(kodkod.engine.Solution)

Example 93 with Bounds

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

the class GRA013_026 method bounds.

/**
 * Returns the bounds.
 *
 * @return the bounds
 */
public final Bounds bounds() {
    final List<String> atoms = new ArrayList<String>(graphSize);
    for (int i = 1; i <= graphSize; i++) atoms.add("n" + i);
    atoms.add("goal");
    final Universe u = new Universe(atoms);
    final TupleFactory f = u.factory();
    final Bounds b = new Bounds(u);
    b.bound(goal, f.setOf("goal"));
    final TupleSet ns = f.range(f.tuple("n1"), f.tuple("n" + graphSize));
    b.boundExactly(node, ns);
    final TupleSet s = f.noneOf(2);
    for (int i = 1; i < graphSize; i++) {
        for (int j = i + 1; j < graphSize; j++) s.add(f.tuple("n" + i, "n" + j));
    }
    b.boundExactly(lessThan, s);
    b.bound(red, s);
    b.bound(green, s);
    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 94 with Bounds

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

the class AbstractWorldDefinitions method main.

/**
 * Usage: java examples.AbstractWorldDefinitions [A241 | AbOp_total |
 * AbIgnore_inv | AbTransfer_inv] [univ size]
 */
public static void main(String[] args) {
    if (args.length < 2)
        usage();
    try {
        final String assertion = args[0];
        final int n = Integer.parseInt(args[1]);
        if (n < 1)
            usage();
        final AbstractWorldDefinitions model = new AbstractWorldDefinitions();
        final Solver solver = new Solver();
        solver.options().setSolver(SATFactory.MiniSat);
        solver.options().setReporter(new ConsoleReporter());
        // solver.options().setFlatten(true);
        final Method method = model.getClass().getMethod(assertion);
        final Formula f = model.decls().and(((Formula) method.invoke(model)).not());
        final Bounds b = model.bounds(n);
        System.out.println(f);
        final Solution sol = solver.solve(f, b);
        System.out.println(sol);
    } catch (NumberFormatException nfe) {
        usage();
    } catch (SecurityException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        usage();
    } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : Solver(kodkod.engine.Solver) ConsoleReporter(kodkod.engine.config.ConsoleReporter) Bounds(kodkod.instance.Bounds) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) Formula(kodkod.ast.Formula) Solution(kodkod.engine.Solution)

Example 95 with Bounds

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

the class DNACuts method main.

/**
 * Usage: java examples.alloy.DNACuts [cut chain length] [# links]
 */
public static void main(String[] args) {
    if (args.length < 2)
        usage();
    try {
        final DNACuts model = new DNACuts(Integer.parseInt(args[0]));
        final Solver solver = new Solver();
        solver.options().setSolver(SATFactory.DefaultSAT4J);
        Formula f = model.show();
        Bounds b = model.bounds(Integer.parseInt(args[1]));
        System.out.println("solving...");
        Solution sol = solver.solve(f, b);
        // System.out.println(f);
        // System.out.println(b);
        System.out.println(sol.outcome());
        System.out.println(sol.stats());
    } catch (NumberFormatException nfe) {
        usage();
    }
}
Also used : Formula(kodkod.ast.Formula) Solver(kodkod.engine.Solver) 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