0
Upcoming SlideShare
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Standard text messaging rates apply

# State Space Search(2)

3,265

Published on

1 Like
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

Views
Total Views
3,265
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
65
0
Likes
1
Embeds 0
No embeds

No notes for slide

### Transcript

• 1. State Space Search • Readings: Rich and Knight: Sect 2.1
• 2.
• 3.
• 4.
• 5.
• 6.
• 7.
• 8.
• 9.
• 10. Train Problem • State Representation: A Lisp atom: the current city • Initial State (define *start-state* 'sacramento) • Goal State (define *goal-state* 'austin.texas) (define (solution-state? s) (eqv? s *goal-state*)) • Operators (50) – Go from neighboring capitals to each capital (define *state-operators* (list goto-atlanta goto-montgomery goto-juneau goto-phoenix goto-sacramento goto-santa-fe goto-austin)) (define (goto-montgomery state) (if (member state '(juneau atlanta)) 'montgomery #f))
• 11. Farmer Wolf Goat and Cabbage problem A problem description consists of ;;;1. A structure to represent the state description: jug-contents A fixed sized data structure comprised of a number of fields • (defstruct name field-1 field-2 ... fieldn) defines a structure (defstruct side farmer wolf goat cabbage) => side ;;;2. A list of operators: *jug-problem-operators* ;;; These functions define legal moves in the state space (define *farmer-wolf-goat-cabbage-operators* '(farmer-takes-self farmer-takes-wolf farmer-takes-goat farmer-takes-cabbage)) ;;;3. A definition of each operator: ;;; An operator is a scheme function, that given a state description, returns a new ;;; state description (Or null if the operator can't be applied) (define (farmer-takes-self state) (safe (make-side 'farmer (opposite (side.farmer state)) 'wolf (side.wolf state) 'goat (side.goat state) 'cabbage (side.cabbage state))))
• 12. A particular problem requires ;;;.1. A start state (define *start-state* (make-side 'farmer 'east 'wolf 'east 'goat 'east 'cabbage 'east)) ;;;2. A function to determine whether a state is the goal state. ;;; By covention, we'll call this (solution-state? x) (define (solution-state? state) ;;&quot;A state description is the solution if the everything is on the west&quot; (and (eqv? 'west (side.farmer state)) (eqv? 'west (side.wolf state)) (eqv? 'west (side.goat state)) (eqv? 'west (side.cabbage state))))
• 13. Water Jug Problem State Representation • State Representation (defstruct jug-contents four three) • Initial State (define *start-state* (make-jug-contents 'three 0 'four 0)) • Goal State ;;A state description is the solution if the four galloon jug has 2 gallons in it&quot; (define (solution-state? state) (= 2 (jug-contents.four state))) • A list of operators (define *jug-problem-operators* '(fill-four fill-three dump-four dump-three fill-four-from-three fill-three-from-four empty-three-into-four empty-four-into-three))
• 14. • Operator 1 (define (fill-four state) (when (< (jug-contents.four state) 4) (make-jug-contents 'three (jug-contents.three state) 'four 4)))
• 15. Applying the operators
• ? *start-state*
• #S(JUG-CONTENTS :FOUR 0 :THREE 0)
• ? (fill-four *start-state*)
• #S(JUG-CONTENTS :FOUR 4 :THREE 0)
• ? (fill-three-from-four (fill-four *start-state*))
• #S(JUG-CONTENTS :FOUR 1 :THREE 3)
• ? (fill-three-from-four
• (fill-four
• (empty-four-into-three
• (dump-three
• (fill-three-from-four
• (fill-four *start-state*))))))
• #S(JUG-CONTENTS :FOUR 2 :THREE 3)
• ? (solution-state? (fill-three-from-four
• (fill-four
• (empty-four-into-three
• (dump-three
• (fill-three-from-four
• (fill-four *start-state*)
• ))))))