【发布时间】:2012-01-13 17:37:31
【问题描述】:
我有一个充满事实的数据库,例如:
overground( watfordjunction , watfordhighstreet , 2 ).
overground( watfordhighstreet , bushey , 3 ).
overground( bushey , carpenderspark , 3 ).
overground( carpenderspark , hatchend , 2 ).
示例:watford 路口到 watfordhighstreet 需要 2 分钟。
然后我设计了一个规则,以便我可以测试从任何站点到另一个站点的旅程是否可以完成,包括任何反向旅程。
isjourney( Station1 , Station2 ) :-
overground( Station1 , _ , _ ) ,
overground( _ , Station2 , _ ) ;
overground( Station2 , _ , _ ) ,
overground( _ , Station1 , _ )
.
isjourney( Station1 , Station2 ) :-
overground( Station1 , Station3 , _ ) ,
isjourney( Station3 , Station2 )
.
isjourney( Station1 , Station2 ) :-
overground( Station4 , Station2 , _ ) ,
isjourney( Station1 , Station4 )
.
(请原谅下划线,我在粘贴时遇到了问题)
最后我想出了工作正常的方法,但是我只是在反复试验后才设法想出它,所以我无法解释它是如何工作的,甚至无法解释它在做什么......任何人都可以体验过 prolog解释一下它的作用?
【问题讨论】:
-
对不起,我在顶部提到的所有事实都是为了被称为地上而不是车站,当您拥有相同文件 xD 的 5 个版本时会发生这种情况。无论如何,我进行了编辑,希望现在事情变得有意义,在事实中定义了地面。