EX4.3 GPSを「うっかり目標達成」に対応 その1

4章で定義したGPSは複数の目標を指定した場合、ある目標達成によって他の目標が部分的に達成できる場合をうまく扱っていない。これを修正する問題。

まずは、その様なシチュエーションをオペレータのセットで定義する。

;; Exercise 4.3[h] GPS does not recognize the situation where a goal
;; is accidentally solved as part of achieving another goal. Consider
;; the goal of eating dessert. Assume that there are two operators
;; available: eating ice cream (which requires having the ice cream)
;; and eating cake (which requires having the cake). Assume that we
;; can buy a cake, and that the bakery has a deal where it gives out
;; free ice cream to each customer who purchases and eats a cake.  
;;
;; (1) Design a list of operators to representation this situation.
;; (2) Give gps the goal of eating dessert. Show that, with the right
;; this of operators, gps will decide to eat ice cream, then decide to
;; buy and eat the cake in order to get the free ice cream, and then
;; go ahead and eat the ice cream, even though the goal of eating
;; dessert has already been achieved by eating the cake.
;; (3) Fix gps so that it does not manifest the problem.
(use-package :paip.gpsv2)

(defparameter *eating-op*
  (list
   (op 'eating-ice-cream 
       :preconds '(having-ice-cream)
       :add-list '(eat-ice-cream)
       :del-list '(having-ice-cream))
   (op 'eating-cake
       :preconds '(having-cake)
       :add-list '(haveing-ice-cream eat-cake)
       :del-list '(having-cake))
   (op 'buy-cake
       :preconds '(have-money)
       :add-list '(having-cake)
       :del-list '(have-money))
   (op 'buy-ice-cream
       :preconds '(have-money)
       :add-list '(having-ice-cream)
       :del-list '(have-money))
  "デザートを食べる")

4章で定義したGPSだと解決出来ないことを確認。

CL-USER> (paip.aux:indebug :gps)
(:GPS)
CL-USER> (gps '(have-money) '(eat-cake eat-ice-cream) *eating-op*)
Goal: EAT-CAKE
Consider: EATING-CAKE
  Goal: HAVING-CAKE
  Consider: BUY-CAKE
    Goal: HAVE-MONEY
  Action: BUY-CAKE
Action: EATING-CAKE
Goal: EAT-ICE-CREAM
Consider: EATING-ICE-CREAM
  Goal: HAVING-ICE-CREAM
Goal: EAT-ICE-CREAM
Consider: EATING-ICE-CREAM
  Goal: HAVING-ICE-CREAM
NIL

これを修正するのは次回で。

追記

スペルミスしてた…。

   (op 'eating-cake
       :preconds '(having-cake)
       :add-list '(haveing-ice-cream eat-cake)
       :del-list '(having-cake))

haveing-ice-creamになっていたので失敗していた模様。
having-ice-creamに修正したら解決出来るようになった…。

(setf *eating-op*
  (list
   (op 'eating-ice-cream 
       :preconds '(having-ice-cream)
       :add-list '(eat-ice-cream)
       :del-list '(having-ice-cream))
   (op 'eating-cake
       :preconds '(having-cake)
       :add-list '(having-ice-cream eat-cake)
       :del-list '(having-cake))
   (op 'buy-cake
       :preconds '(have-money)
       :add-list '(having-cake)
       :del-list '(have-money))
   (op 'buy-ice-cream
       :preconds '(have-money)
       :add-list '(having-ice-cream)
       :del-list '(have-money))))

実行結果。

CL-USER> (gps '(have-money) '(eat-ice-cream eat-cake) *eating-op*)
Goal: EAT-ICE-CREAM
Consider: EATING-ICE-CREAM
  Goal: HAVING-ICE-CREAM
  Consider: BUY-ICE-CREAM
    Goal: HAVE-MONEY
  Action: BUY-ICE-CREAM
Action: EATING-ICE-CREAM
Goal: EAT-CAKE
Consider: EATING-CAKE
  Goal: HAVING-CAKE
  Consider: BUY-CAKE
    Goal: HAVE-MONEY
Goal: EAT-CAKE
Consider: EATING-CAKE
  Goal: HAVING-CAKE
  Consider: BUY-CAKE
    Goal: HAVE-MONEY
  Action: BUY-CAKE
Action: EATING-CAKE
Goal: EAT-ICE-CREAM
Consider: EATING-ICE-CREAM
  Goal: HAVING-ICE-CREAM
Action: EATING-ICE-CREAM
((PAIP.GPSV2::START)
 (PAIP.GPSV2::EXECUTING BUY-CAKE)
 (PAIP.GPSV2::EXECUTING EATING-CAKE)
 (PAIP.GPSV2::EXECUTING EATING-ICE-CREAM))
CL-USER> 

Ex4.3はGPSV2だと既に解決済みの問題なのかなぁ。