Hi!
I've tried to run the py-lacam
code on my device (Macbook Air 1M), but, unfortunatelly, the execution seems to be really slow.
Below are the adjsutments that I did. The maps are from the standard benchmark.
The algorithm claims to perform really fast, but, maybe, its perfomance is the best only in C++? Can it be the case?
I am implementing all of the algorithms in Python, that is why it is really important for me to check this repo.
Thank you in advance!
The paper is great!
Additional code:
import random
import numpy as np
import re
from typing import TypeAlias
from pycam.mapf_utils import Config
def get_dims_from_pic(img_dir, path='maps'):
with open(f'{path}/{img_dir}') as f:
lines = f.readlines()
height = int(re.search(r'\d+', lines[1]).group())
width = int(re.search(r'\d+', lines[2]).group())
return height, width
def get_np_from_dot_map(img_dir, path='maps'):
with open(f'{path}/{img_dir}') as f:
lines = f.readlines()
height, width = get_dims_from_pic(img_dir, path)
img_np = np.zeros((height, width))
for height_index, line in enumerate(lines[4:]):
for width_index, curr_str in enumerate(line):
if curr_str == '.':
img_np[height_index, width_index] = 1
return img_np, (height, width)
def build_grid(img_dir, path='maps', show_map=False):
print('Start to build_graph_from_png...')
img_np, (height, width) = get_np_from_dot_map(img_dir, path)
return img_np
def get_grid_and_poses(img_dir, num_of_agents, path_to_maps='maps'):
def fill_the_group(list_of_names, list_of_obj):
while len(list_of_names) < num_of_agents:
x_len, y_len = grid.shape
x, y = random.randint(0, x_len-1), random.randint(0, y_len-1)
pos_str = f'{x}_{y}'
if grid[x, y] and pos_str not in list_of_names:
list_of_names.append(pos_str)
list_of_obj.append((x, y))
grid = build_grid(img_dir=img_dir, path=path_to_maps, show_map=False)
grid = grid > 0
starts, goals = Config(), Config()
start_names, goal_names = [], []
fill_the_group(start_names, starts)
fill_the_group(goal_names, goals)
return grid, starts, goals
def main():
# img_dir='empty-32-32.map' # 32-32
img_dir = 'random-32-32-10.map' # 32-32 | LNS | Up to 400 agents with w=5, h=2, lim=1min.
# img_dir='random-32-32-20.map' # 32-32
# img_dir='room-32-32-4.map' # 32-32
# img_dir='maze-32-32-2.map' # 32-32
num_of_agents = 10
grid, starts, goals = get_grid_and_poses(img_dir=img_dir, num_of_agents=num_of_agents)
print()
if __name__ == '__main__':
main()
app.py
file:
import argparse
from pathlib import Path
from my_grid_and_poses import get_grid_and_poses
from pycam import (
LaCAM,
get_grid,
get_scenario,
save_configs_for_visualizer,
validate_mapf_solution,
)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"-m",
"--map-file",
type=Path,
default=Path(__file__).parent / "assets" / "tunnel.map",
)
parser.add_argument(
"-i",
"--scen-file",
type=Path,
default=Path(__file__).parent / "assets" / "tunnel.scen",
)
parser.add_argument(
"-N",
"--num-agents",
type=int,
default=2,
)
parser.add_argument(
"-o",
"--output-file",
type=str,
default="output.txt",
)
parser.add_argument(
"-v",
"--verbose",
type=int,
default=1,
)
parser.add_argument("-s", "--seed", type=int, default=0)
parser.add_argument("-t", "--time_limit_ms", type=int, default=100000)
parser.add_argument(
"--flg_star", action=argparse.BooleanOptionalAction, default=True
)
args = parser.parse_args()
# my grid and start-goal positions
# img_dir='empty-32-32.map' # 32-32
img_dir = 'random-32-32-10.map' # 32-32 | LNS | Up to 400 agents with w=5, h=2, lim=1min.
# img_dir='random-32-32-20.map' # 32-32
# img_dir='room-32-32-4.map' # 32-32
# img_dir='maze-32-32-2.map' # 32-32
num_of_agents = 4
grid, starts, goals = get_grid_and_poses(img_dir=img_dir, num_of_agents=num_of_agents)
# solve MAPF
planner = LaCAM()
solution = planner.solve(
grid=grid,
starts=starts,
goals=goals,
seed=args.seed,
time_limit_ms=args.time_limit_ms,
flg_star=args.flg_star,
verbose=args.verbose,
)
validate_mapf_solution(grid, starts, goals, solution)
# save result
save_configs_for_visualizer(solution, args.output_file)