I need a method that returns all the roads* used in a route between two points, here's the map I have:
Example, to point A
to E
, i need a list of roads used, like that:
route(a, e, R).
R = [1,5].
I'm having problems in marking the routes that i've already visited, and on top of that, register the number of the road used in a list.
So here's my code so far:
road(1,a,b).
road(2,a,d).
road(3,b,c).
road(4,c,d).
road(5,b,e).
road(6,c,f).
road(7,d,f).
road(8,e,f).
connected(A,B) :- road(_,A,B).
route(A, B, R) :- road(R, A, B), road(R, B, A).
route(A, B, [R2|R]) :- route(A, C, R2), route(C, B, R2).
Your solution is still not resisting cycles in graph, here is once that keeps it in mind
Thanks for the help! I did know the procedure, but i was finding difficult in appending the roads to the list, here's the final code:
Here's my desired output:
I was making a confusion in appending the list in the second definition of route, the examples helped me. Thanks for the help!!