这可能是一个简单的问题,但我需要以不同的方式来做。问题是我必须在序言中找到可能的飞行路线。我有这个知识库
from_to(fresno,seattle).
from_to(fresno,albany).
from_to(albany,dallas).
from_to(fresno,boston).
from_to(dallas,seattle).
from_to(dallas,albany).
from_to(seattle,dallas).
from_to(seattle,omaha).
from_to(atlanta,albany).
from_to(atlanta,dallas).
from_to(atlanta,boston).
from_to(omaha,atlanta).
from_to(omaha,albany).
from_to(albany,seattle).
我必须创建一个谓词 route(X,Y) 来检查我们是否可以从 X 到 Y。我所做的是:
route(X,Y):-from_to(X,Y).
route(X,Y):-from_to(X,Z), route(Z,Y).
但它不起作用,因为图形是循环的。我在互联网上搜索,每个人都说的唯一一件事就是使用列表并检查访问过的路径。但我不能使用列表!我必须在不使用列表的情况下创建谓词路由(X,Y),如果没有列表,我该如何完成呢?谢谢