×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# find the shortest path

## find the shortest path

(OP)
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

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!