本文整理汇总了Java中kodkod.ast.IntConstant类的典型用法代码示例。如果您正苦于以下问题:Java IntConstant类的具体用法?Java IntConstant怎么用?Java IntConstant使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IntConstant类属于kodkod.ast包,在下文中一共展示了IntConstant类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: formula
import kodkod.ast.IntConstant; //导入依赖的package包/类
/**
* Returns the formula a1 <= v1 <= a2 <= v2 .... a1000<=v1000
*
* @return the formula
*/
public final Formula formula() {
final List<Formula> constraints = new ArrayList<Formula>(2000);
final List<IntConstant> constants = new ArrayList<IntConstant>(1001);
for (int i = low; i <= high; i += 10) {
constants.add(IntConstant.constant(i));
}
for (int i = 0; i < 1000; i++) {
IntExpression varExpr = var[i].sum(); // convert to primitive int
constraints.add(constants.get(i).lte(varExpr)); // a_i <= v_i
constraints.add(varExpr.lte(constants.get(i + 1))); // v_i <=
// a_(i+1)
}
return Formula.and(constraints);
}
开发者ID:AlloyTools,项目名称:org.alloytools.alloy,代码行数:22,代码来源:IntConstraints.java
示例2: testTranslateProjection
import kodkod.ast.IntConstant; //导入依赖的package包/类
public final void testTranslateProjection() {
assertTrue(isSatisfiable(
r3[0].eq(r2[0].project(IntConstant.constant(0), IntConstant.constant(1), IntConstant.constant(0)))));
assertTrue(isSatisfiable(r2[1].in(r3[0].project(r1[3].count(), r1[2].count()))));
final Variable v = Variable.nary("r", 2);
assertFalse(isSatisfiable(
v.transpose().eq(v.project(IntConstant.constant(1), IntConstant.constant(0))).not().forSome(
v.setOf(r2[0]))));
bounds.boundExactly(r3[0], bounds.upperBound(r3[0]));
bounds.boundExactly(r2[0], bounds.upperBound(r2[0]));
assertTrue(isSatisfiable(r3[0].project(IntConstant.constant(0), IntConstant.constant(1)).eq(r2[0])));
assertTrue(
isSatisfiable(r3[0].project(IntConstant.constant(0), IntConstant.constant(4), IntConstant.constant(2))
.eq(Expression.NONE.product(Expression.NONE).product(Expression.NONE))));
assertTrue(
isSatisfiable(r3[0].project(IntConstant.constant(0), IntConstant.constant(-1), IntConstant.constant(2))
.eq(Expression.NONE.product(Expression.NONE).product(Expression.NONE))));
}
开发者ID:AlloyTools,项目名称:org.alloytools.alloy,代码行数:25,代码来源:TranslatorTest.java
示例3: testIntSum
import kodkod.ast.IntConstant; //导入依赖的package包/类
private void testIntSum(Options.IntEncoding encoding) {
solver.options().setIntEncoding(encoding);
final Variable x = Variable.unary("x");
bounds.bound(r1, factory.setOf("13", "14", "15"), factory.setOf("13", "14", "15"));
Formula f = IntConstant.constant(3).eq(IntConstant.constant(1).sum(x.oneOf(r1)));
Solution s = solve(f);
assertNotNull(s.instance());
bounds.bound(r1, factory.noneOf(1), factory.setOf("1", "3", "5"));
bounds.boundExactly(1, factory.setOf("1"));
bounds.boundExactly(3, factory.setOf("3"));
bounds.boundExactly(5, factory.setOf("5"));
f = IntConstant.constant(9).eq(x.sum().sum(x.oneOf(r1)));
s = solve(f);
assertNotNull(s.instance());
assertEquals(s.instance().tuples(r1), factory.setOf("1", "3", "5"));
}
开发者ID:AlloyTools,项目名称:org.alloytools.alloy,代码行数:19,代码来源:IntTest.java
示例4: testBasic
import kodkod.ast.IntConstant; //导入依赖的package包/类
@Test
public void testBasic() {
Options opt = new Options();
opt.setNoOverflow(true);
opt.setBitwidth(2);
IncrementalSolver solver = IncrementalSolver.solver(opt);
Universe univ = new Universe("-2", "-1", "0", "1");
Bounds b = new Bounds(univ);
TupleFactory factory = univ.factory();
b.boundExactly(-2, factory.range(factory.tuple("-2"), factory.tuple("-2")));
b.boundExactly(-1, factory.range(factory.tuple("-1"), factory.tuple("-1")));
b.boundExactly(0, factory.range(factory.tuple("0"), factory.tuple("0")));
b.boundExactly(1, factory.range(factory.tuple("1"), factory.tuple("1")));
Variable n = Variable.unary("n");
Formula f = n.sum().plus(IntConstant.constant(1)).lte(n.sum()).forSome(n.oneOf(Expression.INTS));
Solution sol = solver.solve(f, b);
assertNoInstance(sol);
}
开发者ID:AlloyTools,项目名称:org.alloytools.alloy,代码行数:19,代码来源:IncrementalOverflowNumTest.java
示例5: visit
import kodkod.ast.IntConstant; //导入依赖的package包/类
/** {@inheritDoc} */
@Override public Object visit(ExprConstant x) throws Err {
switch(x.op) {
case MIN: return IntConstant.constant(min); //TODO
case MAX: return IntConstant.constant(max); //TODO
case NEXT: return A4Solution.KK_NEXT;
case TRUE: return Formula.TRUE;
case FALSE: return Formula.FALSE;
case EMPTYNESS: return Expression.NONE;
case IDEN: return Expression.IDEN.intersection(a2k(UNIV).product(Expression.UNIV));
case STRING:
Expression ans = s2k(x.string);
if (ans==null) throw new ErrorFatal(x.pos, "String literal "+x+" does not exist in this instance.\n");
return ans;
case NUMBER:
int n=x.num();
//[am] const
// if (n<min) throw new ErrorType(x.pos, "Current bitwidth is set to "+bitwidth+", thus this integer constant "+n+" is smaller than the minimum integer "+min);
// if (n>max) throw new ErrorType(x.pos, "Current bitwidth is set to "+bitwidth+", thus this integer constant "+n+" is bigger than the maximum integer "+max);
return IntConstant.constant(n).toExpression();
}
throw new ErrorFatal(x.pos, "Unsupported operator ("+x.op+") encountered during ExprConstant.accept()");
}
开发者ID:ModelWriter,项目名称:Tarski,代码行数:24,代码来源:TranslateAlloyToKodkod.java
示例6: Transpose4x4UnaryL
import kodkod.ast.IntConstant; //导入依赖的package包/类
public Transpose4x4UnaryL() {
for(int i = 0; i < 4; i++) {
mx1[i] = Relation.unary("mx1[" + i + "]");
mx2[i] = Relation.unary("mx2[" + i + "]");
sx1[i] = Relation.unary("sx1[" + i + "]");
sx2[i] = Relation.unary("sx2[" + i + "]");
for(int j = 0; j < 4; j++) {
mi[i][j] = Relation.unary("mi[" + i + ", " + j + "]");
si[i][j] = Relation.unary("si[" + i + ", " + j + "]");
}
}
this.succ = Relation.binary("succ");
for(int i = 0; i < 16; i++) {
ints[i] = IntConstant.constant(i).toExpression();
}
}
开发者ID:emina,项目名称:kodkod,代码行数:18,代码来源:Transpose4x4UnaryL.java
示例7: Transpose4x4UnaryLR
import kodkod.ast.IntConstant; //导入依赖的package包/类
public Transpose4x4UnaryLR() {
for(int i = 0; i < 4; i++) {
sl[i] = Relation.unary("sl[" + i + "]");
tl[i] = Relation.unary("tl[" + i + "]");
mx1[i] = Relation.unary("mx1[" + i + "]");
mx2[i] = Relation.unary("mx2[" + i + "]");
sx1[i] = Relation.unary("sx1[" + i + "]");
sx2[i] = Relation.unary("sx2[" + i + "]");
for(int j = 0; j < 4; j++) {
mi[i][j] = Relation.unary("mi[" + i + ", " + j + "]");
si[i][j] = Relation.unary("si[" + i + ", " + j + "]");
}
}
this.idx = Relation.unary("idx");
this.succ = Relation.binary("succ");
for(int i = 0; i <= 16; i++) {
ints[i] = IntConstant.constant(i).toExpression();
}
}
开发者ID:emina,项目名称:kodkod,代码行数:24,代码来源:Transpose4x4UnaryLR.java
示例8: print
import kodkod.ast.IntConstant; //导入依赖的package包/类
/**
* Prints the given solution using the given options to the console
*/
void print(Instance instance, Options options) {
final Evaluator eval = new Evaluator(instance, options);
final int n = instance.universe().size();
for(int i = 0; i < n; i++) {
Expression x = IntConstant.constant(i).toExpression();
for(int j = 0; j < n; j++) {
Expression y = IntConstant.constant(j).toExpression();
if (eval.evaluate(x.product(y).in(queen))) {
System.out.print(" Q");
} else {
System.out.print(" .");
}
}
System.out.println();
}
// System.out.println(instance);
}
开发者ID:emina,项目名称:kodkod,代码行数:21,代码来源:BlockedNQueens2.java
示例9: print
import kodkod.ast.IntConstant; //导入依赖的package包/类
/**
* Prints the given solution using the given options to the console
*/
void print(Instance instance, Options options) {
final Evaluator eval = new Evaluator(instance, options);
final int n = instance.tuples(queen).size();
for(int i = 0; i < n; i++) {
Expression ci = IntConstant.constant(i).toExpression();
for(int j = 0; j < n; j++) {
Expression cj = IntConstant.constant(j).toExpression();
if (eval.evaluate(x.join(ci).intersection(y.join(cj)).some())) {
System.out.print(" Q");
} else {
System.out.print(" .");
}
}
System.out.println();
}
// System.out.println(instance);
}
开发者ID:emina,项目名称:kodkod,代码行数:21,代码来源:BlockedNQueens.java
示例10: print
import kodkod.ast.IntConstant; //导入依赖的package包/类
/**
* Prints the given solution
*/
void print(Instance instance, Options options) {
final Evaluator eval = new Evaluator(instance, options);
for(int i = 0; i < n; i++) {
Expression ci = IntConstant.constant(i).toExpression();
for(int j = 0; j < n; j++) {
Expression cj = IntConstant.constant(j).toExpression();
if (eval.evaluate(x.join(ci).intersection(y.join(cj)).some())) {
System.out.print(" Q");
} else {
System.out.print(" .");
}
}
System.out.println();
}
// System.out.println(instance);
}
开发者ID:emina,项目名称:kodkod,代码行数:20,代码来源:NQueens.java
示例11: testTranslateProjection
import kodkod.ast.IntConstant; //导入依赖的package包/类
@Test
public final void testTranslateProjection() {
assertTrue(isSatisfiable(r3[0].eq(
r2[0].project(IntConstant.constant(0), IntConstant.constant(1), IntConstant.constant(0)))));
assertTrue(isSatisfiable(r2[1].in(r3[0].project(r1[3].count(), r1[2].count()))));
final Variable v = Variable.nary("r", 2);
assertFalse(isSatisfiable(v.transpose().
eq(v.project(IntConstant.constant(1), IntConstant.constant(0))).not().
forSome(v.setOf(r2[0]))));
bounds.boundExactly(r3[0], bounds.upperBound(r3[0]));
bounds.boundExactly(r2[0], bounds.upperBound(r2[0]));
assertTrue(isSatisfiable(r3[0].project(IntConstant.constant(0), IntConstant.constant(1)).eq(r2[0])));
assertTrue(isSatisfiable(r3[0].project(IntConstant.constant(0), IntConstant.constant(4), IntConstant.constant(2)).
eq(Expression.NONE.product(Expression.NONE).product(Expression.NONE))));
assertTrue(isSatisfiable(r3[0].project(IntConstant.constant(0), IntConstant.constant(-1), IntConstant.constant(2)).
eq(Expression.NONE.product(Expression.NONE).product(Expression.NONE))));
}
开发者ID:emina,项目名称:kodkod,代码行数:24,代码来源:TranslatorTest.java
示例12: testExtremeShifts
import kodkod.ast.IntConstant; //导入依赖的package包/类
@Test
public final void testExtremeShifts() {
final int bw = 32;
solver.options().setBitwidth(bw);
final IntRange range = solver.options().integers();
final int mask = ~(-1 << bw);
final IntConstant min = IntConstant.constant(range.min());
final IntConstant max = IntConstant.constant(range.max());
testBinOp(SHL, min, min, min.value(), min.value(), 0, mask);
testBinOp(SHL, min, max, min.value(), max.value(), 0, mask);
testBinOp(SHL, max, min, max.value(), min.value(), 0, mask);
testBinOp(SHL, max, max, max.value(), max.value(), 0, mask);
testBinOp(SHA, min, min, min.value(), min.value(), -1, mask);
testBinOp(SHA, min, max, min.value(), max.value(), -1, mask);
testBinOp(SHA, max, min, max.value(), min.value(), 0, mask);
testBinOp(SHA, max, max, max.value(), max.value(), 0, mask);
testBinOp(SHR, min, min, min.value(), min.value(), 0, mask);
testBinOp(SHR, min, max, min.value(), max.value(), 0, mask);
testBinOp(SHR, max, min, max.value(), min.value(), 0, mask);
testBinOp(SHR, max, max, max.value(), max.value(), 0, mask);
}
开发者ID:emina,项目名称:kodkod,代码行数:22,代码来源:IntTest.java
示例13: testIntSum
import kodkod.ast.IntConstant; //导入依赖的package包/类
private void testIntSum(Options.IntEncoding encoding) {
solver.options().setIntEncoding(encoding);
final Variable x = Variable.unary("x");
bounds.bound(r1, factory.setOf("13","14","15"), factory.setOf("13","14","15"));
Formula f = IntConstant.constant(3).eq(IntConstant.constant(1).sum(x.oneOf(r1)));
Solution s = solve(f);
assertNotNull(s.instance());
bounds.bound(r1, factory.noneOf(1), factory.setOf("1","3","5"));
bounds.boundExactly(1, factory.setOf("1"));
bounds.boundExactly(3, factory.setOf("3"));
bounds.boundExactly(5, factory.setOf("5"));
f = IntConstant.constant(9).eq(x.sum().sum(x.oneOf(r1)));
s = solve(f);
assertNotNull(s.instance());
assertEquals(s.instance().tuples(r1), factory.setOf("1","3","5"));
}
开发者ID:emina,项目名称:kodkod,代码行数:19,代码来源:IntTest.java
示例14: getAtomExpr
import kodkod.ast.IntConstant; //导入依赖的package包/类
public static Expression getAtomExpr(Object atom, Map<Object,Relation> atom2rel) {
if (atom instanceof Integer)
return IntConstant.constant((Integer) atom).toExpression();
if (atom instanceof String) {
try {
return IntConstant.constant(Integer.parseInt(atom.toString())).toExpression();
} catch (NumberFormatException e) {}
}
Relation rel = atom2rel != null ? atom2rel.get(atom) : null;
return rel;
}
开发者ID:AlloyTools,项目名称:org.alloytools.alloy,代码行数:12,代码来源:Bounds.java
示例15: edge
import kodkod.ast.IntConstant; //导入依赖的package包/类
private void edge(Node n1, Node n2) {
if (n2 instanceof LeafExpression || n2 instanceof ConstantFormula || n2 instanceof IntConstant) {
}
graph.append(id(n1));
graph.append("->");
graph.append(id(n2));
graph.append(";\n");
}
开发者ID:AlloyTools,项目名称:org.alloytools.alloy,代码行数:10,代码来源:PrettyPrinter.java
示例16: conditionalSum
import kodkod.ast.IntConstant; //导入依赖的package包/类
/**
* Returns the sum of the elements in x (conditional on the non-emptiness of
* a given a[i]) located at indices [lo..hi]
*
* @return the sum of cardinalities of the elements in x (conditional on the
* non-emptiness of a given a[i]) located at indices [lo..hi]
*/
private static IntExpression conditionalSum(Expression[] a, Expression[] x, int lo, int hi) {
if (lo > hi)
return IntConstant.constant(0);
else if (lo == hi)
return a[lo].some().thenElse(x[lo].sum(), IntConstant.constant(0));
else {
final int mid = (lo + hi) / 2;
final IntExpression lsum = conditionalSum(a, x, lo, mid);
final IntExpression hsum = conditionalSum(a, x, mid + 1, hi);
return lsum.plus(hsum);
}
}
开发者ID:AlloyTools,项目名称:org.alloytools.alloy,代码行数:20,代码来源:Viktor.java
示例17: equations
import kodkod.ast.IntConstant; //导入依赖的package包/类
/**
* Returns the equations to be satisfied.
*
* @return equations to be satisfied.
*/
public final Formula equations() {
// each b <= cols-1
Formula f0 = Formula.TRUE;
final IntConstant colConst = IntConstant.constant(cols - 1);
for (IntExpression bi : b) {
f0 = f0.and(bi.lte(colConst));
}
final Variable[] y = new Variable[rows];
for (int i = 0; i < rows; i++) {
y[i] = Variable.unary("y" + i);
}
Decls decls = y[0].oneOf(INTS);
for (int i = 1; i < rows; i++)
decls = decls.and(y[i].oneOf(INTS));
Formula f1 = Formula.TRUE;
final Expression[] combo = new Expression[rows];
for (int i = 0; i < cols; i++) {
for (int j = i + 1; j < cols; j++) {
for (int k = j + 1; k < cols; k++) {
Formula f2 = Formula.TRUE;
for (int m = 0; m < rows; m++) {
combo[0] = a[m][i];
combo[1] = a[m][j];
combo[2] = a[m][k];
f2 = f2.and(conditionalSum(combo, y, 0, rows - 1).eq(b[m]));
}
f1 = f1.and(f2.not().forAll(decls));
}
}
}
return f0.and(f1);
}
开发者ID:AlloyTools,项目名称:org.alloytools.alloy,代码行数:42,代码来源:Viktor.java
示例18: solveAll
import kodkod.ast.IntConstant; //导入依赖的package包/类
@Override
protected Iterator<Solution> solveAll(final Formula formula) {
final IncrementalSolver solver = IncrementalSolver.solver(options);
return new Iterator<Solution>() {
Solution sol;
@Override
public boolean hasNext() {
return sol == null || sol.sat();
}
@Override
public Solution next() {
if (sol == null) {
sol = solver.solve(formula, bounds);
} else {
Evaluator ev = new Evaluator(sol.instance());
int a = evalInt(ev, op1);
int b = evalInt(ev, op2);
int r = evalInt(ev, ret);
Formula f = op1.eq(IntConstant.constant(a).toExpression())
.and(op2.eq(IntConstant.constant(b).toExpression()))
.and(ret.eq(IntConstant.constant(r).toExpression()))
.not();
sol = solver.solve(f, new Bounds(factory.universe()));
}
return sol;
}
@Override
public void remove() {
throw new RuntimeException("Not supported");
}
};
}
开发者ID:AlloyTools,项目名称:org.alloytools.alloy,代码行数:37,代码来源:IncrementalOverflowEnumTest.java
示例19: testFelix_01032007
import kodkod.ast.IntConstant; //导入依赖的package包/类
public final void testFelix_01032007() {
List<String> atomlist = Arrays.asList("-1", "-2", "-3", "-4", "-5", "-6", "-7", "-8", "0", "1", "2", "3", "4",
"5", "6", "7");
Universe universe = new Universe(atomlist);
TupleFactory factory = universe.factory();
Bounds bounds = new Bounds(universe);
bounds.boundExactly(-8, factory.range(factory.tuple("-8"), factory.tuple("-8")));
bounds.boundExactly(-7, factory.range(factory.tuple("-7"), factory.tuple("-7")));
bounds.boundExactly(-6, factory.range(factory.tuple("-6"), factory.tuple("-6")));
bounds.boundExactly(-5, factory.range(factory.tuple("-5"), factory.tuple("-5")));
bounds.boundExactly(-4, factory.range(factory.tuple("-4"), factory.tuple("-4")));
bounds.boundExactly(-3, factory.range(factory.tuple("-3"), factory.tuple("-3")));
bounds.boundExactly(-2, factory.range(factory.tuple("-2"), factory.tuple("-2")));
bounds.boundExactly(-1, factory.range(factory.tuple("-1"), factory.tuple("-1")));
bounds.boundExactly(0, factory.range(factory.tuple("0"), factory.tuple("0")));
bounds.boundExactly(1, factory.range(factory.tuple("1"), factory.tuple("1")));
bounds.boundExactly(2, factory.range(factory.tuple("2"), factory.tuple("2")));
bounds.boundExactly(3, factory.range(factory.tuple("3"), factory.tuple("3")));
bounds.boundExactly(4, factory.range(factory.tuple("4"), factory.tuple("4")));
bounds.boundExactly(5, factory.range(factory.tuple("5"), factory.tuple("5")));
bounds.boundExactly(6, factory.range(factory.tuple("6"), factory.tuple("6")));
bounds.boundExactly(7, factory.range(factory.tuple("7"), factory.tuple("7")));
Expression set = IntConstant.constant(8).toExpression();
Solver solver = new Solver();
solver.options().setSolver(SATFactory.DefaultSAT4J);
solver.options().setBitwidth(4);
solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT);
Solution sol = solver.solve(set.some(), bounds);
assertNotNull("expected SATISFIABLE but was " + sol.outcome(), sol.instance());
Evaluator eval = new Evaluator(sol.instance(), solver.options());
TupleSet ts = eval.evaluate(set);
assertFalse(ts.size() == 0);
}
开发者ID:AlloyTools,项目名称:org.alloytools.alloy,代码行数:41,代码来源:BugTests.java
示例20: exeKodkodDef
import kodkod.ast.IntConstant; //导入依赖的package包/类
protected int exeKodkodDef(int i, int j) {
IntExpression kkIntExpr = kodkodOpExpr(IntConstant.constant(i), IntConstant.constant(j));
Expression kkExpr = kkIntExpr.toExpression();
Formula f = ret
.eq(kkExpr.some().thenElse(kkIntExpr.toExpression(), IntConstant.constant(DEF_VAL).toExpression()));
Solution sol = solve(f);
return eval(sol.instance());
}
开发者ID:AlloyTools,项目名称:org.alloytools.alloy,代码行数:9,代码来源:OverflowNumTest.java
注:本文中的kodkod.ast.IntConstant类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论