Skip to content

Commit 3a16ca2

Browse files
authored
Merge pull request #59 from APLA-Toolbox/add-performance-metrics
Data Analyst
2 parents ff04455 + e1bb7af commit 3a16ca2

12 files changed

+489
-39
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,4 @@ dmypy.json
136136
# Logs
137137
logs/*
138138
!logs/.gitkeep
139+
data.json

jupyddl/a_star.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def __init__(self, automated_planner, heuristic_function):
1515
is_closed=False,
1616
is_open=True,
1717
heuristic=heuristic_function,
18+
heuristic_based=True,
1819
)
1920
self.heuristic_function = heuristic_function
2021
self.open_nodes_n = 1
@@ -27,6 +28,7 @@ def __hash(self, node):
2728
return string.split(sep, 1)[0] + ")"
2829

2930
def search(self):
31+
opened_nodes = 0
3032
time_start = now()
3133
self.automated_planner.logger.debug(
3234
"Search started at: " + str(timestamp.now())
@@ -45,7 +47,7 @@ def search(self):
4547
self.automated_planner.logger.debug(
4648
"Search finished at: " + str(timestamp.now())
4749
)
48-
return current_node, computation_time
50+
return current_node, computation_time, opened_nodes
4951

5052
current_node.is_closed = True
5153
current_node.is_open = False
@@ -61,7 +63,9 @@ def search(self):
6163
heuristic=self.heuristic_function,
6264
is_closed=False,
6365
is_open=True,
66+
heuristic_based=True,
6467
)
68+
opened_nodes += 1
6569
child_hash = self.__hash(child)
6670
if child_hash in self.nodes:
6771
if self.nodes[child_hash].is_closed:
@@ -79,4 +83,4 @@ def search(self):
7983
self.open_nodes_n += 1
8084
computation_time = now() - time_start
8185
self.automated_planner.logger.warning("!!! No path found !!!")
82-
return None, computation_time
86+
return None, computation_time, opened_nodes

jupyddl/automated_planner.py

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ def __init_logger(self, log_level):
4141
format="%(levelname)s:%(message)s",
4242
filemode="w",
4343
level=log_level,
44-
) # Creates the log file
44+
)
45+
46+
def display_available_heuristics(self):
47+
print(list(self.available_heuristics.keys()))
4548

4649
def transition(self, state, action):
4750
return self.pddl.transition(self.domain, state, action, check=False)
@@ -92,34 +95,30 @@ def get_state_def_from_path(self, path):
9295
trimmed_path.append(node.state)
9396
return trimmed_path
9497

95-
def breadth_first_search(self, time_it=False):
98+
def breadth_first_search(self):
9699
bfs = BreadthFirstSearch(self)
97-
last_node, total_time = bfs.search()
100+
last_node, total_time, opened_nodes = bfs.search()
98101
path = self.__retrace_path(last_node)
99-
if time_it:
100-
return path, total_time
101-
return path, None
102102

103-
def depth_first_search(self, time_it=False):
103+
return path, total_time, opened_nodes
104+
105+
def depth_first_search(self):
104106
dfs = DepthFirstSearch(self)
105-
last_node, total_time = dfs.search()
107+
last_node, total_time, opened_nodes = dfs.search()
106108
path = self.__retrace_path(last_node)
107-
if time_it:
108-
return path, total_time
109-
return path, None
110109

111-
def dijktra_best_first_search(self, time_it=False):
110+
return path, total_time, opened_nodes
111+
112+
def dijktra_best_first_search(self):
112113
dijkstra = DijkstraBestFirstSearch(self)
113-
last_node, total_time = dijkstra.search()
114+
last_node, total_time, opened_nodes = dijkstra.search()
114115
path = self.__retrace_path(last_node)
115-
if time_it:
116-
return path, total_time
117-
return path, None
118116

119-
def astar_best_first_search(self, time_it=False, heuristic=goal_count_heuristic):
117+
return path, total_time, opened_nodes
118+
119+
def astar_best_first_search(self, heuristic=goal_count_heuristic):
120120
astar = AStarBestFirstSearch(self, heuristic)
121-
last_node, total_time = astar.search()
121+
last_node, total_time, opened_nodes = astar.search()
122122
path = self.__retrace_path(last_node)
123-
if time_it:
124-
return path, total_time
125-
return path, None
123+
124+
return path, total_time, opened_nodes

jupyddl/bfs.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ def __init__(self, automated_planner):
1111
self.queue = [self.init]
1212

1313
def search(self):
14+
opened_nodes = 0
1415
time_start = now()
1516
self.automated_planner.logger.debug(
1617
"Search started at: " + str(timestamp.now())
@@ -27,7 +28,7 @@ def search(self):
2728
self.automated_planner.logger.debug(
2829
"Search finished at: " + str(timestamp.now())
2930
)
30-
return current_node, computation_time
31+
return current_node, computation_time, opened_nodes
3132

3233
actions = self.automated_planner.available_actions(current_node.state)
3334
for act in actions:
@@ -39,9 +40,10 @@ def search(self):
3940
parent_action=act,
4041
parent=current_node,
4142
)
43+
opened_nodes += 1
4244
if child in self.visited:
4345
continue
4446
self.queue.append(child)
4547
computation_time = now() - time_start
4648
self.automated_planner.logger.warning("!!! No path found !!!")
47-
return None, computation_time
49+
return None, computation_time, opened_nodes

0 commit comments

Comments
 (0)