Suppose to have a list of air planes defined as follow:
plane(rome,berlin).
plane(berlin,london).
plane(london,lisboa).
plane(london,dublin).
plane(dublin,paris).
plane(rome,paris).
plane(berlin,paris).
I will solve the problem to find all routes between two cities in the following way:
route(Dep, Arr, [Dep, Arr]) :- plane(Dep, Arr).
route(Dep, Arr, [Dep|C]) :- plane(Dep, Z), route(Z, Arr, C).
For example with
?- route(rome,paris,P).
I obtain:
P = [rome, paris]
P = [rome, berlin, paris]
P = [rome, berlin, london, dublin, paris]
false.
The problem comes if I add prices, e.g.,
plane(rome,berlin,20).
plane(berlin,london,14).
plane(london,lisboa,44).
plane(london,dublin,99).
plane(dublin,paris,44).
plane(rome,paris,4).
plane(berlin,paris,6).
I have two questions:
- What does the last false represent?
- How can I get the list of all the routes with the total price and the cheaper one?