11import logging
22
3+
34class BasicHeuristic :
45 def __init__ (self , automated_planner , heuristic_key ):
56 self .automated_planner = automated_planner
67 self .heuristic_keys = {
78 "basic/zero" : self .__zero_heuristic ,
8- "basic/goal_count" : self .__goal_count_heuristic
9+ "basic/goal_count" : self .__goal_count_heuristic ,
910 }
1011 if heuristic_key not in list (self .heuristic_keys .keys ()):
11- logging .warning ("Heuristic key isn't registered, forcing it to [basic/goal_count]" )
12+ logging .warning (
13+ "Heuristic key isn't registered, forcing it to [basic/goal_count]"
14+ )
1215 heuristic_key = "basic/goal_count"
1316
1417 self .current_h = heuristic_key
@@ -31,19 +34,21 @@ class DeleteRelaxationHeuristic:
3134 def __init__ (self , automated_planner , heuristic_key ):
3235 class DRHCache :
3336 def __init__ (self , domain = None , axioms = None , preconds = None , additions = None ):
34- self .domain = domain
37+ self .domain = domain
3538 self .axioms = axioms
3639 self .preconds = preconds
3740 self .additions = additions
38-
41+
3942 self .automated_planner = automated_planner
4043 self .cache = DRHCache ()
4144 self .heuristic_keys = {
4245 "delete_relaxation/h_add" : self .__h_add ,
43- "delete_relaxation/h_max" : self .__h_max
46+ "delete_relaxation/h_max" : self .__h_max ,
4447 }
4548 if heuristic_key not in list (self .heuristic_keys .keys ()):
46- logging .warning ("Heuristic key isn't registered, forcing it to [delete_relaxation/h_add]" )
49+ logging .warning (
50+ "Heuristic key isn't registered, forcing it to [delete_relaxation/h_add]"
51+ )
4752 heuristic_key = "delete_relaxation/h_add"
4853
4954 self .current_h = heuristic_key
@@ -56,25 +61,30 @@ def compute(self, state):
5661 self .__pre_compute ()
5762 domain = self .cache .domain
5863 goals = self .automated_planner .goals
59- types = state .types
60- facts = state .facts
64+ types = state .types
65+ facts = state .facts
6166 fact_costs = self .automated_planner .pddl .init_facts_costs (facts )
62- while not (len (fact_costs ) == self .automated_planner .pddl .length (facts ) and self .__facts_eq (fact_costs , facts )):
63- facts , state = self .automated_planner .pddl .get_facts_and_state (fact_costs , types )
67+ while not (
68+ len (fact_costs ) == self .automated_planner .pddl .length (facts )
69+ and self .__facts_eq (fact_costs , facts )
70+ ):
71+ facts , state = self .automated_planner .pddl .get_facts_and_state (
72+ fact_costs , types
73+ )
6474 if self .automated_planner .satisfies (goals , state ):
6575 costs = []
66- fact_costs_str = dict ( [(str (k ), val ) for k , val in fact_costs .items ()] )
76+ fact_costs_str = dict ([(str (k ), val ) for k , val in fact_costs .items ()])
6777 for g in goals :
6878 if str (g ) in fact_costs_str :
6979 costs .append (fact_costs_str [str (g )])
7080 costs .insert (0 , 0 )
7181 return self .heuristic_keys [self .current_h ](costs )
72-
82+
7383 for ax in self .cache .axioms :
7484 fact_costs = self .automated_planner .pddl .compute_costs_one_step_derivation (
7585 facts , fact_costs , ax , self .current_h
7686 )
77-
87+
7888 actions = self .automated_planner .available_actions (state )
7989 if not actions :
8090 break
@@ -93,13 +103,14 @@ def __pre_compute(self):
93103 additions = dict ()
94104 self .automated_planner .pddl .cache_global_preconditions (domain )
95105 for name , definition in domain .actions .items ():
96- additions [name ] = self .automated_planner .pddl .effect_diff (definition .effect ).add
106+ additions [name ] = self .automated_planner .pddl .effect_diff (
107+ definition .effect
108+ ).add
97109 self .cache .additions = additions
98110 self .cache .preconds = self .automated_planner .pddl .g_preconditions
99111 self .cache .domain = domain
100112 self .cache .axioms = axioms
101113 self .has_been_precomputed = True
102-
103114
104115 def __h_add (self , costs ):
105116 return sum (costs )
@@ -109,7 +120,6 @@ def __h_max(self, costs):
109120
110121 def __facts_eq (self , facts_dict , facts_set ):
111122 for f in facts_set :
112- if not (f in facts_dict .keys ()):
123+ if not (f in facts_dict .keys ()):
113124 return False
114125 return True
115-
0 commit comments