如何解决从使用 Python 包 dd 建模的二元决策图中计算最小割集
问题:如何从使用 Python 包 dd 建模的二元决策图中计算最小割集 (MCS)?
定义: 简而言之,根据下面的示例,MCS 是导致输出 1 的最少且唯一的事件集。
示例:
给定图中的二元决策图:
只有三个 MCS:
- {BE1 和 BE2}
- {BE1 & BE3 & BE4}
- {BE1 & BE3 & BE5}
注意事项:
- 一个割集是 {BE1 & BE2 & BE3 & BE4},但它不是最小的,因为它是由第一个和第二个割集组成的。
- 割集仅由输出为 1 的节点组成。因此,MCS 是 {BE1 & BE3 & BE4} 而不是 {BE1 & ¬BE2 & BE3 & BE4}。
对于 BDD,您可以使用以下代码(基于 this publication):
from dd import autoref
bdd = autoref.BDD()
bdd.declare('BE1','BE2','BE3','BE4','BE5')
# These are the assignments to the input variables
# where the Boolean function is TRUE (the y).
# The assignments where the Boolean function is FALSE
# are not used in the disjunction below.
data = [{'BE1': True,'BE3': True,'BE5': True},{'BE1': True,'BE4': True},'BE4': True,'BE2': True},'BE2': True,'BE3': True},'BE5': True}]
u = bdd.false
for d in data:
u |= bdd.cube(d) # disjunction so far
bdd.dump('example.png',roots=[u])
输出应该是这样的:
mcs = your_function(bbd)
print(mcs)
[['BE1','BE2'],['BE1','BE4'],'BE5']]
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。