Preview

Prolog Sample Program

Powerful Essays
Open Document
Open Document
1219 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Prolog Sample Program
CPT114 – LOGIC & APPLICATIONS
Academic Session 2014/2015, Semester 1

Prolog Assignment 1
WORLD TRAVEL ROUTE FINDING PROGRAM

Page Number
1.0
Problem Statement
1
2.0
Prolog Program
2-3
3.0
List of Queries
4-5

4.0

Sample Input – Output

6-8

1.0 Problem Statement This assignment required us to make a prolog program to determine best route to travel from a city to another city using both number of cities pass through along the journey and the shortest distance between the departure and arrival city. We decided that the best route given to user with priority of least transits, followed by shortest distance between departure and arrival city. This will reduce the time spend on transit between city. We believed that this is the primary concern of the passengers. However, if the user still wants to have another route with shortest distance between departure and arrival city regardless of increase number of transit city, the program will provide the respective route. We will prompt the user to select between these two types of best routes.
List of available cities:
New York
London
San Francisco
Tokyo
Rome
Calcutta
Cairo
Sydney
Cape Town
Panama

2.0 Prolog Program distance(london,rome,0.8). distance(london,newyork,3.2). distance(london,panama,4.5). distance(london,capetown,5.8). distance(panama,sydney,7.7). distance(newyork,panama,1.9). distance(newyork,sanfrancisco,2.5). distance(sanfrancisco,tokyo,4.5). distance(sanfrancisco,sydney,6.2). distance(tokyo,calcutta,2.5). distance(tokyo,sydney,4.1). distance(calcutta,cairo,2.2). distance(sydney,calcutta,4.4). distance(sydney,capetown,6.0). distance(capetown,rome,5.1). distance(cairo,rome,0.9).

connected(X,Y,L) :- distance(X,Y,L) ; distance(Y,X,L).

path2(A,B,Path,Len,Num) :- travel(A,B,[A],Q,Len), reverse(Q,Path),length(Path,N),Num is N-2.

travel(A,B,P,[B|P],L) :- connected(A,B,L). travel(A,B,Visited,Path,L) :- connected(A,C,D), C \== B,
\+member(C,Visited),

You May Also Find These Documents Helpful