Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to calculate the distance between two cities??

Status
Not open for further replies.

inuy

Programmer
Dec 8, 2003
1
0
0
GB
How to calculate the distance between two
cities more than one city away from each other (by direct
connection).
distance(brisbane, sydney, 1000).
distance(sydney, canberra, 400).
distance(canberra, toowoomba, 1200).
distance(toowoomba, brisbane, 200).

for example:
one city away form each other.
oad(X, Y, D) :-
distance(X, Z, D1),
distance(Z, Y, D2),
D is D1+D2.
 
You should throw in a recursive step. i.e. add:

oad(X,Y,D) :- distance(X,Y,D). {base case}
oad(X,Y,D) :-
distance(X,Z,D1),
oad(Z,Y,D2),
D is D1+D2.
 
Now that the first step is out of the way, is there any way to refine the recursion so that it can filter out some certain place?

let's say that the journey shouldn't past through canberra,and we add another route to it like:

(sydney,disneyland).
(disneyland,toowomba).

Please help!!>!??!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top