#|------------------------------------------------------------------------ the world... bedroom through to hall through to kitchen, lockable doors climable table in kitchen, climable chair in hall, climable bed in bedroom lockable cupboard in bedroom ------------------------------------------------------------------------|# (defparameter *world1* '((connects bedroom hall bedroom-door) (connects hall bedroom bedroom-door) (connects hall kitchen kitchen-door) (connects kitchen hall kitchen-door) (in bedroom-door bedroom) (in bedroom-door hall) (in kitchen-door kitchen) (in kitchen-door hall) (unlocks bdrm-key bedroom-door) (unlocks ktchn-key kitchen-door) (in table kitchen) (climable table) (in chair hall) (climable chair) (in cupboard bedroom) (unlocks cpbd-key cupboard) )) (defparameter *s1* '((in R hall)(has R ktchn-key) (locked bedroom-door) (closed bedroom-door) (locked kitchen-door) (closed kitchen-door) )) (defparameter *mops2* '((move-room (txt . (R moves from ?rm1 to ?rm2)) (pre . ((in R ?rm1) (connects ?rm1 ?rm2 ?door) (open ?door))) (del . ((in R ?rm1))) (add . ((in R ?rm2))) ) (open (txt . (R opens ?x)) (pre . ((in R ?rm)(in ?x ?rm)(closed ?x)(unlocked ?x))) (del . ((closed ?x))) (add . ((open ?x))) ) (closed (txt . (R closes ?x)) (pre . ((in R ?rm)(in ?x ?rm)(open ?x))) (del . ((open ?x))) (add . ((closed ?x))) ) (unlock (txt . (R unlocks ?x)) (pre . ((in R ?rm)(in ?x ?rm)(locked ?x)(unlocks ?key ?x)(has R ?key))) (del . ((locked ?x))) (add . ((unlocked ?x))) ) (lock (txt . (R locks ?x)) (pre . ((in R ?rm)(in ?x ?rm)(unlocked ?x)(unlocks ?key ?x)(has R ?key))) (del . ((unlocked ?x))) (add . ((locked ?x))) ) )) #|------------------------------------------------------------------------ example call explicitly combining world kn & state description > (ops-search ($+ *world1* *s1*) '((in R kitchen)) *mops2*) (((unlocks cpbd-key cupboard) (in cupboard bedroom) (climable chair) (in chair hall) (climable table) (in table kitchen) (unlocks ktchn-key kitchen-door) (unlocks bdrm-key bedroom-door) (in kitchen-door hall) (in kitchen-door kitchen) ...) ((path (R unlocks kitchen-door)) (unlocked kitchen-door) (closed kitchen-door) (closed bedroom-door) (locked bedroom-door) (has R ktchn-key) (in R hall) (connects bedroom hall bedroom-door) (connects hall bedroom bedroom-door) (connects hall kitchen kitchen-door) ...) ((path (R unlocks kitchen-door) (R opens kitchen-door)) (open kitchen-door) (unlocks cpbd-key cupboard) (in cupboard bedroom) (climable chair) (in chair hall) (climable table) (in table kitchen) (unlocks ktchn-key kitchen-door) (unlocks bdrm-key bedroom-door) ...) ((path (R unlocks kitchen-door) (R opens kitchen-door) (R moves from hall to kitchen)) (in R kitchen) (unlocked kitchen-door) (closed bedroom-door) (locked bedroom-door) (has R ktchn-key) (connects bedroom hall bedroom-door) (connects hall bedroom bedroom-door) (connects hall kitchen kitchen-door) (connects kitchen hall kitchen-door) ...)) alternative call using world kn explicitly > (ops-search *s1* '((in R kitchen)) *mops2* :world *world1*) (((in R hall) (has R ktchn-key) (locked bedroom-door) (closed bedroom-door) (locked kitchen-door) (closed kitchen-door)) ((path (R unlocks kitchen-door)) (unlocked kitchen-door) (closed kitchen-door) (closed bedroom-door) (locked bedroom-door) (has R ktchn-key) (in R hall)) ((path (R unlocks kitchen-door) (R opens kitchen-door)) (open kitchen-door) (in R hall) (has R ktchn-key) (locked bedroom-door) (closed bedroom-door) (unlocked kitchen-door)) ((path (R unlocks kitchen-door) (R opens kitchen-door) (R moves from hall to kitchen)) (in R kitchen) (unlocked kitchen-door) (closed bedroom-door) (locked bedroom-door) (has R ktchn-key) (open kitchen-door))) ------------------------------------------------------------------------|# (defparameter *world2* '((connects bedroom hall bedroom-door) (connects hall kitchen kitchen-door) (unlocks bdrm-key bedroom-door) (unlocks ktchn-key kitchen-door) (in table kitchen) (climable table) (in chair hall) (climable chair) (in cupboard bedroom) (unlocks cpbd-key cupboard) )) (defparameter *s2* '((in R hall)(has R ktchn-key) (locked bedroom-door) (locked kitchen-door) )) ;(Rule ?n ??pre => ??post) (defparameter rules '((Rule 1 (connects ?rm1 ?rm2 ?door) => (connects ?rm2 ?rm1 ?door)) (Rule 2 (connects ?rm1 ?rm2 ?door) => (in ?door ?rm1)) (Rule 3 (locked ?x) => (closed ?x)) )) #|------------------------------------------------------------------------ > (forevery ('((connects ?rm1 ?rm2 ?door)) *world2*) #?((connects ?rm2 ?rm1 ?door) (in ?door ?rm1) (in ?door ?rm2))) (((connects hall bedroom bedroom-door) (in bedroom-door bedroom) (in bedroom-door hall)) ((connects kitchen hall kitchen-door) (in kitchen-door hall) (in kitchen-door kitchen))) > (fwd-chain rules *world2*) ((in kitchen-door kitchen) (in bedroom-door hall) (in bedroom-door bedroom) (in kitchen-door hall) (connects kitchen hall kitchen-door) (connects hall bedroom bedroom-door) (connects bedroom hall bedroom-door) (connects hall kitchen kitchen-door) (unlocks bdrm-key bedroom-door) (unlocks ktchn-key kitchen-door) ...) > (ops-search (fwd-chain rules *s2*) '((in R kitchen)) *mops2* :world (fwd-chain rules *world2*)) (((closed kitchen-door) (closed bedroom-door) (in R hall) (has R ktchn-key) (locked bedroom-door) (locked kitchen-door)) ((path (R unlocks kitchen-door)) (unlocked kitchen-door) (locked bedroom-door) (has R ktchn-key) (in R hall) (closed bedroom-door) (closed kitchen-door)) ((path (R unlocks kitchen-door) (R opens kitchen-door)) (open kitchen-door) (closed bedroom-door) (in R hall) (has R ktchn-key) (locked bedroom-door) (unlocked kitchen-door)) ((path (R unlocks kitchen-door) (R opens kitchen-door) (R moves from hall to kitchen)) (in R kitchen) (unlocked kitchen-door) (locked bedroom-door) (has R ktchn-key) (closed bedroom-door) (open kitchen-door))) ------------------------------------------------------------------------|# (defun op-search2 (start goal world ops) (ops-search (fwd-chain rules start) goal ops :world (fwd-chain rules world))) #|------------------------------------------------------------------------ > (op-search2 *s2* '((in R kitchen)) *world2* *mops2*) (((closed kitchen-door) (closed bedroom-door) (in R hall) (has R ktchn-key) (locked bedroom-door) (locked kitchen-door)) ((path (R unlocks kitchen-door)) (unlocked kitchen-door) (locked bedroom-door) (has R ktchn-key) (in R hall) (closed bedroom-door) (closed kitchen-door)) ((path (R unlocks kitchen-door) (R opens kitchen-door)) (open kitchen-door) (closed bedroom-door) (in R hall) (has R ktchn-key) (locked bedroom-door) (unlocked kitchen-door)) ((path (R unlocks kitchen-door) (R opens kitchen-door) (R moves from hall to kitchen)) (in R kitchen) (unlocked kitchen-door) (locked bedroom-door) (has R ktchn-key) (closed bedroom-door) (open kitchen-door))) ------------------------------------------------------------------------|#