CPS 721 Quiz 9
2021 Practice Version
(not shared) Switch account
The Glass Swapping Puzzle
Copyright By Assignmentchef assignmentchef
There are 3 full glasses of water and 3 empty glasses on a table in the following order:
By only swapping adjacent full and empty glasses, we wish to get all full glasses to the left side of the table, and all empty glasses to the right side. Two glasses cannot be swapped if they are both full or if they are both empty. We will use the integers 1 through 6 to denote the positions on the table, from left to right. The predicate position(P) is used to instantiate the variable P to one of these integers.
This planning domain has the following fluents:
full(P, S) this fluent is true if the glass at position P is full in situation S empty(P, S) this fluent is true if the glass at position P is empty in situation S
This domain also has the following action:
swap(P1, P2) swap the glasses at positions P1 and P2, where P1 is the position directly to the left of P2
Which of the following is the correct Prolog implementation of the precondition for the action swap(P1, P2)?
poss(swap(P1, P2), S):- position(P1), P2 is P1 + 1, (full(P1, S), empty(P2, S)), (empty(P1, S), full(P2, S)).
poss(swap(P1, P2), S):- position(P1), P2 is P1 + 1, P2 =< 6, not full(P1, P2, S), not empty(P1, P2, S).poss(swap(P1, P2)):- position(P1), position(P2), full(P1), empty(P2), P2 is P1 + 1, P2 is P1 – 1.poss(swap(P1, P2), S):- position(P1), position(P2), P2 is P1 + 1, not (full(P1, S), full(P2, S)), not (empty(P1, S), empty(P2, S)).poss(swap(P1, P2), S):- position(P1, S), position(P2, S), (full(P1, [A|S]), empty(P2, [A|S])), (full(P2, [A|S], empty(P1, [A|S])), P2 is P1 + 1. Which two of the following constitute the correct Prolog implementation of both positive successor state axioms for the fluent full(P, S)? (Select exactly 2, the correct answers will be adjacent)full(P1, [swap(P1, P2)|S]).full(P2, [swap(P1, P2)|S]).full(P1, [swap(P1, P2)|S]):- full(P2, S).full(P2, [swap(P1, P2)|S]):- full(P1, S).full(P, [swap(P1, P2)|S]):- full(P, S), not P = P1.full(P, [swap(P1, P2)|S]):- full(P, S), not P = P2.full(P1, [swap(P1, P2)|S]):- empty(P2, [swap(P1, P2)|S]). full(P2, [swap(P1, P2)|S]):- empty(P1, [swap(P1, P2)|S]).Which of the following is the correct Prolog implementation of the negative successor state axiom for the fluent empty(P, S)?empty(P, [swap(P1, P2)|S]):- empty(P, S), not (P = P1, P = P2). empty(P, [A|S]):- full(P, S), A = swap(P, P1), A = swap(P2, P). empty(P, [A|S]):- empty(P, S), not (A = swap(P, P1), A = swap(P2, P)). empty(P, [swap(P1, P2)|S]):- full(P2, S), P = P1.empty(P, [A|S]):- empty(P, S), not A = swap(P, P2), not A = swap(P2, P).Which of the following is the correct Prolog implementation of the goal_state predicate for this puzzle?goal_state([ ]):- full(1, [ ]), full(2, [ ]), full(3, [ ]), empty(4, [ ]), empty(5, [ ]), empty(6, [ ]). goal_state([ ]):- full(1, [ ]), full(3, [ ]), full(5, [ ]), empty(2, [ ]), empty(4, [ ]), empty(6, [ ]).goal_state(S):- full(P1, S), full(P2, S), full(P3, S), empty(P4, S), empty(P5, S), empty(P6, S).goal_state(S):- full(1, S), full(3, S), full(5, S), empty(2, S), empty(4, S), empty(6, S). goal_state(S):- full(1, S), full(2, S), full(3, S), empty(4, S), empty(5, S), empty(6, S).Clear formThis form was created inside of. Report Abuse Forms CS: assignmentchef QQ: 1823890830 Email: [email protected]
Reviews
There are no reviews yet.