-
Notifications
You must be signed in to change notification settings - Fork 1
/
plan.py
executable file
·133 lines (113 loc) · 3.67 KB
/
plan.py
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env python
import argparse
import os
import subprocess
from planning.util import is_numeric
from util.logging import init_logger
_CUR_DIR = os.path.dirname(os.path.abspath(__file__))
def parse_opts():
parser = argparse.ArgumentParser()
parser.add_argument("domain_pddl", type=str)
parser.add_argument("problem_pddl", type=str)
parser.add_argument("model_path", type=str)
parser.add_argument("-t", "--timeout", type=int, default=1800)
parser.add_argument(
"-p", "--planner", type=str, default="fd", choices=["pwl", "fd", "nfd", "policy"]
)
parser.add_argument(
"-f",
"--plan_file",
type=str,
default="plan.plan",
help="Output plan file. Default: plan.plan",
)
opts = parser.parse_args()
return opts
def main():
init_logger()
opts = parse_opts()
domain_pddl = opts.domain_pddl
assert os.path.exists(domain_pddl)
# domain_pddl = os.path.abspath(domain_pddl)
if is_numeric(domain_pddl):
if opts.planner != "nfd":
print("Domain is numeric so switching planner to nfd.")
opts.planner = "nfd"
problem_pddl = opts.problem_pddl
assert os.path.exists(problem_pddl)
# problem_pddl = os.path.abspath(problem_pddl)
model_path = opts.model_path
assert os.path.exists(model_path)
# model_path = os.path.abspath(model_path)
planner = opts.planner
timeout = str(opts.timeout)
trash_file = ""
for s in [domain_pddl, problem_pddl, model_path, planner, timeout]:
trash_file += str(hash(s))
trash_file = f"output_{trash_file}.out"
# trash_file = os.path.abspath(trash_file)
match planner:
case "pwl":
cmd = [
"python3",
f"{_CUR_DIR}/planning/powerlifted/powerlifted.py",
"-s",
"gbfs",
"-d",
domain_pddl,
"-i",
problem_pddl,
"-g",
"clique_kckp",
"--time-limit",
timeout,
"-e",
"wlgoose",
"-m",
model_path,
"--translator-output-file",
trash_file,
"--plan-file",
opts.plan_file,
]
case "fd":
h_goose = f'wlgoose(model_file="{model_path}")'
cmd = [
"python3",
f"{_CUR_DIR}/planning/downward/fast-downward.py",
"--sas-file",
trash_file,
"--plan-file",
opts.plan_file,
"--search-time-limit",
timeout,
domain_pddl,
problem_pddl,
"--search",
f"eager_greedy([{h_goose}])",
]
case "nfd":
h_goose = f'wlgoose(model_path={model_path},domain_path={domain_pddl},problem_path={problem_pddl})'
cmd = [
"python2", # nfd defines a pddl module which clashes with the pddl package
f"{_CUR_DIR}/planning/numeric-downward/fast-downward.py",
"--build",
"release64",
"--sas_file",
trash_file,
"--plan-file",
opts.plan_file,
"--search-time-limit",
timeout,
domain_pddl,
problem_pddl,
"--search",
f"eager_greedy({h_goose})",
]
case _:
raise NotImplementedError
subprocess.check_call(cmd)
if os.path.exists(trash_file):
os.remove(trash_file)
if __name__ == "__main__":
main()