Z3连接的组件

发布于 2025-02-05 04:43:17 字数 235 浏览 3 评论 0 原文

作为拼图求解器的一部分,我从用户输入中动态构建图形,节点和边缘。

每个节点均分配一个整数const,代表其一部分连接的组件。 节点仅限于与邻居相同的连接组件。

当前,它可以将相同的数字分配给多个组件,但是我想限制解决方案,以便每个连接的组件必须具有唯一的数字。

我无法围绕如何在Z3中表达这种约束。

我不是在寻找工作代码,只是关于如何处理此问题的高级描述,我可以从那里进行。

提前致谢!

As part of a puzzle solver, I dynamically build a graph, nodes and edges, from user input.

Each node is assigned an integer const, representing which connected component it is part of.
Nodes are restricted to have the same connected component as their neighbors.

Currently, it can assign the same number to multiple components, but I want to restrict the solution so that each connected component must have a unique number.

I cannot wrap my head around how to express this constraint in Z3.

I'm not looking for working code, just a high level description of how to approach this, and I can take it from there.

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忱杏 2025-02-12 04:43:18

可以使用

以下片段可能会让您入门:

#  https://stackoverflow.com/q/56496558/1911064
from z3 import *

B = BoolSort()
NodeSort = DeclareSort('Node')

R = Function('R', NodeSort, NodeSort, B)
TC_R = TransitiveClosure(R)

s = Solver()

na, nb, nc = Consts('na nb nc', NodeSort)
s.add(R(na, nb))
s.add(R(nb, nc))
s.add(Not(TC_R(na, nc)))

print(s.check())   # produces unsat

Nodes of a graph component connected via other nodes can be modelled using TransitiveClosure.

The following snippet might get you started:

#  https://stackoverflow.com/q/56496558/1911064
from z3 import *

B = BoolSort()
NodeSort = DeclareSort('Node')

R = Function('R', NodeSort, NodeSort, B)
TC_R = TransitiveClosure(R)

s = Solver()

na, nb, nc = Consts('na nb nc', NodeSort)
s.add(R(na, nb))
s.add(R(nb, nc))
s.add(Not(TC_R(na, nc)))

print(s.check())   # produces unsat
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文