Answers.Body: <h1>Ah hah!</h1>
  
  <p>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:</p>
  
  <pre><code>   (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)))
  )
  </code></pre>
  
  <h1>However</h1>
  
  <p>If I wanted the opposite to be true, d1 to be the largest, the changes would have been as following:</p>
  
  <pre><code>; Swapped ?disc &amp; ?to in (smaller ...) statement
  :precondition (and (smaller ?disc ?to) (on ?disc ?from) 
  </code></pre>
  
  <h3>And</h3>
  
  <pre><code>; 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)
  </code></pre>
  
  <p>:)</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-26T07:46:19.933Z
Answers.LastActivityDate: 2020-03-26T07:46:19.933Z
Answers.UserDisplayName: Michael
Body: <p>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.</p>
  
  <p>PDDL is telling me that the goal can be simplified to false; however, I know for a fact that this puzzle is solvable.</p>
  
  <h3>Puzzle:</h3>
  
  <p><a href="https://i.sstatic.net/W9dQF.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/W9dQF.png" alt="Tower of Hanoi"></a></p>
  
  <blockquote>
    <p>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.</p>
  </blockquote>
  
  <h3>Rules:</h3>
  
  <blockquote>
    <p>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.</p>
  </blockquote>
  
  <h1>My Code</h1>
  
  <h3>Domain</h3>
  
  <pre><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))))
    )
  </code></pre>
  
  <h3>Problem</h3>
  
  <pre><code>(define (problem hanoi5)
    (:domain hanoi)
    (:objects peg1 peg2 peg3 d1 d2 d3 d4 d5)
    (:init 
      (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)))
  )
  </code></pre>
  
  <p>I'm really at a loss here. Thank you!</p>
  
Tags: <planning><pddl>
Title: Can't solve Towers of Hanoi in PDDL
UserDisplayName: Michael
ThreadText: # Can't solve Towers of Hanoi in PDDL
  
  (Asked by: username_0 on 2020-03-26)
  
  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.
  
  ### Puzzle:
  
  [![Tower of Hanoi](https://i.sstatic.net/W9dQF.png)](https://i.sstatic.net/W9dQF.png)
  
  > 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.
  
  ### Rules:
  
  > 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
  
  ### Domain
  
  ```
  (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))))
    )
  
  ```
  
  ### Problem
  
  ```
  (define (problem hanoi5)
    (:domain hanoi)
    (:objects peg1 peg2 peg3 d1 d2 d3 d4 d5)
    (:init 
      (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!
  
  **Tags:** planning, pddl
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2020-03-26. Score: 1 | Accepted answer
  
  # 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)))
  )
  
  ```
  
  # However
  
  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) 
  
  ```
  
  ### And
  
  ```
  ; 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)
  
  ```
  
  :)
  
  
  ---
  
  