Java Code Examples for kodkod.engine.config.Options#integers()

The following examples show how to use kodkod.engine.config.Options#integers() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IntTest.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/**
 * Tests all comparison 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 testComparisonOps(IntExpression[] vals) {
    final Options options = solver.options();

    final IntRange range = options.integers();
    final int min = range.min(), max = range.max();

    for (int i = min; i <= max; i++) {
        IntExpression vi = vals[i - min];

        for (int j = min; j <= max; j++) {

            IntExpression vj = vals[j - min];

            testCompOp(EQ, vi, vj, i, j, i == j);
            testCompOp(LT, vi, vj, i, j, i < j);
            testCompOp(LTE, vi, vj, i, j, i <= j);
            testCompOp(GT, vi, vj, i, j, i > j);
            testCompOp(GTE, vi, vj, i, j, i >= j);

        }
    }

}
 
Example 2
Source File: IntTest.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 3
Source File: IntTest.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 4
Source File: IntTest.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
        }
    }

}
 
Example 5
Source File: IntTest.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
private final void test2sComplementUnOps(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());

    for (int i = min; i <= max; i++) {
        IntExpression vi = vals[i - min];
        testUnOp(IntOperator.NEG, vi, i, -i, mask);
        testUnOp(IntOperator.NOT, vi, i, ~i, mask);
        testUnOp(IntOperator.ABS, vi, i, Math.abs(i), mask);
        testUnOp(IntOperator.SGN, vi, i, i < 0 ? -1 : i > 0 ? 1 : 0, mask);
    }
}
 
Example 6
Source File: IntTest.java    From kodkod with MIT License 5 votes vote down vote up
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;
}
 
Example 7
Source File: IntTest.java    From kodkod with MIT License 5 votes vote down vote up
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;
}
 
Example 8
Source File: IntTest.java    From kodkod with MIT License 5 votes vote down vote up
/**
 * 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 int bw = options.bitwidth();
	final IntRange range = options.integers();
	final int min = range.min(), max = range.max();
	final int mask = ~(-1 << bw);
	
	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);
			
			final int shrmask = ~(-1 << (bw - ((j < 0 || j > bw) ? bw : j)));
			testBinOp(SHL, vi, vj, i, j, i << j, mask);				
			testBinOp(SHR, vi, vj, i, j, shrmask & (i >> j), mask);
			testBinOp(SHA, vi, vj, i, j, i >> j, mask);
		}
	}
	
}
 
Example 9
Source File: IntTest.java    From kodkod with MIT License 5 votes vote down vote up
private final void test2sComplementUnOps(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());
	
	for(int i = min; i <= max; i++) {
		IntExpression vi = vals[i-min];
		testUnOp(IntOperator.NEG, vi, i, -i, mask);
		testUnOp(IntOperator.NOT, vi, i, ~i, mask);
		testUnOp(IntOperator.ABS, vi, i, Math.abs(i), mask);
		testUnOp(IntOperator.SGN, vi, i, i < 0 ? -1 : i > 0 ? 1 : 0, mask);
	}		
}
 
Example 10
Source File: IntTest.java    From kodkod with MIT License 4 votes vote down vote up
/**
 * Tests all comparison 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 testComparisonOps(IntExpression[] vals) {
	final Options options = solver.options();
	
	final IntRange range = options.integers();
	final int min = range.min(), max = range.max();
	
	for(int i = min; i <= max; i++) {
			IntExpression vi = vals[i-min];
		
			
		for(int j = min; j <= max; j++) {
			
			IntExpression vj = vals[j-min];
		
			testCompOp(EQ, vi, vj, i, j, i==j);
			testCompOp(LT, vi, vj, i, j, i<j);
			testCompOp(LTE, vi, vj, i, j, i<=j);
			testCompOp(GT, vi, vj, i, j, i>j);
			testCompOp(GTE, vi, vj, i, j, i>=j);
			
		}
	}
	
}