diff --git a/gripper/gripper.py b/gripper/gripper.py new file mode 100755 index 00000000..de0c101c --- /dev/null +++ b/gripper/gripper.py @@ -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() + ")))") diff --git a/grippers/README b/grippers/README new file mode 100644 index 00000000..b36e353f --- /dev/null +++ b/grippers/README @@ -0,0 +1,20 @@ + +# Grippers (python) + +usage: gripper.py [-h] [--seed SEED] balls robots grippers rooms + +positional arguments: + balls the number of balls + robots the number of robots + grippers the number of grippers per robot + rooms the number of rooms + +optional arguments: + -h, --help show this help message and exit + --seed SEED, -s SEED random seed + + +# Grippers (C language) + + +This version is equivalent to the python version with 2 grippers per robot. diff --git a/grippers/gripper.py b/grippers/gripper.py new file mode 100755 index 00000000..4e883857 --- /dev/null +++ b/grippers/gripper.py @@ -0,0 +1,60 @@ +#!/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("robots", type=int, help="the number of robots") +parser.add_argument("grippers", type=int, help="the number of grippers per robot") +parser.add_argument("rooms", type=int, help="the number of rooms") +parser.add_argument("--seed", "-s", type=int, help="random seed") + +args = parser.parse_args() + +random.seed(args.seed) + +robots = [f"robot{i}" for i in range(args.robots)] +rooms = [f"room{i}" for i in range(args.rooms)] +grippers = [f"gripper{i}" for i in range(args.grippers)] +balls = [f"ball{i}" for i in range(args.balls)] + + + +def init(): + facts = [f"(free {r} {g})" + for r in robots + for g in grippers] + + for ball in balls: + room = random.choice(rooms) + facts.append(f"(at {ball} {room})") + for robot in robots: + room = random.choice(rooms) + facts.append(f"(at-robby {robot} {room})") + + return " ".join(facts) + + +def goal(): + facts = [] + + for ball in balls: + room = random.choice(rooms) + facts.append(f"(at {ball} {room})") + + return " ".join(facts) + + +print("(define (problem gripper)") +print(" (:domain gripper-ex-typed)") +print(" (:objects " + + " ".join( + robots + ["-", "robot"] + + rooms + ["-", "room"] + + grippers + ["-", "gripper"] + + balls + ["-", "ball"]) + + ")") +print(" (:init " + init() + ")") +print(" (:goal (and " + goal() + ")))")