Skip to content

Commit b9a0696

Browse files
committed
Fix runtime search computation
1 parent 5b4584b commit b9a0696

12 files changed

Lines changed: 194 additions & 88 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,5 @@ data.json
136136
pddl-examples/*
137137
data/*
138138
scripts/*
139+
*.txt
139140
!scripts/ipc.py

jupyddl/a_star.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
class AStarBestFirstSearch:
1010
def __init__(self, automated_planner, heuristic_function):
11+
self.time_start = now()
1112
self.automated_planner = automated_planner
1213
self.metrics = Metrics()
1314
self.init = Node(
@@ -30,7 +31,6 @@ def __hash(self, node):
3031
return string.split(sep, 1)[0] + ")"
3132

3233
def search(self, node_bound=float("inf")):
33-
time_start = now()
3434
self.automated_planner.logger.debug(
3535
"Search started at: " + str(timestamp.now())
3636
)
@@ -45,7 +45,7 @@ def search(self, node_bound=float("inf")):
4545
if self.automated_planner.satisfies(
4646
self.automated_planner.problem.goal, current_node.state
4747
):
48-
self.metrics.runtime = now() - time_start
48+
self.metrics.runtime = now() - self.time_start
4949
self.automated_planner.logger.debug(
5050
"Search finished at: " + str(timestamp.now())
5151
)
@@ -95,6 +95,6 @@ def search(self, node_bound=float("inf")):
9595
self.nodes[child_hash] = child
9696
self.open_nodes_n += 1
9797
self.metrics.n_opened += 1
98-
self.metrics.runtime = now() - time_start
98+
self.metrics.runtime = now() - self.time_start
9999
self.automated_planner.logger.warning("!!! No path found !!!")
100100
return None, self.metrics

jupyddl/automated_planner.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
from .a_star import AStarBestFirstSearch
55
from .greedy_best_first import GreedyBestFirstSearch
66
from .metrics import Metrics
7-
from .heuristics import BasicHeuristic, DeleteRelaxationHeuristic, RelaxedCriticalPathHeuristic, CriticalPathHeuristic
7+
from .heuristics import (
8+
BasicHeuristic,
9+
DeleteRelaxationHeuristic,
10+
RelaxedCriticalPathHeuristic,
11+
CriticalPathHeuristic,
12+
)
813
import coloredlogs
914
import logging
1015
import julia
@@ -36,7 +41,7 @@ def __init__(self, domain_path, problem_path, log_level="DEBUG"):
3641
"relaxed_critical_path/3",
3742
"critical_path/1",
3843
"critical_path/2",
39-
"critical_path/3"
44+
"critical_path/3",
4045
]
4146

4247
# Logger

jupyddl/bfs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66

77
class BreadthFirstSearch:
88
def __init__(self, automated_planner):
9+
self.time_start = now()
910
self.visited = []
1011
self.automated_planner = automated_planner
1112
self.init = Node(self.automated_planner.initial_state, automated_planner)
1213
self.queue = [self.init]
1314
self.metrics = Metrics()
1415

1516
def search(self, node_bound=float("inf")):
16-
time_start = now()
1717
self.automated_planner.logger.debug(
1818
"Search started at: " + str(timestamp.now())
1919
)
@@ -25,7 +25,7 @@ def search(self, node_bound=float("inf")):
2525
if self.automated_planner.satisfies(
2626
self.automated_planner.problem.goal, current_node.state
2727
):
28-
self.metrics.runtime = now() - time_start
28+
self.metrics.runtime = now() - self.time_start
2929
self.automated_planner.logger.debug(
3030
"Search finished at: " + str(timestamp.now())
3131
)
@@ -54,6 +54,6 @@ def search(self, node_bound=float("inf")):
5454
continue
5555
self.metrics.n_opened += 1
5656
self.queue.append(child)
57-
self.metrics.runtime = now() - time_start
57+
self.metrics.runtime = now() - self.time_start
5858
self.automated_planner.logger.warning("!!! No path found !!!")
5959
return None, self.metrics

jupyddl/data_analyst.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -509,10 +509,7 @@ def comparative_astar_heuristic_plot(
509509
times_y.append(data[node_opened])
510510

511511
ax.plot(
512-
nodes_sorted,
513-
times_y,
514-
"-o",
515-
label=h,
512+
nodes_sorted, times_y, "-o", label=h,
516513
)
517514

518515
plt.title("A* heuristics complexity comparison")
@@ -544,10 +541,7 @@ def comparative_greedy_bfs_heuristic_plot(
544541
times_y.append(data[node_opened])
545542

546543
ax.plot(
547-
nodes_sorted,
548-
times_y,
549-
"-o",
550-
label=h,
544+
nodes_sorted, times_y, "-o", label=h,
551545
)
552546

553547
plt.title("Greedy Best First heuristics complexity comparison")
@@ -622,10 +616,7 @@ def comparative_data_plot(
622616
for node_opened in nodes_sorted:
623617
times_y.append(data[node_opened])
624618
ax.plot(
625-
nodes_sorted,
626-
times_y,
627-
"-o",
628-
label=planner,
619+
nodes_sorted, times_y, "-o", label=planner,
629620
)
630621
plt.title("Planners complexity comparison")
631622
plt.legend(loc="upper left")
@@ -753,9 +744,7 @@ def compute_planners_efficiency(self):
753744
plt.ylabel("Cost to goal")
754745
for key, val in costs.items():
755746
ax.plot(
756-
val,
757-
"-o",
758-
label=key,
747+
val, "-o", label=key,
759748
)
760749
costs[key] = [i for i in costs[key] if i != 0]
761750
plt.title("Planners efficiency (costs)")

jupyddl/dfs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66

77
class DepthFirstSearch:
88
def __init__(self, automated_planner):
9+
self.time_start = now()
910
self.visited = []
1011
self.automated_planner = automated_planner
1112
self.init = Node(self.automated_planner.initial_state, automated_planner)
1213
self.stack = [self.init]
1314
self.metrics = Metrics()
1415

1516
def search(self, node_bound=float("inf")):
16-
time_start = now()
1717
self.automated_planner.logger.debug(
1818
"Search started at: " + str(timestamp.now())
1919
)
@@ -25,7 +25,7 @@ def search(self, node_bound=float("inf")):
2525
if self.automated_planner.satisfies(
2626
self.automated_planner.problem.goal, current_node.state
2727
):
28-
self.metrics.runtime = now() - time_start
28+
self.metrics.runtime = now() - self.time_start
2929
self.automated_planner.logger.debug(
3030
"Search finished at: " + str(timestamp.now())
3131
)
@@ -54,6 +54,6 @@ def search(self, node_bound=float("inf")):
5454
continue
5555
self.metrics.n_opened += 1
5656
self.stack.append(child)
57-
self.metrics.runtime = now() - time_start
57+
self.metrics.runtime = now() - self.time_start
5858
self.automated_planner.logger.warning("!!! No path found !!!")
5959
return None, self.metrics

jupyddl/dijkstra.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def zero_heuristic():
1212

1313
class DijkstraBestFirstSearch:
1414
def __init__(self, automated_planner):
15+
self.time_start = now()
1516
self.automated_planner = automated_planner
1617
self.metrics = Metrics()
1718
self.init = Node(
@@ -35,7 +36,6 @@ def search(self, node_bound=float("inf")):
3536
self.automated_planner.logger.debug(
3637
"Search started at: " + str(timestamp.now())
3738
)
38-
time_start = now()
3939
while self.open_nodes_n > 0:
4040
current_key = min(
4141
[n for n in self.nodes if self.nodes[n].is_open],
@@ -46,7 +46,7 @@ def search(self, node_bound=float("inf")):
4646
if self.automated_planner.satisfies(
4747
self.automated_planner.problem.goal, current_node.state
4848
):
49-
self.metrics.runtime = now() - time_start
49+
self.metrics.runtime = now() - self.time_start
5050
self.automated_planner.logger.debug(
5151
"Search finished at: " + str(timestamp.now())
5252
)
@@ -96,6 +96,6 @@ def search(self, node_bound=float("inf")):
9696
self.nodes[child_hash] = child
9797
self.metrics.n_opened += 1
9898
self.open_nodes_n += 1
99-
self.metrics.runtime = now() - time_start
99+
self.metrics.runtime = now() - self.time_start
100100
self.automated_planner.logger.warning("!!! No path found !!!")
101101
return None, self.metrics

jupyddl/greedy_best_first.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
class GreedyBestFirstSearch:
1010
def __init__(self, automated_planner, heuristic_function):
11+
self.time_start = now()
1112
self.automated_planner = automated_planner
1213
self.metrics = Metrics()
1314
self.init = Node(
@@ -30,7 +31,6 @@ def __hash(self, node):
3031
return string.split(sep, 1)[0] + ")"
3132

3233
def search(self, node_bound=float("inf")):
33-
time_start = now()
3434
self.automated_planner.logger.debug(
3535
"Search started at: " + str(timestamp.now())
3636
)
@@ -45,7 +45,7 @@ def search(self, node_bound=float("inf")):
4545
if self.automated_planner.satisfies(
4646
self.automated_planner.problem.goal, current_node.state
4747
):
48-
self.metrics.runtime = now() - time_start
48+
self.metrics.runtime = now() - self.time_start
4949
self.automated_planner.logger.debug(
5050
"Search finished at: " + str(timestamp.now())
5151
)
@@ -96,6 +96,6 @@ def search(self, node_bound=float("inf")):
9696
self.nodes[child_hash] = child
9797
self.open_nodes_n += 1
9898
self.metrics.n_opened += 1
99-
self.metrics.runtime = now() - time_start
99+
self.metrics.runtime = now() - self.time_start
100100
self.automated_planner.logger.warning("!!! No path found !!!")
101101
return None, self.metrics

0 commit comments

Comments
 (0)