# Różnice

Różnice między wybraną wersją a wersją aktualną.

 — pl:prolog:pllib:graph_path_4 [2019/06/27 15:50] (aktualna) Linia 1: Linia 1: + ====== Graph path 4 ====== + {{tag>​graphs}} + ===== Description ===== + Generates paths between any two nodes of the graph + + {{:​prolog:​pllib:​graph_path_4.png|}} + + **Source**: ​ PrologTutorial (on-line tutorial + + + + ===== Download ===== + Program source code: {{graph_path_4.pl}} + ===== Listing ===== + + /* prolog tutorial 2.15 Graph structures and paths */ + + + + edge(1,2). + + edge(1,4). + + edge(1,3). + + edge(2,3). + + edge(2,5). + + edge(3,4). + + edge(3,5). + + edge(4,5). + + + + connected(X,​Y) :- edge(X,Y) ; edge(Y,X). + + + + path(A,​B,​Path) :- + + ​travel(A,​B,​[A],​Q), ​ + + ​reverse(Q,​Path). + + + + travel(A,​B,​P,​[B|P]) :- + + ​connected(A,​B). + + travel(A,​B,​Visited,​Path) :- + + ​connected(A,​C), ​ + + C \== B, + + ​\+member(C,​Visited),​ + + ​travel(C,​B,​[C|Visited],​Path).  ​ + + + + % ?- path(1,​5,​P). + + ​ + ===== Comments =====
pl/prolog/pllib/graph_path_4.txt · ostatnio zmienione: 2019/06/27 15:50 (edycja zewnętrzna)