本文整理汇总了Java中kodkod.ast.Expression.NONE属性的典型用法代码示例。如果您正苦于以下问题:Java Expression.NONE属性的具体用法?Java Expression.NONE怎么用?Java Expression.NONE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类kodkod.ast.Expression
的用法示例。
在下文中一共展示了Expression.NONE属性的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: interpret
/**
* Returns a {@link kodkod.engine.bool.BooleanMatrix matrix} m of
* {@link kodkod.engine.bool.BooleanValue boolean formulas} representing the
* specified constant expression.
*
* @return { m: BooleanMatrix | let dset = [0..this.universe.size()^c.arity)
* | m.dimensions.dimensions = [0..c.arity) ->one
* this.universe.size() && c = UNIV => m.elements[dset] = TRUE, c =
* NONE => m.elements[dset] = FALSE, c = IDEN => (all i: dset |
* (some j: int | i = j*(1+this.universe.size())) => m.elements[i] =
* TRUE, m.elements[i] = FALSE), c = INT => (all i: dset | (some j:
* int | this.interpret(j)=i) => m.elements[i] = TRUE, m.elements[i]
* = FALSE }
*/
public final BooleanMatrix interpret(ConstantExpression c) {
final int univSize = universe().size();
if (c == Expression.UNIV) {
final IntSet all = Ints.rangeSet(Ints.range(0, univSize - 1));
return factory().matrix(Dimensions.square(univSize, 1), all, all);
} else if (c == Expression.IDEN) {
final Dimensions dim2 = Dimensions.square(univSize, 2);
final IntSet iden = Ints.bestSet(dim2.capacity());
for (int i = 0; i < univSize; i++) {
iden.add(i * univSize + i);
}
return factory().matrix(dim2, iden, iden);
} else if (c == Expression.NONE) {
return factory().matrix(Dimensions.square(univSize, 1), Ints.EMPTY_SET, Ints.EMPTY_SET);
} else if (c == Expression.INTS) {
final IntSet ints = Ints.bestSet(univSize);
for (IntIterator iter = ints().iterator(); iter.hasNext();) {
ints.add(interpret(iter.next()));
}
return factory().matrix(Dimensions.square(univSize, 1), ints, ints);
} else {
throw new IllegalArgumentException("unknown constant expression: " + c);
}
}
示例2: visit
/** {@inheritDoc} */
public void visit(ConstantExpression x) {
if (map.containsKey(x))
return;
String newname = null;
if (x == Expression.NONE)
newname = "Expression.NONE";
else if (x == Expression.UNIV)
newname = "Expression.UNIV";
else if (x == Expression.IDEN)
newname = "Expression.IDEN";
else if (x == Expression.INTS)
newname = "Expression.INTS";
else
throw new RuntimeException("Unknown kodkod ConstantExpression \"" + x + "\" encountered");
map.put(x, newname);
}
示例3: a2k
/** Returns the corresponding Kodkod expression for the given expression, or null if it is not associated with anything. */
Expression a2k(Expr expr) throws ErrorFatal {
while(expr instanceof ExprUnary) {
if (((ExprUnary)expr).op==ExprUnary.Op.NOOP) { expr = ((ExprUnary)expr).sub; continue; }
if (((ExprUnary)expr).op==ExprUnary.Op.EXACTLYOF) { expr = ((ExprUnary)expr).sub; continue; }
break;
}
if (expr instanceof ExprConstant && ((ExprConstant)expr).op==ExprConstant.Op.EMPTYNESS) return Expression.NONE;
if (expr instanceof ExprConstant && ((ExprConstant)expr).op==ExprConstant.Op.STRING) return s2k.get(((ExprConstant)expr).string);
if (expr instanceof Sig || expr instanceof Field || expr instanceof ExprVar) return a2k.get(expr);
if (expr instanceof ExprBinary) {
Expr a=((ExprBinary)expr).left, b=((ExprBinary)expr).right;
switch(((ExprBinary)expr).op) {
case ARROW: return a2k(a).product(a2k(b));
case PLUS: return a2k(a).union(a2k(b));
case MINUS: return a2k(a).difference(a2k(b));
//TODO: IPLUS, IMINUS???
}
}
return null; // Current only UNION, PRODUCT, and DIFFERENCE of Sigs and Fields and ExprConstant.EMPTYNESS are allowed in a defined field's definition.
}
示例4: allocateSubsetSig
/** Allocate relations for SubsetSig top-down. */
private Expression allocateSubsetSig(SubsetSig sig) throws Err {
// We must not visit the same SubsetSig more than once, so if we've been here already, then return the old value right away
Expression sum = sol.a2k(sig);
if (sum!=null && sum!=Expression.NONE) return sum;
// Recursively form the union of all parent expressions
TupleSet ts = factory.noneOf(1);
for(Sig parent:sig.parents) {
Expression p = (parent instanceof PrimSig) ? sol.a2k(parent) : allocateSubsetSig((SubsetSig)parent);
ts.addAll(sol.query(true, p, false));
if (sum==null) sum=p; else sum=sum.union(p);
}
// If subset is exact, then just use the "sum" as is
if (sig.exact) { sol.addSig(sig, sum); return sum; }
// Allocate a relation for this subset sig, then bound it
rep.bound("Sig "+sig+" in "+ts+"\n");
Relation r = sol.addRel(sig.label, null, ts);
sol.addSig(sig, r);
// Add a constraint that it is INDEED a subset of the union of its parents
sol.addFormula(r.in(sum), sig.isSubset);
return r;
}
示例5: visit
/** {@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()");
}
示例6: interpret
/**
* Returns a {@link kodkod.engine.bool.BooleanMatrix matrix} m of
* {@link kodkod.engine.bool.BooleanValue boolean formulas} representing
* the specified constant expression.
* @return { m: BooleanMatrix | let dset = [0..this.universe.size()^c.arity) |
* m.dimensions.dimensions = [0..c.arity) ->one this.universe.size() &&
* c = UNIV => m.elements[dset] = TRUE, c = NONE => m.elements[dset] = FALSE,
* c = IDEN => (all i: dset | (some j: int | i = j*(1+this.universe.size())) => m.elements[i] = TRUE, m.elements[i] = FALSE),
* c = INT => (all i: dset | (some j: int | this.interpret(j)=i) => m.elements[i] = TRUE, m.elements[i] = FALSE }
*/
public final BooleanMatrix interpret(ConstantExpression c) {
final int univSize = universe().size();
if (c==Expression.UNIV) {
final IntSet all = Ints.rangeSet(Ints.range(0, univSize-1));
return factory().matrix(Dimensions.square(univSize, 1), all, all);
} else if (c==Expression.IDEN) {
final Dimensions dim2 = Dimensions.square(univSize, 2);
final IntSet iden = Ints.bestSet(dim2.capacity());
for(int i = 0; i < univSize; i++) {
iden.add(i*univSize + i);
}
return factory().matrix(dim2, iden, iden);
} else if (c==Expression.NONE) {
return factory().matrix(Dimensions.square(univSize, 1), Ints.EMPTY_SET, Ints.EMPTY_SET);
} else if (c==Expression.INTS) {
final IntSet ints = Ints.bestSet(univSize);
for(IntIterator iter = ints().iterator(); iter.hasNext(); ) {
ints.add(interpret(iter.next()));
}
return factory().matrix(Dimensions.square(univSize, 1), ints, ints);
} else {
throw new IllegalArgumentException("unknown constant expression: " + c);
}
}
示例7: ts2expr
public Expression ts2expr(TupleSet tset) {
if (tset == null)
return Expression.NONE;
Expression tsetExpr = null;
for (Tuple t : tset) {
Expression tupleExpr = null;
for (int i = 0; i < t.arity(); i++) {
Expression atomRel = ensureAtomExpr(t.atom(i));
tupleExpr = tupleExpr == null ? atomRel : tupleExpr.product(atomRel);
}
tsetExpr = tsetExpr == null ? tupleExpr : tsetExpr.union(tupleExpr);
}
return (tsetExpr == null) ? Expression.NONE : tsetExpr;
}
示例8: a2k
/**
* Returns the corresponding Kodkod expression for the given expression, or
* null if it is not associated with anything.
*/
Expression a2k(Expr expr) throws ErrorFatal {
while (expr instanceof ExprUnary) {
if (((ExprUnary) expr).op == ExprUnary.Op.NOOP) {
expr = ((ExprUnary) expr).sub;
continue;
}
if (((ExprUnary) expr).op == ExprUnary.Op.EXACTLYOF) {
expr = ((ExprUnary) expr).sub;
continue;
}
break;
}
if (expr instanceof ExprConstant && ((ExprConstant) expr).op == ExprConstant.Op.EMPTYNESS)
return Expression.NONE;
if (expr instanceof ExprConstant && ((ExprConstant) expr).op == ExprConstant.Op.STRING)
return s2k.get(((ExprConstant) expr).string);
if (expr instanceof Sig || expr instanceof Field || expr instanceof ExprVar)
return a2k.get(expr);
if (expr instanceof ExprBinary) {
Expr a = ((ExprBinary) expr).left, b = ((ExprBinary) expr).right;
switch (((ExprBinary) expr).op) {
case ARROW :
return a2k(a).product(a2k(b));
case PLUS :
return a2k(a).union(a2k(b));
case MINUS :
return a2k(a).difference(a2k(b));
// TODO: IPLUS, IMINUS???
}
}
return null; // Current only UNION, PRODUCT, and DIFFERENCE of Sigs and
// Fields and ExprConstant.EMPTYNESS are allowed in a
// defined field's definition.
}
示例9: allocateSubsetSig
/** Allocate relations for SubsetSig top-down. */
private Expression allocateSubsetSig(SubsetSig sig) throws Err {
// We must not visit the same SubsetSig more than once, so if we've been
// here already, then return the old value right away
Expression sum = sol.a2k(sig);
if (sum != null && sum != Expression.NONE)
return sum;
// Recursively form the union of all parent expressions
TupleSet ts = factory.noneOf(1);
for (Sig parent : sig.parents) {
Expression p = (parent instanceof PrimSig) ? sol.a2k(parent) : allocateSubsetSig((SubsetSig) parent);
ts.addAll(sol.query(true, p, false));
if (sum == null)
sum = p;
else
sum = sum.union(p);
}
// If subset is exact, then just use the "sum" as is
if (sig.exact) {
sol.addSig(sig, sum);
return sum;
}
// Allocate a relation for this subset sig, then bound it
rep.bound("Sig " + sig + " in " + ts + "\n");
Relation r = sol.addRel(sig.label, null, ts);
sol.addSig(sig, r);
// Add a constraint that it is INDEED a subset of the union of its
// parents
sol.addFormula(r.in(sum), sig.isSubset);
return r;
}
示例10: visit
/** {@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()");
}
示例11: sim
/** If ex is a simple combination of Relations, then return that combination, else return null. */
private Expression sim(Expr ex) {
while(ex instanceof ExprUnary) {
ExprUnary u = (ExprUnary)ex;
if (u.op!=ExprUnary.Op.NOOP && u.op!=ExprUnary.Op.EXACTLYOF) break;
ex = u.sub;
}
if (ex instanceof ExprBinary) {
ExprBinary b = (ExprBinary)ex;
if (b.op==ExprBinary.Op.ARROW || b.op==ExprBinary.Op.PLUS || b.op==ExprBinary.Op.JOIN) {
Expression left = sim(b.left); if (left==null) return null;
Expression right = sim(b.right); if (right==null) return null;
if (b.op==ExprBinary.Op.ARROW) return left.product(right);
if (b.op==ExprBinary.Op.PLUS) return left.union(right); else return left.join(right);
}
}
if (ex instanceof ExprConstant) {
switch(((ExprConstant)ex).op) {
case EMPTYNESS: return Expression.NONE;
}
}
if (ex==Sig.NONE) return Expression.NONE;
if (ex==Sig.SIGINT) return Expression.INTS;
if (ex instanceof Sig) return sol.a2k((Sig)ex);
if (ex instanceof Field) return sol.a2k((Field)ex);
return null;
}
示例12: visit
/** {@inheritDoc} */
public void visit(ConstantExpression x) {
if (map.containsKey(x)) return;
String newname=null;
if (x==Expression.NONE) newname="Expression.NONE";
else if (x==Expression.UNIV) newname="Expression.UNIV";
else if (x==Expression.IDEN) newname="Expression.IDEN";
else if (x==Expression.INTS) newname="Expression.INTS";
else throw new RuntimeException("Unknown kodkod ConstantExpression \""+x+"\" encountered");
map.put(x,newname);
}
示例13: sim
/**
* If ex is a simple combination of Relations, then return that combination,
* else return null.
*/
private Expression sim(Expr ex) {
while (ex instanceof ExprUnary) {
ExprUnary u = (ExprUnary) ex;
if (u.op != ExprUnary.Op.NOOP && u.op != ExprUnary.Op.EXACTLYOF)
break;
ex = u.sub;
}
if (ex instanceof ExprBinary) {
ExprBinary b = (ExprBinary) ex;
if (b.op == ExprBinary.Op.ARROW || b.op == ExprBinary.Op.PLUS || b.op == ExprBinary.Op.JOIN) {
Expression left = sim(b.left);
if (left == null)
return null;
Expression right = sim(b.right);
if (right == null)
return null;
if (b.op == ExprBinary.Op.ARROW)
return left.product(right);
if (b.op == ExprBinary.Op.PLUS)
return left.union(right);
else
return left.join(right);
}
}
if (ex instanceof ExprConstant) {
switch (((ExprConstant) ex).op) {
case EMPTYNESS :
return Expression.NONE;
}
}
if (ex == Sig.NONE)
return Expression.NONE;
if (ex == Sig.SIGINT)
return Expression.INTS;
if (ex instanceof Sig)
return sol.a2k((Sig) ex);
if (ex instanceof Field)
return sol.a2k((Field) ex);
return null;
}