I would like to find out what is the shortest path from point a to z.
edge(a,b,3).
edge(a,d,8).
edge(a,i,9).
edge(a,f,11).
edge(a,j,16).
edge(a,e,19).
edge(b,h,4).
edge(b,c,6).
edge(b,j,13).
edge(b,g,8).
edge(b,d,5).
edge(b,i,6).
edge(b,f,8).
edge(b,e,16
edge(d,i,1).
edge(d,f,3).
edge(d,j,8).
edge(d,e,11).
edge(d,g,1).
edge(d,c,8).
edge(d,z,16).
edge(i,f,2).
edge(i,j,7).
edge(i,e,10).
edge(i,g,2).
edge(i,c,9).
edge(i,z,17).
edge(f,k,1).
edge(f,g,3).
edge(f,h,9).
edge(f,j,5).
edge(f,e,8).
edge(g,h,6).
edge(g,f,3).
edge(g,c,7).
edge(g,z,15).
edge(g,k,4).
edge(k,j,7).
edge(k,c,14).
edge(j,c,7).
edge(j,e,3).
edge(e,z,8).
path(X,Y,M,[Y]) :- edge(X,Y,M).
path(X,Y,P,[W|T]) :- edge(X,W,M),path(W,Y,N,T),
P is M+N.
pravilo(X,Y,Z) :- assert(min(100)),assert(minpath([])),!,
path(X,Y,K,PATH1),
(min(Z),K<Z,
retract(min(Z));assert(min(K))),
minpath(Q),retract(minpath(Q)),
assert(minpath([X|PATH1])),
nl,!,
fail.
?- pravilo(a,z,X);
write("Minimal Path:"),
minpath(PATH),
write(PATH),
nl,
write("Path weight:"),
min(W),
write(W).
any one can help me to fix it? How would I do this?
thanks
edge(a,b,3).
edge(a,d,8).
edge(a,i,9).
edge(a,f,11).
edge(a,j,16).
edge(a,e,19).
edge(b,h,4).
edge(b,c,6).
edge(b,j,13).
edge(b,g,8).
edge(b,d,5).
edge(b,i,6).
edge(b,f,8).
edge(b,e,16
edge(d,i,1).
edge(d,f,3).
edge(d,j,8).
edge(d,e,11).
edge(d,g,1).
edge(d,c,8).
edge(d,z,16).
edge(i,f,2).
edge(i,j,7).
edge(i,e,10).
edge(i,g,2).
edge(i,c,9).
edge(i,z,17).
edge(f,k,1).
edge(f,g,3).
edge(f,h,9).
edge(f,j,5).
edge(f,e,8).
edge(g,h,6).
edge(g,f,3).
edge(g,c,7).
edge(g,z,15).
edge(g,k,4).
edge(k,j,7).
edge(k,c,14).
edge(j,c,7).
edge(j,e,3).
edge(e,z,8).
path(X,Y,M,[Y]) :- edge(X,Y,M).
path(X,Y,P,[W|T]) :- edge(X,W,M),path(W,Y,N,T),
P is M+N.
pravilo(X,Y,Z) :- assert(min(100)),assert(minpath([])),!,
path(X,Y,K,PATH1),
(min(Z),K<Z,
retract(min(Z));assert(min(K))),
minpath(Q),retract(minpath(Q)),
assert(minpath([X|PATH1])),
nl,!,
fail.
?- pravilo(a,z,X);
write("Minimal Path:"),
minpath(PATH),
write(PATH),
nl,
write("Path weight:"),
min(W),
write(W).
any one can help me to fix it? How would I do this?
thanks