Skip to content

Commit 9edeabf

Browse files
committed
Merge branch 'add-astar' of https://github.com/APLA-Toolbox/jl-pddl-wrapper into add-astar
2 parents 267dc5e + 7c1895b commit 9edeabf

7 files changed

Lines changed: 40 additions & 11 deletions

File tree

main.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@ def main():
1414
args = args_parser.parse_args()
1515
apla_tbx = AutomatedPlanner(args.domain, args.problem)
1616
apla_tbx.logger.info("Starting the planning script")
17-
apla_tbx.logger.debug("Available heuristics: " + str(apla_tbx.available_heuristics.keys()))
17+
apla_tbx.logger.debug(
18+
"Available heuristics: " + str(apla_tbx.available_heuristics.keys())
19+
)
1820

1921
path, computation_time = apla_tbx.dijktra_best_first_search(time_it=True)
2022
apla_tbx.logger.debug(apla_tbx.get_actions_from_path(path))
2123

2224
apla_tbx.logger.debug("Computation time: %.2f seconds" % computation_time)
2325
apla_tbx.logger.info("Terminate with grace...")
2426

27+
2528
if __name__ == "__main__":
2629
main()

src/a_star.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ def __hash(self, node):
2828

2929
def search(self):
3030
time_start = now()
31-
self.automated_planner.logger.debug("Search started at: " + str(timestamp.now()))
31+
self.automated_planner.logger.debug(
32+
"Search started at: " + str(timestamp.now())
33+
)
3234
while self.open_nodes_n > 0:
3335
current_key = min(
3436
[n for n in self.nodes if self.nodes[n].is_open],
@@ -40,7 +42,9 @@ def search(self):
4042
self.automated_planner.problem.goal, current_node.state
4143
):
4244
computation_time = now() - time_start
43-
self.automated_planner.logger.debug("Search finished at: " + str(timestamp.now()))
45+
self.automated_planner.logger.debug(
46+
"Search finished at: " + str(timestamp.now())
47+
)
4448
return current_node, computation_time
4549

4650
current_node.is_closed = True

src/automated_planner.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@
55
from .heuristics import goal_count_heuristic, zero_heuristic
66
import coloredlogs, logging
77
import julia
8+
89
_ = julia.Julia(compiled_modules=False, debug=False)
910
from julia import PDDL
1011
from time import time as now
12+
1113
logging.getLogger("julia").setLevel(logging.WARNING)
14+
15+
1216
class AutomatedPlanner:
1317
def __init__(self, domain_path, problem_path, log_level="DEBUG"):
1418
# Planning Tool

src/bfs.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ def __init__(self, automated_planner):
1212

1313
def search(self):
1414
time_start = now()
15-
self.automated_planner.logger.debug("Search started at: " + str(timestamp.now()))
15+
self.automated_planner.logger.debug(
16+
"Search started at: " + str(timestamp.now())
17+
)
1618
while self.queue:
1719
current_node = self.queue.pop(0)
1820
if current_node not in self.visited:
@@ -22,7 +24,9 @@ def search(self):
2224
self.automated_planner.problem.goal, current_node.state
2325
):
2426
computation_time = now() - time_start
25-
self.automated_planner.logger.debug("Search finished at: " + str(timestamp.now()))
27+
self.automated_planner.logger.debug(
28+
"Search finished at: " + str(timestamp.now())
29+
)
2630
return current_node, computation_time
2731

2832
actions = self.automated_planner.available_actions(current_node.state)

src/dfs.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from datetime import datetime as timestamp
33
from time import time as now
44

5+
56
class DepthFirstSearch:
67
def __init__(self, automated_planner):
78
self.visited = []
@@ -11,7 +12,9 @@ def __init__(self, automated_planner):
1112

1213
def search(self):
1314
time_start = now()
14-
self.automated_planner.logger.debug("Search started at: " + str(timestamp.now()))
15+
self.automated_planner.logger.debug(
16+
"Search started at: " + str(timestamp.now())
17+
)
1518
while self.stack:
1619
current_node = self.stack.pop(0)
1720
if current_node not in self.visited:
@@ -21,7 +24,9 @@ def search(self):
2124
self.automated_planner.problem.goal, current_node.state
2225
):
2326
computation_time = now() - time_start
24-
self.automated_planner.logger.debug("Search finished at: " + str(timestamp.now()))
27+
self.automated_planner.logger.debug(
28+
"Search finished at: " + str(timestamp.now())
29+
)
2530
return current_node, computation_time
2631

2732
actions = self.automated_planner.available_actions(current_node.state)

src/dijkstra.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from datetime import datetime as timestamp
66
from time import time as now
77

8+
89
class DijkstraBestFirstSearch:
910
def __init__(self, automated_planner):
1011
self.automated_planner = automated_planner
@@ -13,7 +14,7 @@ def __init__(self, automated_planner):
1314
automated_planner,
1415
is_closed=False,
1516
is_open=True,
16-
heuristic=zero_heuristic
17+
heuristic=zero_heuristic,
1718
)
1819
self.open_nodes_n = 1
1920
self.nodes = dict()
@@ -25,7 +26,9 @@ def __hash(self, node):
2526
return string.split(sep, 1)[0] + ")"
2627

2728
def search(self):
28-
self.automated_planner.logger.debug("Search started at: " + str(timestamp.now()))
29+
self.automated_planner.logger.debug(
30+
"Search started at: " + str(timestamp.now())
31+
)
2932
time_start = now()
3033
while self.open_nodes_n > 0:
3134
current_key = min(
@@ -38,7 +41,9 @@ def search(self):
3841
self.automated_planner.problem.goal, current_node.state
3942
):
4043
computation_time = now() - time_start
41-
self.automated_planner.logger.debug("Search finished at: " + str(timestamp.now()))
44+
self.automated_planner.logger.debug(
45+
"Search finished at: " + str(timestamp.now())
46+
)
4247
return current_node, computation_time
4348

4449
current_node.is_closed = True

tests/test_astar.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@
1111
def test_astar_init():
1212
apla = AutomatedPlanner("data/domain.pddl", "data/problem.pddl")
1313
astar = AStarBestFirstSearch(apla, apla.available_heuristics["goal_count"])
14-
assert astar.init.h_cost == apla.available_heuristics["goal_count"](apla.initial_state, apla)
14+
assert astar.init.h_cost == apla.available_heuristics["goal_count"](
15+
apla.initial_state, apla
16+
)
17+
1518

1619
def test_astar_goal():
1720
apla = AutomatedPlanner("data/domain.pddl", "data/problem.pddl")
1821
path, _ = apla.astar_best_first_search()
1922
assert apla.available_heuristics["goal_count"](path[-1], apla) == 0
2023

24+
2125
def test_astar_path_length():
2226
apla = AutomatedPlanner("data/domain.pddl", "data/problem.pddl")
2327
path, _ = apla.astar_best_first_search()

0 commit comments

Comments
 (0)