forked from eartser/sipp-mapf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·67 lines (54 loc) · 2.57 KB
/
main.py
File metadata and controls
executable file
·67 lines (54 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from util.movingai_parser import *
from search_functions.AnytimeSIPP import AnytimeSIPP
from multiagent.MAPF import MAPF
from entity.Agent import Agent
from search_functions.SIPP import SIPP
from search_functions.WSIPP import WdSIPP
from search_functions.WSIPP import WrSIPP
from search_functions.FocalSIPP import FocalSIPP
from entity.Map import TimestampSearchMap
from search_functions.AStar import AStar
from util.draw import Draw
from IPython.display import Image
from testing.run_scens import run_scens
from entity.Statistics import Statistics
import argparse
import random
def manhattan_distance(i1, j1, i2, j2):
di = abs(i2 - i1)
dj = abs(j2 - j1)
return di + dj
def optional_heuristic(node):
return node.i
if __name__ == '__main__':
random.seed(243)
parser = argparse.ArgumentParser(description='Multi-agent path finding using different algorithms')
parser.add_argument('map_filename', type=str,
help='.map file containing map description')
parser.add_argument('scen_filename', type=str,
help='.map.scen file containing scenarios description')
parser.add_argument('agents_n', type=int,
help='number of agents for a single task')
parser.add_argument('algorithm', type=str,
help='name of algorithm for path planning (astar/sipp/wdsipp/wrsipp/focal/anytime)')
parser.add_argument('--weight', type=float, default=1,
help='floating point to use in suboptimal algorithms')
parser.add_argument('--tasks_n', type=int, default=1,
help='number of random tasks to generate and run')
parser.add_argument('--time_limit', type=int, default=10,
help='time limit for a single task in seconds')
parser.add_argument('--gif_filename', type=str,
help='path to save a .gif file representing one of the tasks in motion')
args = parser.parse_args()
algos = {'astar': AStar(manhattan_distance),
'sipp': SIPP(manhattan_distance),
'wdsipp': WdSIPP(manhattan_distance, args.weight),
'wrsipp': WrSIPP(manhattan_distance, args.weight),
'focal': FocalSIPP(manhattan_distance, optional_heuristic, args.weight),
'anytime': AnytimeSIPP(manhattan_distance)}
agents_cnt = args.agents_n
search_function = algos[args.algorithm]
stats = Statistics()
run_scens(args.map_filename, args.scen_filename, agents_cnt, search_function, stats, args.tasks_n,
args.gif_filename, args.time_limit)
print(stats)