QUESTION
Describe your assignment
Your task is mainly to maintain a database of distances between cities in Romania.
Step 1: Key-in data
• Create an external file to store all the distances shown in the map above. Present the data in Prolog fact. Save them in an external file.
• You program must allow add, delete, and retrieve data from the external file.
Step 2: Preparing to Prolog Rules
Create suitable Prolog rules for inference purposes. Rules should be formed in order to answer at least 5 queries, but NOT limited to:
• Where can we go from one city?
• Which city is nearest to a specific city?
• All the possible paths from a specific city.
• The shortest path from one city to another specific city.
SOLUTION
Romania
Romania (71,’Quaredia’,’151′,’151 Siblu’, ‘Quaredia, 71,Zerind)
Romania(75,’Arad’,’140 siblu’,118,’Timisora’)
Romania(111,’Lugoj’,’ Timisora ‘,70,’Mehadia’,75,’Doberata)
Romania (1,'Grocery',181).
Romania (3,'Deli',193).
Romania (5,'Produce',199).
Romania (gaia,uranus).
Romania (X,Y) :- Romania (_,X,Y).
RomaniaS(uranus,gaia,rhea).
RomaniaS(cronus,rhea,zeus).
RomaniaS(cronus,rhea,hera).
RomaniaS(cronus,rhea,demeter).
RomaniaS(zeus,leto,artemis).
RomaniaS(zeus,leto,apollo).
RomaniaS(demeter,zeus,persephone).
female(artemis).
female(persephone).
female(X) :- Romania(X,_).
male(apollo).
father(X,Y) :- RomaniaS(X,_,Y).
% First the facts:
1. p(pam,bob).
2. p(tom,bob).
3. p(bob,ann).
4. p(bob,pat).
5. p(pat,jim).
6. p(tom,liz).
% A procedure for predecessor:
7. pred(X,Z):- p(X,Z).
8. pred(X,Z):- p(X,Y), pred(Y,Z).
% Line numbers for our reference only
?- pred( tom, X).
7. pred( tom, Z):- p(tom, Z)
2. p(tom, bob) ; bob matches Z (Z/bob), which is backed up to X
X=bob;
6. p(tom, liz) ; Z/liz, so then X/liz
X=liz;
no
8. pred(tom, Z):- p(tom, Y), pred(Y, Z).
2. p(tom, bob), pred(bob, Z)
7. pred(bob, Z):- p(bob, Z).
3. p(bob, ann) ;Z/ann, X/ann
X=ann;
4. p(bob, pat) ;Z/pat, X/pat
X=pat;
no
8. pred(bob, Z):- p(bob, Y), pred(Y, Z).
3. p(bob, ann), pred(ann, Z)
… no
4. p(bob, pat), pred(pat, Z)
7. pred(pat,Z):- p(pat, Z)
5.p(pat, jim)
X=jim;
no
no
no
no
6. p(tom, liz), pred( liz, Z)… no
vestavia% cat min.pro
min(X, Y, X) :- X < Y.
min(X, Y, Y) :- X >= Y.
vestavia% sbp
SB-Prolog Version 3.1
| ?- consult(‘min.pro’).
yes
| ?- min(0, 1, 0).
yes
| ?- min(17, 45, Minimum).
Minimum = 17
yes
| ?- min(65, 3, Minimum).
Minimum = 3
yes
| ?- ^D
Halt. Program terminated normally
vestavia% cat factorial.pro
factorial(0, 1).
factorial(N, Factorial) :-
M is N – 1, factorial(M, M_Factorial),
Factorial is N * M_Factorial.
vestavia% sbp
SB-Prolog Version 3.1
| ?- consult(‘factorial.pro’).
yes
| ?- factorial(5, Factorial).
Factorial = 120
yes
| ?- factorial(10, Factorial).
Factorial = 3628800
yes
| ?- ^D
Halt. Program terminated normally
vestavia% cat length.pro
length([], 0).
length([X | Xs], Length) :-
length(Xs, Xs_Length),
Length is Xs_Length + 1.
vestavia% sbp
SB-Prolog Version 3.1
| ?- consult(‘length.pro’).
yes
| ?- length([a, b, c, d], Length).
Length = 4
yes
| ?- length([a, [b, c]], Length).
Length = 2
yes
| ?- length([], Length).
Length = 0
yes
| ?- length([a, [b, c], d, [e, f, [g, h]]],
Length).
Length = 4
yes
| ?- ^D
Halt. Program terminated normally
vestavia% cat lisp_functions.pro
car([X | Xs], X).
cdr([X | Xs], Xs).
cons(X, Xs, [X | Xs]).
append([], Ys, Ys).
append([X | Xs], Ys, [X | Zs]) :-
append(Xs, Ys, Zs).
vestavia% sbp
SB-Prolog Version 3.1
| ?- consult(‘lisp_functions.pro’).
yes
| ?- cons(x, [], A).
A = [x]
yes
| ?- cons(y, [x], B).
B = [y,x]
Yes
KE69
But you can order it from our service and receive complete high-quality custom paper. Our service offers Technology essay sample that was written by professional writer. If you like one, you have an opportunity to buy a similar paper. Any of the academic papers will be written from scratch, according to all customers’ specifications, expectations and highest standards.”