java eq_Java Relation.eq方法代码示例

这段代码展示了如何在Java中使用kodkod库进行关系约束,具体涉及Relation.eq方法的用法。通过创建universe、bound关系以及设置变量和公式,最终解决求解器的问题并验证实例。
摘要由CSDN通过智能技术生成

import kodkod.ast.Relation; //导入方法依赖的package包/类

public final void testFelix_03062008_2() {

Relation x5 = Relation.unary("Role");

Relation x6 = Relation.unary("Session");

List atomlist = Arrays.asList("Role$0", "Session$0", "Session$1");

Universe universe = new Universe(atomlist);

TupleFactory factory = universe.factory();

Bounds bounds = new Bounds(universe);

TupleSet x5_upper = factory.noneOf(1);

x5_upper.add(factory.tuple("Role$0"));

bounds.bound(x5, x5_upper);

TupleSet x6_upper = factory.noneOf(1);

x6_upper.add(factory.tuple("Session$0"));

x6_upper.add(factory.tuple("Session$1"));

bounds.bound(x6, x6_upper);

Variable x11 = Variable.unary("x_a");

Decls x10 = x11.oneOf(x6);

Variable x15 = Variable.unary("x_b");

Decls x14 = x15.oneOf(x5);

Variable x17 = Variable.unary("x_c");

Decls x16 = x17.oneOf(x5);

Decls x13 = x14.and(x16);

Expression x20 = x15.product(x17);

Expression x19 = x11.product(x20);

Formula x18 = x19.some();

Formula x12 = x18.forSome(x13);

Formula x9 = x12.forAll(x10);

Formula x24 = x5.some();

Formula x23 = x24.not();

Formula x28 = x5.eq(x5);

Formula x29 = x6.eq(x6);

Formula x25 = x28.and(x29);

Formula x22 = x23.and(x25);

Formula x8 = x9.and(x22).and(x5.no()).and(x6.no());

Solver solver = new Solver();

solver.options().setSolver(SATFactory.DefaultSAT4J);

solver.options().setBitwidth(2);

// solver.options().setFlatten(false);

solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT);

solver.options().setSymmetryBreaking(20);

solver.options().setSkolemDepth(2);

System.out.flush();

Solution sol = solver.solve(x8, bounds);

Instance inst = sol.instance();

assertNotNull(inst);

for (Relation rel : inst.relations()) {

if (rel != x5 && rel != x6) {

final TupleSet range = inst.tuples(x6).product(inst.tuples(x5));

assertTrue(range.containsAll(inst.tuples(rel)));

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值