Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

COMP4411, Fall 2022 Assignment One

1. Multithread/Queue Implement in Java a Queue class whose add and remove methods are synchronized.   Supply one thread,  called the producer, which keeps inserting strings into the queue as long as there are fewer than ten elements in it.  When the queue gets to full, the thread waits. As sample strings, simply use time stamps new Date() .toString().  Supply a second thread, called the consumer, that keeps removing and printing strings from the queue as long as the queue is not empty. When the queue is empty, the thread waits. Both the consumer and producer threads should run for 100 iterations. Starter codes are given. (20 marks)

2. Run the following Prolog program from Ivan Bratko and query the problem to find out all answers. (30 marks)

parent(pam,  bob) .

parent(tom,  bob) .

parent(tom,  liz) .

parent(bob,  ann) .

parent(bob,  pat) .

parent(pat,  jim) .

female(pam) .

female(liz) .

female(ann) .

female(pat) .

male(tom) .

male(bob) .

male(jim) .

mother(X,  Y)  :-  parent(  X,  Y),  female(  X) .

(a) Who are Bob’s children?

(b) Who is a grandparent of Jim?

(c) Who are Tom’s grandchildren?

(d) Do Ann and Pat have a common parent? (e) Who is the mother of Bob?

(f) Who is the father of Bob?

(g) Add to the program a rule for father(X,Y), and then ask the

program who is the father of Pat.

3. Consult the following Prolog program. (30 marks)

male(tom) .

male(peter) .

male(doug) .

male(david) .

female(susan) .

parent(doug,  susan) .

parent(tom,  william) .

parent(doug,david) .

parent(doug,tom) .

grandfather(GP,GC):- male(GP),  parent(GP,A),  parent(A,GC) .

Draw the tracing tree to verify manually the following query ?-  grandfather(X,Y) .

to the program will return:

X  =  doug,

Y  =  william  ;

false .

4. Assume that a, b, c, d, e are Prolog predicates. Translate the following logical statements into one or more valid Prolog sentences that express the same thing. (20 marks)

❼ (a V b V c) ∨ d ⊃ e

❼ a V (b ∨ c) V d ⊃ e