Search in sources :

Example 11 with Options

use of kodkod.engine.config.Options in project org.alloytools.alloy by AlloyTools.

the class IntTest method test2sComplementBinOps.

/**
 * Tests all binary ops for this.solver.options and range of vals.
 *
 * @requires this.solver.options.intEncoding = binary
 * @requires vals contains int expressions that represent all integers allowed
 *           by this.solver.options, in proper sequence
 */
private final void test2sComplementBinOps(IntExpression[] vals) {
    final Options options = solver.options();
    final IntRange range = options.integers();
    final int min = range.min(), max = range.max();
    final int mask = ~(-1 << options.bitwidth());
    final int shiftmask = ~(-1 << (32 - Integer.numberOfLeadingZeros(options.bitwidth() - 1)));
    for (int i = min; i <= max; i++) {
        IntExpression vi = vals[i - min];
        for (int j = min; j <= max; j++) {
            IntExpression vj = vals[j - min];
            testBinOp(PLUS, vi, vj, i, j, i + j, mask);
            testBinOp(MINUS, vi, vj, i, j, i - j, mask);
            testBinOp(MULTIPLY, vi, vj, i, j, i * j, mask);
            if (j != 0) {
                testBinOp(DIVIDE, vi, vj, i, j, i / j, mask);
                testBinOp(MODULO, vi, vj, i, j, i % j, mask);
            }
            testBinOp(AND, vi, vj, i, j, i & j, mask);
            testBinOp(OR, vi, vj, i, j, i | j, mask);
            testBinOp(XOR, vi, vj, i, j, i ^ j, mask);
            testBinOp(SHL, vi, vj, i, j, i << (j & shiftmask), i << j, mask);
            testBinOp(SHR, vi, vj, i, j, (i & mask) >>> (j & shiftmask), mask);
            testBinOp(SHA, vi, vj, i, j, i >> (j & shiftmask), mask);
        }
    }
}
Also used : Options(kodkod.engine.config.Options) IntExpression(kodkod.ast.IntExpression) IntRange(kodkod.util.ints.IntRange)

Example 12 with Options

use of kodkod.engine.config.Options in project org.alloytools.alloy by AlloyTools.

the class IntTest method nonConstants.

private IntExpression[] nonConstants() {
    final Options options = solver.options();
    final IntRange range = options.integers();
    final int min = range.min(), max = range.max();
    final int size = range.size();
    final Relation[] r = new Relation[size];
    final TupleFactory f = bounds.universe().factory();
    for (int i = 0; i < size; i++) {
        int arity = i % 3 + 1;
        r[i] = Relation.nary("r" + i, arity);
        TupleSet b = f.noneOf(arity);
        for (int j = (i / 3) * ((int) Math.pow(SIZE, arity - 1)), jmax = j + size; j < jmax; j++) {
            b.add(f.tuple(arity, j % b.capacity()));
        }
        bounds.bound(r[i], b);
    }
    final IntExpression[] vals = new IntExpression[max - min + 1];
    for (int i = 0; i < size; i++) {
        vals[i] = i + min < 0 ? r[i].count().negate() : r[i].count();
    }
    return vals;
}
Also used : Options(kodkod.engine.config.Options) TupleSet(kodkod.instance.TupleSet) Relation(kodkod.ast.Relation) IntExpression(kodkod.ast.IntExpression) IntRange(kodkod.util.ints.IntRange) TupleFactory(kodkod.instance.TupleFactory)

Example 13 with Options

use of kodkod.engine.config.Options in project org.alloytools.alloy by AlloyTools.

the class IntTest method constants.

private IntExpression[] constants() {
    final Options options = solver.options();
    final IntRange range = options.integers();
    final int min = range.min(), max = range.max();
    final IntExpression[] vals = new IntExpression[max - min + 1];
    for (int i = min; i <= max; i++) {
        vals[i - min] = constant(i);
    }
    return vals;
}
Also used : Options(kodkod.engine.config.Options) IntExpression(kodkod.ast.IntExpression) IntRange(kodkod.util.ints.IntRange)

Aggregations

Options (kodkod.engine.config.Options)13 IntExpression (kodkod.ast.IntExpression)5 IntRange (kodkod.util.ints.IntRange)5 Relation (kodkod.ast.Relation)3 Bounds (kodkod.instance.Bounds)3 Formula (kodkod.ast.Formula)2 Solution (kodkod.engine.Solution)2 TupleFactory (kodkod.instance.TupleFactory)2 LinkedHashSet (java.util.LinkedHashSet)1 Variable (kodkod.ast.Variable)1 IncrementalSolver (kodkod.engine.IncrementalSolver)1 Solver (kodkod.engine.Solver)1 BooleanFormula (kodkod.engine.bool.BooleanFormula)1 BooleanValue (kodkod.engine.bool.BooleanValue)1 HOLTranslation (kodkod.engine.hol.HOLTranslation)1 TupleSet (kodkod.instance.TupleSet)1 Universe (kodkod.instance.Universe)1 Test (org.junit.Test)1