@@ -29,6 +29,7 @@ def __goal_count_heuristic(self, state):
2929 count += 1
3030 return count
3131
32+
3233class DeleteRelaxationHeuristic :
3334 def __init__ (self , automated_planner , heuristic_key ):
3435 class DRHCache :
@@ -127,6 +128,7 @@ def __facts_eq(self, facts_dict, facts_set):
127128 return False
128129 return True
129130
131+
130132class CriticalPathHeuristic :
131133 def __init__ (self , automated_planner , critical_path_level = 1 ):
132134 class CPCache :
@@ -139,10 +141,14 @@ def __init__(self, domain=None, axioms=None, preconds=None, additions=None):
139141 self .automated_planner = automated_planner
140142 self .cache = CPCache ()
141143 if critical_path_level > 3 :
142- logging .warning ("Critical Path level is only implemented until 3, forcing it to 3." )
144+ logging .warning (
145+ "Critical Path level is only implemented until 3, forcing it to 3."
146+ )
143147 self .critical_path_level = 3
144148 if critical_path_level < 1 :
145- logging .warning ("Critical Path level has to be at least 1, forcing it to 1." )
149+ logging .warning (
150+ "Critical Path level has to be at least 1, forcing it to 1."
151+ )
146152 self .critical_path_level = 1
147153 else :
148154 self .critical_path_level = critical_path_level
@@ -170,15 +176,36 @@ def compute(self, state):
170176 if str (g ) in fact_costs_str :
171177 costs .append (fact_costs_str [str (g )])
172178 if self .critical_path_level == 2 :
173- pairs_of_goals = [(g1 , g2 ) for g1 in goals for g2 in goals if g1 != g2 ]
179+ pairs_of_goals = [
180+ (g1 , g2 ) for g1 in goals for g2 in goals if g1 != g2
181+ ]
174182 for gs in pairs_of_goals :
175- if str (gs [0 ]) in fact_costs_str and str (gs [1 ]) in fact_costs_str :
176- costs .append (fact_costs_str [str (gs [0 ])] + fact_costs_str [str (gs [1 ])])
183+ if (
184+ str (gs [0 ]) in fact_costs_str
185+ and str (gs [1 ]) in fact_costs_str
186+ ):
187+ costs .append (
188+ fact_costs_str [str (gs [0 ])] + fact_costs_str [str (gs [1 ])]
189+ )
177190 if self .critical_path_level == 3 :
178- 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 ]
191+ triplets_of_goals = [
192+ (g1 , g2 , g3 )
193+ for g1 in goals
194+ for g2 in goals
195+ for g3 in goals
196+ if g1 != g2 and g1 != g3 and g2 != g3
197+ ]
179198 for gs in triplets_of_goals :
180- if str (gs [0 ]) in fact_costs_str and str (gs [1 ]) in fact_costs_str and str (gs [2 ]) in fact_costs_str :
181- costs .append (fact_costs_str [str (gs [0 ])] + fact_costs_str [str (gs [1 ])] + fact_costs_str [str (gs [2 ])])
199+ if (
200+ str (gs [0 ]) in fact_costs_str
201+ and str (gs [1 ]) in fact_costs_str
202+ and str (gs [2 ]) in fact_costs_str
203+ ):
204+ costs .append (
205+ fact_costs_str [str (gs [0 ])]
206+ + fact_costs_str [str (gs [1 ])]
207+ + fact_costs_str [str (gs [2 ])]
208+ )
182209 costs .insert (0 , 0 )
183210 return max (costs )
184211
0 commit comments