Skip to content

Commit

Permalink
[gripper] randomizable python implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
guicho271828 committed Nov 28, 2021
1 parent 9bf57e1 commit a5564af
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions gripper/gripper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env python

import argparse
import random

parser = argparse.ArgumentParser()

parser.add_argument("balls", type=int, help="the number of balls")
parser.add_argument("--seed", "-s", type=int, help="random seed")
parser.add_argument("--randomize", "-r", action="store_true", help="randomize the initial state and the goal if present")

args = parser.parse_args()

random.seed(args.seed)

def init():
# static
facts = ["(room rooma)","(room roomb)", "(gripper left)", "(gripper right)"]
for i in range(args.balls):
facts.append(f"(ball ball{i})")

# fluents
facts.extend(["(free left)", "(free right)"])

if args.randomize:
for i in range(args.balls):
room = random.choice(["rooma","roomb"])
facts.append(f"(at ball{i} {room})")
room = random.choice(["rooma","roomb"])
facts.append(f"(at-robby {room})")
else:
for i in range(args.balls):
facts.append(f"(at ball{i} rooma)")
facts.append(f"(at-robby rooma)")

return " ".join(facts)


def goal():
facts = []
if args.randomize:
for i in range(args.balls):
room = random.choice(["rooma","roomb"])
facts.append(f"(at ball{i} {room})")
else:
for i in range(args.balls):
facts.append(f"(at ball{i} roomb)")

return " ".join(facts)


print("(define (problem gripper)")
print(" (:domain gripper-strips)")
print(" (:objects rooma roomb left right " + " ".join([f"ball{i}" for i in range(args.balls)]) + ")")
print(" (:init " + init() + ")")
print(" (:goal (and " + goal() + ")))")

0 comments on commit a5564af

Please sign in to comment.