University of Calgary
Rob Kremer
Example Solution: And Tree/
Towers of Hanoi


CPSC 433: Artifical Intelligence
Department of Computer Science
Computer
Science

Model

Note that we are modeling the problem as a tower to move to another spindle with only ONE spindle having any disks on it.  It may be in the overall picture, there are disks on other spindles, but those are always ignored and treated like the base.  Thus, a problem is always to move n spindles to the spindle.

A: (S,T)
S: Atree
Atree: (pr, sol:{yes,?}, b1:Atree, ... ,bn:Atree), n>=0
Tower: seq Nat | ∀ x,y ∈ Tower • ((x=y) → (ord x = ord y)) /\ ((ord x < ord y) → (y > x)) // A Tower is a sequence of numbers (disks) with no duplicates with only smaller on larger disks
pr: {(T1:Tower, T2:Tower, T3:Tower, d:{1,2,3}) |
∃ i, j | i≠j /\ j≠n . Ti≠<<>> /\ Tn=<<>> /\ Tj=<<>> } // A problem is a 3 spindles with a tower on one and the other spindles are empty, together with a target spindle (which is empty).  Note that it could be that i=n, which means the problem is solved.

Div: pr+
Div = ((T1, T2, T3, n), ((T'1, T'2, T'3, n'), (T"1, T"2, T"3, n"), (T'''1, T'''2, T'3, n''')) where 
    ∃ i, j | i≠j /\ j≠n /\ i≠n /\ Ti≠<<>> /\ Tn=<<>> /\ Tj=<<>> .
         T'i = tail Ti /\ T'j = <<>> /\ T'n == <<>> /\ n' = j

         T"i = << head Ti >> /\ T"j = <<>> /\ T"n == <<>> /\ n" = n
         T'''i = <<>> /\ T'''j = tail Ti /\ T'''n == <<>> /\ n''' = n
// Ti is the stack, Tn is the target.  Move all but the bottom disk to Tj; move the bottom disk to Tn; then move Tj to Tn.
 
T: S x S,
T= {(s1, s2) | s1 ∈ S /\ s2 ∈ S . Erw (s1, s2) \/ Erw* (s2, s1)}
Erw((pr, ?), (pr, yes)) \/ // mark solved
Erw((pr, ?), (pr, ?, (pr1, ?), ..., (prn, ?))) \/ // divide the problem into children
Erw((pr, ?, b1, ..., bn), (pr, ?, b1', ..., bn')), ∃1 j | j ≤ n • ∀ i | i ≠ j • Erw(bj, bj'), /\ bi = bi' // choose a child to work on
Erw*((pr, ?, , b1, ... , bn), (pr, ?, , b1', ... , bn')), ∀ i • Erw*(bi, bi') \/ bi' = bi' // backtrack //This is not needed for this problem
ErwmarkSolved((T1, T2, T3, n)) = Tn<<>>
Erwdivide= (pr, ?) → (pr, ?, Div(pr))
Erwchoose= <random>
Erw* = <never backtrack >

Process

P: (A, Env, K)
Env: (none)
K: S x Env → S
K(s,env) = apply Erw until we can mark the root as solved.

Search Instance (Example)

Ins = (s0, G)
s0= (<<3 2 1>>, <<>>, <<>>)
G: s → {yes,no}
G = {s → x | s ∈ sgoal /\ x=yes \/ x=no}

sgoal ⊆ s \/ no more expansions possible
sgoal= {(<<>>, <<>>, <<3 2 1>>)}

Example Diagram

                                                                                                         (<<3 2 1>>, <<>>, <<>>, 3)
                                                                                                    /                            |                       \ 
                                                             (<<2 1>>, <<>>, <<>>, 2)  (<<3>>, <<>>, <<>>, 3)   (<<>>, <<2 1>>, <<>>, 3)
                                        /                                   |                \                               yes                         /                      |                                    \
(<<1>>, <<>>, <<>>, 3)  (
<<2>>, <<>>, <<>>, 2)   (<<>>, <<>>, <<1>>, 2)    (<<>>, <<1>>, <<>>, 1)  (<<>>, <<2>>, <<>>, 3)   (<<1>>, <<>>, <<>>, 3)
              yes                                       yes                                         yes                                yes                                       yes                                         yes




CPSC 433: Arficial Intelligence
Department of Computer Science

Last updated 2013-09-01 15:45
Rob Kremer