Skip to content

Commit ba6fbbf

Browse files
committed
fix linting
1 parent b67d91a commit ba6fbbf

5 files changed

Lines changed: 39 additions & 54 deletions

File tree

jupyddl/automated_planner.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,13 @@ def __init__(self, domain_path, problem_path, log_level="DEBUG"):
2727
self.initial_state = self.pddl.initialize(self.problem)
2828
self.goals = self.__flatten_goal()
2929
self.available_heuristics = [
30-
"basic/zero", "basic/goal_count",
31-
"delete_relaxation/h_add", "delete_relaxation/h_max",
32-
"critical_path/1", "critical_path/2", "critical_path/3",
30+
"basic/zero",
31+
"basic/goal_count",
32+
"delete_relaxation/h_add",
33+
"delete_relaxation/h_max",
34+
"critical_path/1",
35+
"critical_path/2",
36+
"critical_path/3",
3337
]
3438

3539
# Logger
@@ -47,7 +51,9 @@ def __run_julia_once(self):
4751
if actions:
4852
self.transition(self.initial_state, actions[0])
4953
return
50-
logging.warning("No actions from initial state, a path probably (definitely) won't be found")
54+
logging.warning(
55+
"No actions from initial state, a path probably (definitely) won't be found"
56+
)
5157

5258
def __init_logger(self, log_level):
5359
import os

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/heuristics.py

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def __goal_count_heuristic(self, state):
2929
count += 1
3030
return count
3131

32+
3233
class DeleteRelaxationHeuristic:
3334
def __init__(self, automated_planner, heuristic_key):
3435
class DRHCache:
@@ -77,10 +78,8 @@ def compute(self, state):
7778
return self.heuristic_keys[self.current_h](costs)
7879

7980
for ax in self.cache.axioms:
80-
fact_costs = (
81-
self.automated_planner.pddl.compute_costs_one_step_derivation(
82-
facts, fact_costs, ax, self.current_h
83-
)
81+
fact_costs = self.automated_planner.pddl.compute_costs_one_step_derivation(
82+
facts, fact_costs, ax, self.current_h
8483
)
8584

8685
actions = self.automated_planner.available_actions(state)
@@ -127,10 +126,7 @@ def __facts_eq(self, facts_dict, facts_set):
127126
return False
128127
return True
129128

130-
<<<<<<< HEAD
131-
=======
132129

133-
>>>>>>> b0a6f7114bd56e8d05402ea32199a4ae7bd498bd
134130
class CriticalPathHeuristic:
135131
def __init__(self, automated_planner, critical_path_level=1):
136132
class CPCache:
@@ -143,10 +139,14 @@ def __init__(self, domain=None, axioms=None, preconds=None, additions=None):
143139
self.automated_planner = automated_planner
144140
self.cache = CPCache()
145141
if critical_path_level > 3:
146-
logging.warning("Critical Path level is only implemented until 3, forcing it to 3.")
142+
logging.warning(
143+
"Critical Path level is only implemented until 3, forcing it to 3."
144+
)
147145
self.critical_path_level = 3
148146
if critical_path_level < 1:
149-
logging.warning("Critical Path level has to be at least 1, forcing it to 1.")
147+
logging.warning(
148+
"Critical Path level has to be at least 1, forcing it to 1."
149+
)
150150
self.critical_path_level = 1
151151
else:
152152
self.critical_path_level = critical_path_level
@@ -174,17 +174,6 @@ def compute(self, state):
174174
if str(g) in fact_costs_str:
175175
costs.append(fact_costs_str[str(g)])
176176
if self.critical_path_level == 2:
177-
<<<<<<< HEAD
178-
pairs_of_goals = [(g1, g2) for g1 in goals for g2 in goals if g1 != g2]
179-
for gs in pairs_of_goals:
180-
if str(gs[0]) in fact_costs_str and str(gs[1]) in fact_costs_str:
181-
costs.append(fact_costs_str[str(gs[0])] + fact_costs_str[str(gs[1])])
182-
if self.critical_path_level == 3:
183-
triplets_of_goals = [(g1, g2, g3) for g1 in goals for g2 in goals for g3 in goals if g1 != g2 and g1 != g3 and g2 != g3]
184-
for gs in triplets_of_goals:
185-
if str(gs[0]) in fact_costs_str and str(gs[1]) in fact_costs_str and str(gs[2]) in fact_costs_str:
186-
costs.append(fact_costs_str[str(gs[0])] + fact_costs_str[str(gs[1])] + fact_costs_str[str(gs[2])])
187-
=======
188177
pairs_of_goals = [
189178
(g1, g2) for g1 in goals for g2 in goals if g1 != g2
190179
]
@@ -215,15 +204,12 @@ def compute(self, state):
215204
+ fact_costs_str[str(gs[1])]
216205
+ fact_costs_str[str(gs[2])]
217206
)
218-
>>>>>>> b0a6f7114bd56e8d05402ea32199a4ae7bd498bd
219207
costs.insert(0, 0)
220208
return max(costs)
221209

222210
for ax in self.cache.axioms:
223-
fact_costs = (
224-
self.automated_planner.pddl.compute_costs_one_step_derivation(
225-
facts, fact_costs, ax, "max"
226-
)
211+
fact_costs = self.automated_planner.pddl.compute_costs_one_step_derivation(
212+
facts, fact_costs, ax, "max"
227213
)
228214

229215
actions = self.automated_planner.available_actions(state)

jupyddl/metrics.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,17 @@ def __str__(self):
2222
else:
2323
av = 0
2424
w = 0
25-
return "Expanded %d state(s).\nOpened %d state(s).\nReopened %d state(s).\nEvaluated %d state(s).\nGenerated %d state(s).\nDead ends: %d state(s).\nRuntime: %.2fs.\nTotal heuristic runtime: %.2fs\nComputational weight of heuristic in the search: %.2f%%" % (
26-
self.n_expended,
27-
self.n_opened,
28-
self.n_reopened,
29-
self.n_evaluated,
30-
self.n_generated,
31-
self.deadend_states,
32-
self.runtime,
33-
av,
34-
w,
25+
return (
26+
"Expanded %d state(s).\nOpened %d state(s).\nReopened %d state(s).\nEvaluated %d state(s).\nGenerated %d state(s).\nDead ends: %d state(s).\nRuntime: %.2fs.\nTotal heuristic runtime: %.2fs\nComputational weight of heuristic in the search: %.2f%%"
27+
% (
28+
self.n_expended,
29+
self.n_opened,
30+
self.n_reopened,
31+
self.n_evaluated,
32+
self.n_generated,
33+
self.deadend_states,
34+
self.runtime,
35+
av,
36+
w,
37+
)
3538
)

tests/test_automated_planner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import sys
44
from os import path
5+
56
sys.path.append(path.dirname(path.dirname(path.abspath(__file__))))
67
from jupyddl.automated_planner import AutomatedPlanner
78

0 commit comments

Comments
 (0)