【发布时间】:2018-12-05 21:43:17
【问题描述】:
我有一个带有标记节点和边的有向根图的规范。该规范描述了哪些节点可以连接到哪些其他节点,以及根据顶点属性的图结构的各个方面。
例如:
每个 A 节点都必须连接到具有边类型 B 的 B 节点,该 B 节点通过任何边类型连接到 D 节点,并且根必须具有到至少 2 个其他节点的路径。
followsSpec(Root) :-
edge(Root, _, A),
edge(Root, _, B),
A != B,
edge(A, edgeTypeB, C),
node(C, nodeTypeC),
edge(C, _, D),
node(D, nodeTypeD).
我想说
node(root, typeA)
followsSpec(root)
并引出图表中使followsSpec 为真的其他可能元素:
node(b, typeB)
node(c, typeC)
edge(root, some_arbitrary_edge_type, b)
edge(root, some_other_arbitrary_edge_type, c)
edge(b, edge_type_b, c)
有没有办法在 Prolog 中做到这一点?
我特别担心效率,因为实际上规范更复杂,至少会有 100 个节点。
编辑:试图形式化:
可溯源谓词是edge/3(其中三个变量对应于转换的源、目标和类型)和node/2(其中两个变量对应于节点标识符和节点标签)。
我从一个事实开始node(root, rootLabel))。
我的观察:followsSpec(root),其中
followsSpec(X) :- "x is connected in a particular way to other nodes through edges"
我想观察的:那些其他节点和边是什么,所以 followSpec(root) 是真的。
【问题讨论】:
-
评论不用于扩展讨论;这个对话是moved to chat。
标签: prolog graph-theory constraint-programming