22import math
33from .heuristics import zero_heuristic
44
5- class DijkstraBestFirstSearch ():
5+
6+ class DijkstraBestFirstSearch :
67 def __init__ (self , automated_planner ):
78 self .automated_planner = automated_planner
8- self .init = Node (self .automated_planner .initial_state , automated_planner , is_closed = False , is_open = True )
9+ self .init = Node (
10+ self .automated_planner .initial_state ,
11+ automated_planner ,
12+ is_closed = False ,
13+ is_open = True ,
14+ )
915 self .open_nodes_n = 1
1016 self .nodes = dict ()
1117 self .nodes [self .__hash (self .init )] = self .init
@@ -17,19 +23,32 @@ def __hash(self, node):
1723
1824 def search (self ):
1925 while self .open_nodes_n > 0 :
20- current_key = min ([n for n in self .nodes if self .nodes [n ].is_open ], key = (lambda k : self .nodes [k ].f_cost ))
26+ current_key = min (
27+ [n for n in self .nodes if self .nodes [n ].is_open ],
28+ key = (lambda k : self .nodes [k ].f_cost ),
29+ )
2130 current_node = self .nodes [current_key ]
2231
23- if self .automated_planner .satisfies (self .automated_planner .problem .goal , current_node .state ):
24- return current_node
32+ if self .automated_planner .satisfies (
33+ self .automated_planner .problem .goal , current_node .state
34+ ):
35+ return current_node
2536
2637 current_node .is_closed = True
2738 current_node .is_open = False
2839 self .open_nodes_n -= 1
29-
40+
3041 actions = self .automated_planner .available_actions (current_node .state )
3142 for act in actions :
32- child = Node (state = self .automated_planner .transition (current_node .state , act ), automated_planner = self .automated_planner , parent_action = act , parent = current_node , heuristic = zero_heuristic , is_closed = False , is_open = True )
43+ child = Node (
44+ state = self .automated_planner .transition (current_node .state , act ),
45+ automated_planner = self .automated_planner ,
46+ parent_action = act ,
47+ parent = current_node ,
48+ heuristic = zero_heuristic ,
49+ is_closed = False ,
50+ is_open = True ,
51+ )
3352 child_hash = self .__hash (child )
3453 if child_hash in self .nodes :
3554 if self .nodes [child_hash ].is_closed :
0 commit comments