Prolog data are symbolic. You could be passing distance in meters, and treat it as distance in feet. That's how one of Mars missions got crashed, although they used another language. So it's ultimately up to you.
As to your code,
findAllRoutes(Start, End, Path) :-
findAllRoutes(Start, _, End, Path),
print('Successful route: '), print(Route).
Route
? What Route
? It's an uninstantiated "singleton" variable. SWI Prolog warns us to that effect. Perhaps you meant Path
.
findAllRoutes(End, _, End, [End]). % route was successfully finished
findAllRoutes(Start, Temp, End, [Start|Rest_of_List]) :-
path(Start, Temp),
findAllRoutes(Temp, _, End, Rest).
again, Rest_of_List
and Rest
probably should have the same name (be the same logical variable).
Otherwise it looks OK, except for its name: it finds one path, not "AllRoutes", on each invocation/backtracking. The name "AllRoutes" suggests it finds all of them and returns them all in its result argument; it's not.
Then comes your data and it's out of sync with your code:
%path(Start, End).
path(1, 4). %find all the possible paths from location 1 to location 4.
%paths_in_place[[Start, End, Distance]].
paths_in_place([[1, 2, 250], [2, 4, 250], [1, 3, 400], [3, 4, 300]]).
% ! must be in parentheses !
Your path(Start, Temp)
call in your code suggests Temp
is an immediate successor to Start
. Not so according to these data. Plus, path/2
definition is missing. But you can just have a bunch of facts instead of the list to define the data.