I'm using PDDL to generate a plan to solve this tower of Hanoi puzzle. I'll give the problem, the rules, the domain and fact sheet for everything.

PDDL is telling me that the goal can be simplified to false; however, I know for a fact that this puzzle is solvable.


Tower of Hanoi

There are 3 posts. Each has rings on it. From bottom to top on each post. The first post has the second largest ring. The second post has the smallest ring, with the second smallest ring on top of it. The third post has the third largest ring, with the largest ring stacked on top of it.


The rules of this game are that you may only stack a ring on top of a larger ring. Your goal is to get all of the rings onto the same post, stacked from largest to smallest.

My Code


(define (domain hanoi)
  (:requirements :strips)
  (:predicates (clear ?x) (on ?x ?y) (smaller ?x ?y))

  (:action move
    :parameters (?disc ?from ?to)
    :precondition (and (smaller ?to ?disc) (on ?disc ?from) 
               (clear ?disc) (clear ?to))
    :effect  (and (clear ?from) (on ?disc ?to) (not (on ?disc ?from))  
          (not (clear ?to))))


(define (problem hanoi5)
  (:domain hanoi)
  (:objects peg1 peg2 peg3 d1 d2 d3 d4 d5)
    (smaller peg1 d1) (smaller peg1 d2) (smaller peg1 d3)
    (smaller peg1 d4) (smaller peg1 d5)
    (smaller peg2 d1) (smaller peg2 d2) (smaller peg2 d3)
    (smaller peg2 d4) (smaller peg2 d5)
    (smaller peg3 d1) (smaller peg3 d2) (smaller peg3 d3)
    (smaller peg3 d4) (smaller peg3 d5)

    (smaller d2 d1) (smaller d3 d1) (smaller d3 d2) (smaller d4 d1)
    (smaller d4 d2) (smaller d4 d3) (smaller d5 d1) (smaller d5 d2)
    (smaller d5 d3) (smaller d5 d4)

    ;(clear peg2) (clear peg3) (clear d1)
    ;(on d5 peg1) (on d4 d5) (on d3 d4) (on d2 d3) (on d1 d2))
    (clear d2) (clear d4) (clear d1)
    (on d2 peg1) (on d5 peg2) (on d4 d5) (on d3 peg3) (on d1 d3))

  (:goal (and (on d5 d4) (on d4 d3) (on d3 d2) (on d2 d1)))

I'm really at a loss here. Thank you!


Ah hah!

The way I had defined the disks made d5 the LARGEST disk, not the smallest. So, the last few lines of the file should be:

   (clear d4) (clear d2) (clear d5)
    (on d4 peg1) (on d1 peg2) (on d2 d1) (on d3 peg3) (on d5 d3))

  (:goal (and (on d1 d2) (on d2 d3) (on d3 d4) (on d4 d5)))


If I wanted the opposite to be true, d1 to be the largest, the changes would have been as following:

; Swapped ?disc & ?to in (smaller ...) statement
:precondition (and (smaller ?disc ?to) (on ?disc ?from) 


; Swapped all d* and peg* objs within (smaller ...) staements
(smaller d1 peg1) (smaller d2 peg1) (smaller d3 peg1)
(smaller d4 peg1) (smaller d5 peg1)
(smaller d1 peg2) (smaller d2 peg2) (smaller d3 peg2)
(smaller d4 peg2) (smaller d5 peg2)
(smaller d1 peg3) (smaller d2 peg3) (smaller d3 peg3)
(smaller d4 peg3) (smaller d5 peg3)



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.