Ex4.4 The Not Looking after You Don't Leap Problem. その1
4章で定義してGPSは最初に見つけたパスでゴールを達成しようとするので、別のオペレータの組み合わせではゴールが達成可能でもそっちは参照しない問題があります。
これを修正するExerciseです。
;; Exercise 4.4[h] The Not Looking after You Don't Leap Problem. Write ;; a program that keeps track of the remaining goals so that it does ;; not get stuck considering only one possible operation when others ;; will eventually lead to the goal. ;; ;; Hint: have achieve take an extra argument including the goals that ;; remain to be achieved after the current goal is achieved. achieve ;; should succeed only if it can achieve the current goal and also ;; achieve-all the remaining goals.
とりあえず確認。
(defpackage :scool-op (:use :cl :paip.gpsv2)) (in-package :scool-op) (defparameter *school-ops* (list (op 'taxi-sun-to-school :preconds '(son-at-home have-money) :add-list '(son-at-school) :del-list '(son-at-home have-money)) (op 'drive-son-to-school :preconds '(son-at-home car-works) :add-list '(son-at-school) :del-list '(son-at-home)) (op 'shop-installs-battery :preconds '(car-needs-battery shop-knows-problem shop-has-money) :add-list '(car-works)) (op 'tell-shop-problem :preconds '(in-communication-with-shop) :add-list '(shop-knows-problem)) (op 'telephone-shop :preconds '(know-phone-number) :add-list '(in-communication-with-shop)) (op 'look-up-numebr :preconds '(have-phone-book) :add-list '(know-phone-number)) (op 'give-shop-money :preconds '(have-money) :add-list '(shop-has-money) :del-list '(have-money)))) (gps '(son-at-home have-money car-works) '(son-at-school have-money) *school-ops*) ;; => NIL
drive-son-to-schoolを実行すれば、ここでのゴールは達成できますが、taxi-son-to-schoolをまず選択してしまうため、have-moneyが達成出来ません。
drive-son-to-schoolをtaxi-son-to-schoolの前に移動すれば達成できますが、いちいち考えるのは面倒です。4.16節でこの問題について考えていますが、解決方法は2つあります。
- 総当たり
- ゴールを保護
総当たりは、達成失敗したら次の選択可能なオペレータを選択する方法です。
ゴールを保護は、今回の場合have-moneyが消費されないようにする方法です。
このExcersieでは2番目の方法で解決します。
その2に続く