;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; ;; SHOPPING AND EATING IN A 2-POINT GRIDWORLD ;; ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; We define a small Gridworld with 2 places (home, plaza1) connected ;; by road1. The robot ME is initially at home, and has no money and ;; is hungry. One of his actions is 'sleep'; this requires that he be ;; tired to at least degree 0.5 (the maximum being 1.0) and that he ;; not be hungry, and and has the effect that he wakes up hungry but ;; not at all tired. He *knows* that there is an ATM (atm1) at plaza1 ;; and he has $20 on his account. (These facts are supplied as part ;; of ME's knowledge when placing him at home). The ATM allows ;; withdrawals of $10 at a time (using a 'withdraw_from' operator). ;; There is also a pizza-place (dominos1) at the plaza, and ME knows ;; about that, as well (from the initial knowledge supplied to him). ;; He can walk to the plaza, which will make him more tired (adding ;; .5 to his level of fatigue). Buying a pizza costs $6 (thus leaving ;; him with $4, if he starts with $10). Eating a pizza will make ME ;; not-hungry. ME can eat at the plaza, but can't sleep there, only ;; at home. So if he wants to sleep, he needs to walk back home ;; first, which will of course make him more tired (by an amount .5). ;; First (load "gridworld-definitions.lisp") ;; and (load "gridworld-planning.lisp") ;; and then (load "eg-shopping-world1-2008.lisp") ;; (which is this file) ;; Possible continuation: ;; (initialize-state) ;; (go!) (def-roadmap '(home plaza1) '((road1 home plaza1))); 2 points, 1 road (def-object 'robot '(is_animate can_talk)); properties not actually used (def-object 'atm '(is_inanimate)) (def-object 'pizza-place '(is_inanimate)) (def-object 'pizza '(is_inanimate)) (place-object 'ME 'robot 'home 0 nil ; no associated-things ;; Note that we create some "current facts" about ;; ME that are really about the situation at plaza1; ;; this is just a way of ensuring that ME knows these ;; facts right at the outset: '((hungry me) (has_dollars me 0) (is_at atm1 plaza1) (atm atm1) (is_tired_to_degree me 0) (retains_dollars_for atm1 me 20) (is_at dominos1 plaza1) (pizza-place dominos1) ) nil) ; no propositional attitudes (place-object 'atm1 'atm 'plaza1 0 nil ; no associated objects '((retains_dollars_for atm1 me 20)) nil ) ; no prop. attitudes (place-object 'dominos1 'pizza-place 'plaza1 0 nil ; no associated-things nil nil ); no current facts or prop.att.'s (setq eat (make-op :name 'eat :pars '(?x ?y ?z); ?x eats ?y at ?z :preconds '((is_at ?x ?z) (is_at ?y ?z) (edible ?y) (hungry ?x)) :effects '((not (is_at ?y ?z)) (not (edible ?y)) (not (hungry ?x)) ) :time-required 1 :value 2 )); NB: happiness independent of eater (setq sleep (make-op :name 'sleep :pars '(?t); level of fatigue ?t ; {0, 0.5, 1.0, 1.5, ...} :preconds '((is_at me home) (not (hungry me)) (is_tired_to_degree me ?t) (>= ?t .5) ) :effects '((hungry me) (is_tired_to_degree me 0) (not (is_tired_to_degree me ?t))) :time-required '(* 4 ?t) :value '(* 3 ?t) )) (setq walk (make-op :name 'walk :pars '(?x ?y ?z ?t); walk from point ?x :preconds '((is_at ME ?x) ;to point ?y on road ?z, (is_on ?x ?z) ;with initial fatigue ?t (is_on ?y ?z) (is_tired_to_degree me ?t) ) :effects '((is_at ME ?y) (not (is_at ME ?x)) (is_tired_to_degree me (+ ?t 0.5)) (not (is_tired_to_degree me ?t)) ) :time-required 1 :value '(- 2 ?t) )) (setq withdraw_from (make-op :name 'withdraw_from :pars '(?atm ?loc ?bal ?amt) ; From ATM ?atm at ?loc withdraw $10, where the ; initial balance is ?bal, and ME initially has $ ?amt :preconds '((atm ?atm) (is_at ?atm ?loc) (is_at me ?loc) (has_dollars me ?amt) (retains_dollars_for ?atm me ?bal) (>= ?bal 10) ) :effects '((retains_dollars_for ?atm me (- ?bal 10)) (not (retains_dollars_for ?atm me ?bal)) (has_dollars me (+ ?amt 10)) (not (has_dollars me ?amt)) ) :time-required 1 :value 0 )) (setq buy_pizza_from (make-op :name 'buy_pizza_from :pars '(?store ?loc ?amt) ; From pizza-place ?store at ?loc buy a pizza, ; where ME initially has $?amt; the pizza obtained ; is assumed to be the same 'pizza1' each time, ; but this doesn't matter -- think of it as ; reincarnation (:-) :preconds '((pizza-place ?store) (is_at ?store ?loc) (is_at me ?loc) (has_dollars me ?amt) (>= ?amt 6) ) :effects '((is_at pizza1 ?loc) (edible pizza1) (has_dollars me (- ?amt 6)) (not (has_dollars me ?amt)) ) :time-required 1 :value 1 )) (setq *operators* '(eat sleep walk withdraw_from buy_pizza_from)) (setq *search-beam* (list (cons 5 *operators*) (cons 4 *operators*) (cons 3 *operators*) )) ;; THE STATE-VALUE FUNCTION HERE IS PRESUMED TO BE THE GENERIC ONE ;; IN `gridworld-planning.lisp'. ;; SAMPLE RUN: ;;============= ;; ;;;; First (load "gridworld-definitions.lisp") ;;;;; and (load "gridworld-planning.lisp") ;;;;; and then (load "eg-shopping-world1-2008.lisp") ;;; ; CL-USER(1): (load "gridworld-definitions.lisp") ; ; Loading ; ; /home/vax3/u18/schubert/290/07/projects/gridworld/gridworld-notime.lisp ; T ; CL-USER(2): (load "gridworld-planning.lisp") ; ; Loading /home/vax3/u18/schubert/290/07/projects/gridworld/develop.lisp ; T ; CL-USER(3): (load "eg-shopping-world1-2008.lisp") ; ; Loading ; ; /home/vax3/u18/schubert/290/07/projects/gridworld/eg-eating-world3.lisp ; T ; CL-USER(4): (initialize-state) ; ; ; ; ; CL-USER(5): (go!) ; ; ; CL-USER(6): (go!) ; ; ; CL-USER(7): (go!) ; ; ; CL-USER(8): (go!) ; ; ; CL-USER(9): (go!) ; ; ; CL-USER(10): (go!) ; ; ; CL-USER(11): (go!)