第7章 Model for TOH


Tower of Hanoiを解決するモデルの概要を以下に示します。


ルール概要

Rule 1

Rule 2

Rule 3

Rule 4

Rule 5

Rule 6

Rule 7


モデルコード
以下のワーキングメモリ,ルールをプロダクションシステムにインポートし,ルールの@1から@29を適当な記号に置き換えて,モデルを完成せよ。
■ワーキングメモリ:テスト課題1
- (1 C)
- (2 B)
- (3 C)
- (4 C)
- (5 B)
- (6 C)
- (A (99))
- (B (2 5 99))
- (C (1 3 4 6 99))
■ワーキングメモリ:テスト課題2
- (1 A)
- (2 B)
- (3 B)
- (4 A)
- (5 C)
- (6 B)
- (A (1 4 99))
- (B (2 3 6 99))
- (C (5 99))

■ルール
- name: rule1
  if:
  - (B ?listb)
  - (A ?lista)
  - (*test-equal (TEMP1) TEMP2)
  - (*test-equal (TEMP3) TEMP4)
  then:
  - (*deposit (Problem-Solved))
  - (*halt)
  
- name: rule2
  if:
  - (State DONE)
  - (Goal (DMove ?disk ?peg))
  then:
  - (*delete (State TEMP5))
  - (*delete (Goal (DMove ?disk ?peg)))
  - (*deposit (Goal (DMove (*minus TEMP6 TEMP7) TEMP8)))
  
- name: rule3
  if:
  - (Goal (DMove ?disk ?peg-a))
  - (State CAN)
  - (?disk ?peg-b)
  - (?peg-a ?lista)
  - (?peg-b ?listb)
  then:
  - (*delete (State CAN))
  - (*delete (Goal (DMove ?disk ?peg-a)))
  - (*delete (?disk TEMP9))
  - (*deposit (?disk TEMP10))
  - (*delete (TEMP11 ?listb))
  - (*deposit (TEMP12 (*remove TEMP13 TEMP14)))
  - (*delete (?peg-a ?lista))
  - (*deposit (?peg-a (*cons TEMP15 TEMP16)))
  
- name: rule4
  if:
  - (Goal (DMove ?disk ?peg-a))
  - (State CANT ?blockingdisk)
  - (?disk ?peg-b)
  then:
  - (*delete (State CANT ?blockingdisk))
  - (*deposit (Goal (DMove TEMP17 (*hanoi-otherpeg TEMP18 TEMP19))))
  
- name: rule5a(test->done)
  if:
  - (Goal (DMove ?disk ?peg-a))
  - (TEMP20 TEMP21)
  then:
  - (*deposit (State DONE))
  
- name: rule5b(test->can)
  if:
  - (Goal (DMove ?disk ?peg-a))
  - (?disk ?peg-b)
  - (?peg-b ?listb)
  - (?peg-a ?lista)
  - (*test-equal ?disk (*first TEMP22))
  - (*test-smaller ?disk (*first TEMP23))
  then:
  - (*deposit (State CAN))
  
- name: rule5c(test->cant)
  if:
  - (Goal (DMove ?disk ?peg-a))
  - (?disk ?peg-b)
  - (?peg-a ?lista)
  - (?peg-b ?listb)
  then:
  - (*deposit (State CANT (*hanoi-findblockingdisk TEMP24 TEMP25 TEMP26)))
  
- name: rule6
  if:
  - (Biggest ?disk)
  then:
  - (*delete (Biggest ?disk))
  - (*deposit (Goal (DMove TEMP27 C)))
  
- name: rule7
  if:
  - (A ?lista)
  - (B ?listb)
  then:
  - (*deposit (Biggest (*hanoi-biggest TEMP28 TEMP29)))