forked from ronuchit/pddlgym_planners
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
64 lines (51 loc) · 2.14 KB
/
test.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
import pddlgym
from pddlgym_planners import PlannerHandler
from pddlgym_planners.ff import FF
from pddlgym_planners.fd import FD
from pddlgym_planners.planner import PlanningFailure
def test_planners():
"""Make sure that the plans found by the planners
succeed in the environments
"""
planners = PlannerHandler()
env_names = ["PDDLEnvBlocks-v0", "PDDLEnvBlocks_operator_actions-v0"]
print("[Test] Evaluating satisficing and optimal planners\n")
for type in ["satisficing", "optimal"]:
for planner_name, planner in planners.get_planners_of_type(type):
for env_name in env_names:
print("[Test] evaluating {} on {}".format(planner_name, env_name))
env = pddlgym.make(env_name)
state, _ = env.reset()
try:
plan = planner(env.domain, state)
for act in plan:
_, reward, done, _ = env.step(act)
assert reward == 1.
assert done
print("\t{} succeeded".format(planner_name))
except PlanningFailure:
print("\t{} failed".format(planner_name))
def test_readme_example():
"""Make sure that the README example runs
"""
# Planning with FastForward
ff_planner = FF()
env = pddlgym.make("PDDLEnvBlocks-v0")
state, _ = env.reset()
print("Plan:", ff_planner(env.domain, state))
print("Statistics:", ff_planner.get_statistics())
# Planning with FastDownward (--alias seq-opt-lmcut)
fd_planner = FD()
env = pddlgym.make("PDDLEnvBlocks-v0")
state, _ = env.reset()
print("Plan:", fd_planner(env.domain, state))
print("Statistics:", fd_planner.get_statistics())
# Planning with FastDownward (--alias lama-first)
lama_first_planner = FD(alias_flag="--alias lama-first")
env = pddlgym.make("PDDLEnvBlocks-v0")
state, _ = env.reset()
print("Plan:", lama_first_planner(env.domain, state))
print("Statistics:", lama_first_planner.get_statistics())
if __name__ == "__main__":
test_planners()
# test_readme_example()