I'm just starting to learn prolog. And i'm getting stuck in this problem. May be anyone can help me out of this.
Given some fact below :
[highlight #A40000]byCar(auckland,hamilton).
byCar(hamilton,raglan).
byCar(valmont,saarbruecken).
byCar(valmont,metz).
byTrain(metz,frankfurt).
byTrain(saarbruecken,frankfurt).
byTrain(metz,paris).
byTrain(saarbruecken,paris).
byPlane(frankfurt,bangkok).
byPlane(frankfurt,singapore).
byPlane(paris,losAngeles).
byPlane(bangkok,auckland).
byPlane(losAngeles,auckland).
[/highlight]
and i define predicate travel/2 as follow :
[highlight #A40000]travel(A,B):-bycar(A,B);bytrain(A,B);byplane(A,B).
travel(A,B):-(bycar(A,C);bytrain(A,C);byplane(A,C)).[/highlight]
And the problem is :
1. By using travel/2 to query the above database, write a predicate travel/3 which
tells how to travel from one place to another. The program should, e.g., answer
‘yes’ to the query travel(valmont,paris,go(valmont,metz,go(metz,paris)))
and X = go(valmont,metz,go(metz,paris,go(paris,losAngeles))) to the
query travel(valmont,losAngeles,X).
2. Extend the predicate travel/3 so that it not only tells via which other cities
you have to go to get from one place to another, but also how, i.e. by car, train,
or plane, you get from one city to the next.
Given some fact below :
[highlight #A40000]byCar(auckland,hamilton).
byCar(hamilton,raglan).
byCar(valmont,saarbruecken).
byCar(valmont,metz).
byTrain(metz,frankfurt).
byTrain(saarbruecken,frankfurt).
byTrain(metz,paris).
byTrain(saarbruecken,paris).
byPlane(frankfurt,bangkok).
byPlane(frankfurt,singapore).
byPlane(paris,losAngeles).
byPlane(bangkok,auckland).
byPlane(losAngeles,auckland).
[/highlight]
and i define predicate travel/2 as follow :
[highlight #A40000]travel(A,B):-bycar(A,B);bytrain(A,B);byplane(A,B).
travel(A,B):-(bycar(A,C);bytrain(A,C);byplane(A,C)).[/highlight]
And the problem is :
1. By using travel/2 to query the above database, write a predicate travel/3 which
tells how to travel from one place to another. The program should, e.g., answer
‘yes’ to the query travel(valmont,paris,go(valmont,metz,go(metz,paris)))
and X = go(valmont,metz,go(metz,paris,go(paris,losAngeles))) to the
query travel(valmont,losAngeles,X).
2. Extend the predicate travel/3 so that it not only tells via which other cities
you have to go to get from one place to another, but also how, i.e. by car, train,
or plane, you get from one city to the next.