PDS by sdaferv


More Info
									PDS Week 8 Practical Answers
1. (a) Constructing a Search Tree Trace for the Breadth-First Search


Trace for the Depth-First Search

2. Completing a Formalisation
(a) (b) Initial state = (1,1,1), Goal state = (3,3,3) # Property of Given State 1 2 3 4 (1,3,3) (x,y,z) where z != 2 (x,y,z) where z != 1 (x,y,z) where z != 3 Description New State (2,3,3)

Move big disk to middle

Move small disk to middle (x,y,2) Move small disk to left Move small disk to right (x,y,1) (x,y,3)

5 6 7 8 9 10 11 12

(3,1,1) (2,3,3) (3,2,2) (2,1,1) (1,2,2) (x,y,z) where y != 1 and y != z (x,y,z) where y != 2 and y != z (x,y,z) where y != 3 and y != z

Move big disk to middle Move big disk to left Move big disk to left Move big disk to right Move big disk to right Move middle disk to left Move mid disk to middle Move mid disk to right

(2,1,1) (1,3,3) (1,2,2) (3,1,1) (3,2,2) (x,1,z) (x,2,z) (x,3,z)


Developing a Formalisation

Representing States We denote the banks of the river "near side" and "far side". Initially, all missionaries, cannibals and boat are on the near side, the goal is for all to be on the far side. Let a state be represented by a tuple of 5 values (mn, cn, mf, cf, boat_pos), where
  

mn and cn denote the number of missionaries and cannibals respectively on the near side, and mf and cf denote the number of missionaries and cannibals respectively on the far side, and boat_pos denotes the location of the boat.

The location of the boat is represented by a value from the set {near, far}. Thus the initial problem state is (3, 3, 0, 0, near) and the goal state is (0, 0, 3, 3, far). Actually, (0, 0, 3, 3, near) is an acceptable goal state too, however it's impossible to achieve.

Describing possible actions An action involves moving at least one missionary or cannibal from one bank to the other. An action is permitted if it does not result in the missionaries on a particular bank being outnumbered by cannibals. Given that the boat holds up to 2 people, the permutations are 1 missionary, 1 cannibal, 1 missionary and 1 cannibal, 2 missionaries, 2 cannibals. We can develop a set of actions based on these.


Property of Given State (mn,cn, mf, cf, boat_pos)


Action (new state) (mn-1,cn, mf+1, cf, far)

Send one 1 boat_pos=near∧mn>0∧mn>cn∧(mf+1)≥cf missionary to the far bank. Send two 2 boat_pos=near∧mn>1∧(mn-2)≥cn∧(mf+2)≥cf missionaries to the far bank. Send one missionary and one 3 boat_pos=near∧mn>0∧cn>0∧mf≥cf cannibal to the far bank. Send two cannibals 4 boat_pos=near∧cn>1∧mf≥(cf+2) to the far bank. Send one cannibal 5 boat_pos=near∧cn>0∧mf≥(cf+1) to the far bank. Bring back one 6 boat_pos=far∧mf>0∧mf>cf∧(mn+1)≥cn missionary. Bring back two 7 boat_pos=far∧mf>1∧(mf-2)≥cf∧(mn+2)≥cn missionaries. Bring back one 8 boat_pos=far∧mf>0∧cf>0∧mn≥cn missionary and one cannibal. Bring back two 9 boat_pos=far∧cf>0∧mn≥(cn+2) cannibals. Bring back one 10 boat_pos=far∧cf>1∧mn>cn) cannibal.

(mn-2,cn, mf+2, cf, far)

(mn-1,cn-1, mf+1, cf+1, far) (mn,cn-2, mf, cf+2, far) (mn,cn-1, mf, cf+1,far) (mn+1,cn, mf-1, cf, near) (mn+2,cn, mf-2, cf, near) (mn+1,cn+1, mf-1, cf-1, near) (mn,cn+1, mf, cf-2, near) (mn,cn+1, mf, cf-1, near)


Coding it in Java

Possible code is given in the file www.dur.ac.uk/m.n.c.rhodes/WaterJugStateSpaceSearch.java. Note: If you didn’t finish this question do look at this and try and understand it.

To top