本文整理汇总了Java中kodkod.ast.Expression.union方法的典型用法代码示例。如果您正苦于以下问题:Java Expression.union方法的具体用法?Java Expression.union怎么用?Java Expression.union使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kodkod.ast.Expression
的用法示例。
在下文中一共展示了Expression.union方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: connectedSites
import kodkod.ast.Expression; //导入方法依赖的package包/类
/**
* Returns the connectedSites predicate.
*
* @return pred connectedSites(sites: set Site) { -- all sites in the given
* set are connected to each other all s: sites | sites - s in
* ((site.s).^link).site }
*/
public Formula connectedSites(Expression sites) {
final Variable s = Variable.unary("s");
Expression closed;
if (closureApprox > 0) {
closed = link;
for (int i = 1; i < closureApprox; i *= 2) {
closed = closed.union(closed.join(closed));
}
} else {
closed = link.closure();
}
final Expression sreachable = site.join(s).join(closed).join(site);
final Formula f = sites.difference(s).in(sreachable);
return f.forAll(s.oneOf(sites));
}
示例2: allocateSubsetSig
import kodkod.ast.Expression; //导入方法依赖的package包/类
/** 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;
}
示例3: ts2expr
import kodkod.ast.Expression; //导入方法依赖的package包/类
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;
}
示例4: allocateSubsetSig
import kodkod.ast.Expression; //导入方法依赖的package包/类
/** 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: sim
import kodkod.ast.Expression; //导入方法依赖的package包/类
/** 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;
}
示例6: testBGP_03172011
import kodkod.ast.Expression; //导入方法依赖的package包/类
public final void testBGP_03172011() {
Relation x5 = Relation.unary("s012");
Relation x8 = Relation.unary("zero");
Relation x9 = Relation.unary("one");
Relation x12 = Relation.nary("next", 2);
Universe universe = new Universe(Arrays.asList("0", "1", "2", "3"));
TupleFactory factory = universe.factory();
Bounds bounds = new Bounds(universe);
bounds.boundExactly(x5, factory.setOf("0", "1", "2"));
bounds.boundExactly(x8, factory.setOf("0"));
bounds.bound(x9, factory.setOf("1"), factory.setOf("1", "2"));
TupleSet x12_upper = factory.noneOf(2);
x12_upper.add(factory.tuple("1", "2"));
x12_upper.add(factory.tuple("2", "3"));
bounds.boundExactly(x12, x12_upper);
Variable x714 = Variable.unary("x714");
Decls x713 = x714.oneOf(x8.union(x9));
Variable x720 = Variable.unary("x720");
Expression x723 = x8.union(x9);
Expression x724 = x9.join(x12);
Expression x722 = x723.union(x724);
Expression x721 = x722.difference(x714);
Decls x719 = x720.oneOf(x721);
Variable x727 = Variable.unary("x727");
Expression x732 = x714.union(x720);
Expression x728 = x5.difference(x732);
Decls x726 = x727.oneOf(x728);
Variable x735 = Variable.unary("x735");
Decls x734 = x735.oneOf(x8);
Variable x893 = Variable.unary("x893");
Decls x892 = x893.oneOf(x727);
Formula x894 = x720.no();
Formula x891 = x894.forAll(x892);
Formula x712 = x891.forSome(x713.and(x719).and(x726).and(x734));
Formula x267 = Formula.FALSE.or(x712);
Solver solver = new Solver();
solver.options().setSolver(SATFactory.MiniSat);
solver.options().setBitwidth(4);
// solver.options().setFlatten(false);
solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT);
solver.options().setSymmetryBreaking(20);
solver.options().setSkolemDepth(0);
final Solution sol = solver.solve(x267, bounds);
assertEquals(sol.outcome(), Solution.Outcome.TRIVIALLY_UNSATISFIABLE);
}
示例7: testFelix_11122006
import kodkod.ast.Expression; //导入方法依赖的package包/类
public final void testFelix_11122006() {
Relation x0 = Relation.nary("Q", 1);
Relation x1 = Relation.nary("B", 1);
Relation x2 = Relation.nary("A", 1);
Relation x3 = Relation.nary("QQ", 3);
List<String> atomlist = Arrays.asList("A", "B", "Q");
Universe universe = new Universe(atomlist);
TupleFactory factory = universe.factory();
Bounds bounds = new Bounds(universe);
TupleSet x0_upper = factory.noneOf(1);
x0_upper.add(factory.tuple("Q"));
bounds.boundExactly(x0, x0_upper);
TupleSet x1_upper = factory.noneOf(1);
x1_upper.add(factory.tuple("B"));
bounds.boundExactly(x1, x1_upper);
TupleSet x2_upper = factory.noneOf(1);
x2_upper.add(factory.tuple("A"));
bounds.boundExactly(x2, x2_upper);
TupleSet x3_upper = factory.noneOf(3);
x3_upper.add(factory.tuple("Q").product(factory.tuple("A")).product(factory.tuple("A")));
x3_upper.add(factory.tuple("Q").product(factory.tuple("B")).product(factory.tuple("B")));
bounds.bound(x3, x3_upper);
Expression x7 = x2.product(x2);
Expression x8 = x0.join(x3);
Formula x6 = x7.in(x8);
Formula x5 = x6.not();
Expression x18 = x1.product(x1);
Expression x17 = x7.union(x18);
Expression x16 = x0.product(x17);
Formula x15 = x3.in(x16);
Formula x4 = x5.and(x15);
Solver solver = new Solver();
solver.options().setSolver(SATFactory.DefaultSAT4J);
solver.options().setBitwidth(4);
solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT);
// System.out.println(bounds);
// System.out.println(x4);
Solution sol = solver.solve(x4, bounds);
assertEquals(sol.outcome(), Solution.Outcome.SATISFIABLE);
// System.out.println(sol.toString());
}
示例8: sim
import kodkod.ast.Expression; //导入方法依赖的package包/类
/**
* 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;
}