2
我試圖找到所有可能的路線,然後打印給用戶,但由於我對prolog很有新意,我遇到了一些麻煩。在圖中查找路線
graph http://i62.tinypic.com/11tu1sh.png
我要打印所有可能的方式去克來自A.這是我到目前爲止有:
direct_path(pathA,pathB).
direct_path(pathA,pathC).
direct_path(pathB,pathD).
direct_path(pathC,pathE).
direct_path(pathC,pathF).
direct_path(pathE,pathD).
direct_path(pathE,pathG).
direct_path(pathF,pathG).
upward(X, Y):- direct_path(X, Y).
upward(X, Z):- direct_path(X, Y), upward(Y, Z).
這樣我可以檢查是否有可能從A點到G,但我該如何打印這個路徑?