Skip to content

Commit

Permalink
Added foraging environments
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthijs den Toom authored and Matthijs den Toom committed Feb 5, 2019
1 parent 8197874 commit baed643
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 11 deletions.
10 changes: 6 additions & 4 deletions generate_environment.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
# This file generates and stores a grid generated.
import numpy as np
from gym_multi_robot.envs.foraging_game import ForagingGame

from gym_multi_robot.envs.tiling_pattern_game import TilingPatternGame

if __name__ == '__main__':

x_dim = 11
y_dim = 11
output_file = 'tiles11x11.npy'
output_file = 'foraging50x50.pickle'

game = TilingPatternGame((11, 11), 2)
game = ForagingGame((50, 50), 1000, (0, 0, 2, 2))
game.reset()

print('Initial fitness:' + str(game.get_fitness()))
print(game.num_tiles)
print(game.grid)
np.save(output_file, game.grid)
print(game.target_area)

game.write(output_file)



18 changes: 15 additions & 3 deletions gym_multi_robot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,30 @@
register(
id='tiling-pattern7x5-static-v0',
entry_point='gym_multi_robot.envs:TilingPatternEnv',
kwargs={'robots_path': 'robots.pickle', 'tiles_path': 'tiles.npy'}
kwargs={'env_storage_path': 'tiles7x5.pickle'}
)

register(
id='tiling-pattern11x11-static-v0',
entry_point='gym_multi_robot.envs:TilingPatternEnv',
kwargs={'robots_path': 'robots.pickle', 'tiles_path': 'tiles11x11.npy'}
kwargs={'env_storage_path': 'tiles11x11_2_5.pickle'}
)

# This environment has all the tiles distributed in a 6x6 block giving a fitness of 67.24
register(
id='tiling-pattern11x11-block-v0',
entry_point='gym_multi_robot.envs:TilingPatternEnv',
kwargs={'robots_path': 'robots.pickle', 'tiles_path': 'tiles11x11_block.npy'}
kwargs={'env_storage_path': 'tiles11x11_block.pickle'}
)

register(
id='foraging11x11-static-v0',
entry_point='gym_multi_robot.envs:ForagingEnv',
kwargs={'env_storage_path': 'foraging11x11.pickle'}
)

register(
id='foraging50x50-v0',
entry_point='gym_multi_robot.envs:ForagingEnv',
kwargs={'x_dim': 50, 'y_dim': 50, 'num_tiles': 1000, 'target_area': (0, 0, 2, 2)}
)
1 change: 1 addition & 0 deletions gym_multi_robot/envs/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from gym_multi_robot.envs.tiling_pattern_env import TilingPatternEnv
from gym_multi_robot.envs.foraging_env import ForagingEnv
4 changes: 2 additions & 2 deletions gym_multi_robot/envs/foraging_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ class ForagingEnv(MultiRobotEnv):
a designated area.
"""

def __init__(self, lattice_size=2, x_dim=7, y_dim=5, seed=None, num_robots=5, env_storage_path=None):
def __init__(self, x_dim=7, y_dim=5, num_tiles=2, target_area=(0, 0, 1, 1), seed=None, num_robots=5, env_storage_path=None):
super().__init__(seed)

if env_storage_path is not None:
env_storage = self.get_static_storage(env_storage_path)
assert isinstance(env_storage, ForagingGameStorage)
self.game = StaticForagingGame(env_storage)
else:
self.game = ForagingGame((x_dim, y_dim), lattice_size, num_robots)
self.game = ForagingGame((x_dim, y_dim), num_tiles, target_area, num_robots)
2 changes: 1 addition & 1 deletion gym_multi_robot/envs/foraging_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def direction_to_target_area(self, location):
is_west = location[0] >= self.target_area[0] + self.target_area[2]
return is_north, is_east, is_south, is_west

def write_config(self, storage_file='tiling_pattern_game.pickle'):
def write(self, storage_file='foraging_game.pickle'):
""" Writes the current configuration of robots and tiles to 2 different files."""
storage = ForagingGameStorage(self)
pickle.dump(storage, open(storage_file, 'wb'))
Expand Down
2 changes: 1 addition & 1 deletion gym_multi_robot/envs/tiling_pattern_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def get_fitness(self):
# TODO: possibly count tiles that robot holds.
return f

def write_config(self, storage_file='tiling_pattern_game.pickle'):
def write(self, storage_file='tiling_pattern_game.pickle'):
""" Writes the current configuration of robots and tiles to 2 different files."""
storage = TilingPatternGameStorage(self)
pickle.dump(storage, open(storage_file, 'wb'))
Expand Down

0 comments on commit baed643

Please sign in to comment.