shortest path

Discussions related to Visual Prolog
Posts: 11
Joined: 7 Dec 2013 15:16

shortest path

Unread post by hadiranji » 29 Jan 2014 21:02

i writing the program who find path in edges but for preventing :
e631: The predicate 'factorial::fac/2 (i,o), which is declared as 'procedure', is actually 'multi'
i used "!" sign is returned only one path but i need to return all path and then use shortest path

how can do it ?

Code: Select all

connected(Window,X,Z):-edge(X,Z,L),L>"0", draw(Window,X,Z),nVal:=nVal+toterm(L), stdio::write(X, " to ",Z," by weight ", L," all ",nVal,"\n"),!.   connected(Window,X,Z):-edge(X,Y,L),L>"0", connected(Window,Y,Z),nVal:=nVal+toterm(L), stdio::write(X, " to ",Y," by weight ", L," all ",nVal,"\n"), draw(Window,X,Y),!.   connected(_Window,_X,_Y).

Paul Cerkez
VIP Member
Posts: 94
Joined: 6 Mar 2000 0:01

Unread post by Paul Cerkez » 30 Jan 2014 16:21

as you only need the shortest, all you need to save is that one. Saving all is a waste of time and space.

Create a fact and store the shortest one there.

as each path is created and calculated, you comapre it against the saved one. if the new one is shorter, replace the stored one with the new shortest one. if it is longer, discard it.

also, when I did this a few years back in VIP 6.x, I included the heuristic rule that after each edge was measured and added to the current path total, I checked its value. it it exceeded the current shortest path saved, I terminated future execution of that path.
AI Rules!

Post Reply