1 Assignment 6 Total Points: 35 Submission: please submit your solution in either .txt or .pl format. You may work in a group of 2. 1. (10 points) This is a classical Prolog application. Given the...

Need help as soon as possible


1 Assignment 6 Total Points: 35 Submission: please submit your solution in either .txt or .pl format. You may work in a group of 2. 1. (10 points) This is a classical Prolog application. Given the following graph of possible flights between eight US cities: a) Build a knowledge base using the predicate directFlight/2 which encodes one city has direct flight to another city. b) Add to rule that checks if there is a route between two cities. Routes of length zero are allowed. Example queries: route(chicago, chicago). should return yes. route(chicago,la). should return yes. route(la,’San Fracisco’). should return no. c) Add a rule that checks if a route has two legs. Example queries: route_of_2_legs(chicago,la). should return yes route_of_2_legs(chicago,denver). should return no d) (optional, 3 extra points)Add cost factor to directFlight, route, and route_of_2_legs so that the knowledge base can tell the cost associated with each flight. For example, route(chicago, X, Y). tells all the cities reachable from Chicago, and the cost(Y)to fly from Chicago to each city(X). 2. (5 points) Consider the following Prolog program: edge(a, b). edge(c, d). edge(a, c). edge(c, b). edge(X, Y) :- edge(Y, X). path(X, X). path(X, Y) :- edge(Z, Y), path(X, Z). Note that this program is nearly identical to one presented in lecture except for the inclusion of the extra rule: edge(X, Y) :- edge(Y, X). The intent is that, with this additional rule, the program should model an undirected (as opposed to directed) graph. (a) Execute the query: ?- edge(a,b). What response do you get? (b) Execute the query ?- edge(b,a). What response do you get? (c) Execute the query ?- edge(a, d). What response do you get? And why? 3. (15 points) Family tree — Probably the most common first example of a logic program is that involving a family tree. Give the following family tree: a) Build a knowledge base using the predicate parent/2, which encodes a person is the parent (biological, not by marriage) of another person; male/1, which encodes a person is a male; and female/1, which encodes a person is a female. b) Add the following rules to the knowledge base: i. mother(X, Y), which means X is Y’s mother. ii. father(X, Y), which means X is Y’s father . iii. grandfather(X, Y), which means X is Y’s grandfather. (Note: Y can have two grandfathers: one on the maternal side, the other on the paternal side.) iv. grandmother(X, Y), which means X is Y’s grandmother. (Note: Y can have two grandfathers: one on the maternal side, the other on the paternal side.) v. siblings(X,Y). which means X and Y are siblings. vi. You may add aunt, uncle and cousin. c) Test your implementation by asking queries. Write down your query and also the result. i. Who are the siblings of Lisa? ii. List all the grandparents of Lisa? iii. List all family members? (Note: Same type of facts and rules should be grouped together, otherwise, you will get discontiguous error and clauses will be ignored.) 4. (5 points) Different languages have different application areas. Research on the application areas of Prolog and summarize your findings in a short paragraph of at least 150 words. 5.(10 extra points). Five schoolgirls sat for an examination. Their parents – so they thought – showed an undue degree of interest in the result. They therefore agreed that, in writing home about the examination, each girl should make one true statement and one untrue one. The following are the relevant passages from their letters:  Betty  Kitty was 2nd  I was 3rd  Ethel  I was on top  Joan was 2nd  Joan  I was 3rd  Ethel was last  Kitty  I came out 2nd  Mary was only 4th  Mary  I was 4th  Betty was 1st Write a prolog program to solve this puzzle. A completely working solution is required for extra points, i.e. all or nothing proposition. In-class Exercise In-class Exercises Chapter 7: 1. Given the program below, #include using namespace std; int fun(int *k){ *k += 4; return 3 * (*k) - 1; } int main(){ int i = 10, j = 10, sum1, sum2; sum1 = (i/2) + fun(&i); sum2 = fun(&j) + (j/2); cout < sum1="">< endl;="" cout="">< sum2="">< endl;="" return="" 0;="" }="" a)="" predict="" the="" values="" of="" sum1="" and="" sum2="" if="" the="" operands="" in="" the="" expressions="" for="" sum1="" and="" sum2="" are="" evaluated="" left="" to="" right.="" b)="" predict="" the="" values="" of="" sum1="" and="" sum2="" if="" the="" operands="" in="" the="" same="" expressions="" are="" evaluated="" right="" to="" left.="" c)="" predict="" the="" values="" of="" sum1="" and="" sum2="" if="" functions="" are="" evaluated="" first.="" d)="" compile="" with="" g++="" and="" run="" the="" program="" on="" pluto="" or="" your="" favorite="" c++="" environment,="" what="" are="" the="" values="" for="" sum1="" and="" sum2?="" 2.="" given="" the="" program="" below,="" #include=""> using namespace std; int a = 5; int fun1( ){ a = 17; return 3; } int fun(int* i){ *i += 5; return 4; } int main(){ a = a + fun1(); cout < "a = " << a << endl; int x = 3; x = x + fun(&x); cout << "x = " << x << endl; return 0; } a) what would be the output if you compile with g++ and run the program on pluto? b) based on 3 and 4 a), what conclusion can you make on operands evaluation order in c++, left-to-right or right-to left? "a=" << a << endl; int x = 3; x = x + fun(&x); cout << " x="">
Nov 29, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here