Skip to content

Commit

Permalink
Modified PutNext level so we can have an easier curriculum
Browse files Browse the repository at this point in the history
  • Loading branch information
maximecb committed Jul 4, 2018
1 parent 56be3bc commit 7a2f544
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 33 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,11 @@ A work-in-progress review of related work can be found [here](https://www.overle
- Environment: Single room with multiple objects. One of the objects must be moved next to another specific object.
- Instruction: Put the X next to the Y
- Level ids:
- `BabyAI-PutNextS6N5-v0`
- `BabyAI-PutNextS7N5-v0`
- `BabyAI-PutNextS8N6-v0`
- `BabyAI-PutNextS8N8-v0`
- `BabyAI-PutNextS4N1-v0`
- `BabyAI-PutNextS5N1-v0`
- `BabyAI-PutNextS6N2-v0`
- `BabyAI-PutNextS6N3-v0`
- `BabyAI-PutNextS7N4-v0`

### PutTwoNext

Expand Down
77 changes: 48 additions & 29 deletions babyai/levels/levels.py
Original file line number Diff line number Diff line change
Expand Up @@ -996,79 +996,98 @@ def verifier(env, action):

class PutNext(RoomGridLevelHC):
"""
Put an object next to another object
There are many objects inside a room, so that the number of possible
instructions is potentially large.
Task of the form: move the A next to the B and the C next to the D.
This task is structured to have a very large number of possible
instructions.
"""

def __init__(
self,
room_size,
num_objs,
objs_per_room,
seed=None
):
assert num_objs >= 5, "no guarantee that non-adjacent objects exist with N < 5"
self.num_objs = num_objs
assert room_size >= 4
assert objs_per_room <= 9
self.objs_per_room = objs_per_room

super().__init__(
num_rows=1,
num_cols=1,
num_cols=2,
room_size=room_size,
seed=seed
)

def gen_mission(self):
self.place_agent(0, 0)

self.add_distractors(self.num_objs)
objs = self.get_room(0, 0).objs
# Add objects to both the left and right rooms
# so that we know that we have two non-adjacent set of objects
objs_l = self.add_distractors(self.objs_per_room, 0, 0)
objs_r = self.add_distractors(self.objs_per_room, 1, 0)

# Remove the wall between the two rooms
self.remove_wall(0, 0, 0)

# Select two objects that are not already adjacent
while True:
x, y = self._rand_subset(objs, 2)
if not pos_next_to(x.init_pos, y.init_pos):
break
# Select objects from both subsets
a = self._rand_elem(objs_l)
b = self._rand_elem(objs_r)

# Randomly flip the object to be moved
if self._rand_bool():
t = a
a = b
b = t

self.surface = "put the %s %s next to the %s %s" % (
x.color, x.type,
y.color, y.type
a.color, a.type,
b.color, b.type
)

self.verifier = verify_put_next(x, y)
self.verifier = verify_put_next(a, b)


class Level_PutNextS6N5(PutNext):
class Level_PutNextS4N1(PutNext):
def __init__(self, seed=None):
super().__init__(
room_size=6,
num_objs=5,
room_size=4,
objs_per_room=1,
seed=seed
)


class Level_PutNextS7N5(PutNext):
class Level_PutNextS5N1(PutNext):
def __init__(self, seed=None):
super().__init__(
room_size=7,
num_objs=5,
room_size=5,
objs_per_room=1,
seed=seed
)


class Level_PutNextS8N6(PutNext):
class Level_PutNextS5N2(PutNext):
def __init__(self, seed=None):
super().__init__(
room_size=8,
num_objs=6,
room_size=5,
objs_per_room=2,
seed=seed
)


class Level_PutNextS8N8(PutNext):
class Level_PutNextS6N3(PutNext):
def __init__(self, seed=None):
super().__init__(
room_size=8,
num_objs=8,
room_size=6,
objs_per_room=3,
seed=seed
)


class Level_PutNextS7N4(PutNext):
def __init__(self, seed=None):
super().__init__(
room_size=7,
objs_per_room=4,
seed=seed
)

Expand Down

0 comments on commit 7a2f544

Please sign in to comment.