Page 1 of 1

shortest path

Posted: 29 Jan 2014 21:02
by hadiranji
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).

Posted: 30 Jan 2014 16:21
by Paul Cerkez
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.