View stunning SlideShares in full-screen with the new iOS app!Introducing SlideShare for AndroidExplore all your favorite topics in the SlideShare appGet the SlideShare app to Save for Later — even offline
View stunning SlideShares in full-screen with the new Android app!View stunning SlideShares in full-screen with the new iOS app!
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))
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))))
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) ;;"A state description is the solution if the everything is on the west" (and (eqv? 'west (side.farmer state)) (eqv? 'west (side.wolf state)) (eqv? 'west (side.goat state)) (eqv? 'west (side.cabbage state))))
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" (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))