-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
randomizable gripper & extended grippers domain, rewritten in python #7
Open
guicho271828
wants to merge
2
commits into
AI-Planning:main
Choose a base branch
from
guicho271828:gripper
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
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() + ")))") |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
# Grippers (python) | ||
|
||
usage: gripper.py [-h] [--seed SEED] balls robots grippers rooms | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's rename the file to grippers.py. |
||
|
||
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. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() + ")))") |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to combine these two options into the
--seed
option and randomize if--seed
is given.