Created
October 31, 2018 19:14
-
-
Save Lokno/56f17aae52a98a87caf386a7af946a2a to your computer and use it in GitHub Desktop.
Python script to generate a PDDL format problem for the hanoi problem. For use with hanoi-domain.pddl.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| num_disks = 15 | |
| num_pegs = 3 | |
| disks = ['disk%d' % (i+1) for i in range(num_disks)] | |
| pegs = ['peg%d' % (i+1) for i in range(num_pegs)] | |
| filename = 'hanoi-problem.pddl' | |
| init = ['(clear disk1)'] | |
| goals = ['(clear disk1)'] | |
| for i in range(1,num_pegs): | |
| init.append('(clear peg%d)' % (i+1)) | |
| for i in range(num_pegs-1): | |
| goals.append('(clear peg%d)' % (i+1)) | |
| for i in range(num_disks-1): | |
| temp_str = '(on disk%d disk%d)' % (i+1,i+2) | |
| init.append(temp_str) | |
| goals.append(temp_str) | |
| init.append('(on disk%d peg%d)' % (num_disks,1)) | |
| goals.append('(on disk%d peg%d)' % (num_disks,num_pegs)) | |
| for i in range(num_disks-1): | |
| for j in range(i+1,num_disks): | |
| init.append('(smaller disk%d disk%d)' % (i+1,j+1)) | |
| for i in range(num_pegs): | |
| for j in range(num_disks): | |
| init.append('(smaller disk%d peg%d)' % (j+1,i+1)) | |
| problemstr = '''(define (problem hanoi-problem) (:domain hanoi-domain) | |
| (:objects | |
| %s - disk | |
| %s - peg | |
| ) | |
| (:init | |
| (= (cost) 0) | |
| %s | |
| ) | |
| (:goal | |
| (and | |
| %s | |
| ) | |
| ) | |
| (:metric minimize(cost)) | |
| )''' % ( ' '.join(disks), ' '.join(pegs), '\n '.join(init), '\n '.join(goals) ) | |
| with open(filename,"w") as f: | |
| f.write(problemstr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment