@@ -327,9 +327,11 @@ def iterative_deepening_search(problem):
327
327
# Pseudocode from https://webdocs.cs.ualberta.ca/%7Eholte/Publications/MM-AAAI2016.pdf
328
328
329
329
def bidirectional_search (problem ):
330
- e = problem .find_min_edge ()
331
- gF , gB = {problem .initial : 0 }, {problem .goal : 0 }
332
- openF , openB = [problem .initial ], [problem .goal ]
330
+ e = 0
331
+ if isinstance (problem , GraphProblem ):
332
+ e = problem .find_min_edge ()
333
+ gF , gB = {Node (problem .initial ): 0 }, {Node (problem .goal ): 0 }
334
+ openF , openB = [Node (problem .initial )], [Node (problem .goal )]
333
335
closedF , closedB = [], []
334
336
U = np .inf
335
337
@@ -340,14 +342,14 @@ def extend(U, open_dir, open_other, g_dir, g_other, closed_dir):
340
342
open_dir .remove (n )
341
343
closed_dir .append (n )
342
344
343
- for c in problem . actions ( n ):
345
+ for c in n . expand ( problem ):
344
346
if c in open_dir or c in closed_dir :
345
- if g_dir [c ] <= problem .path_cost (g_dir [n ], n , None , c ):
347
+ if g_dir [c ] <= problem .path_cost (g_dir [n ], n . state , None , c . state ):
346
348
continue
347
349
348
350
open_dir .remove (c )
349
351
350
- g_dir [c ] = problem .path_cost (g_dir [n ], n , None , c )
352
+ g_dir [c ] = problem .path_cost (g_dir [n ], n . state , None , c . state )
351
353
open_dir .append (c )
352
354
353
355
if c in open_other :
@@ -372,15 +374,15 @@ def find_key(pr_min, open_dir, g):
372
374
"""Finds key in open_dir with value equal to pr_min
373
375
and minimum g value."""
374
376
m = np .inf
375
- state = - 1
377
+ node = Node ( - 1 )
376
378
for n in open_dir :
377
379
pr = max (g [n ] + problem .h (n ), 2 * g [n ])
378
380
if pr == pr_min :
379
381
if g [n ] < m :
380
382
m = g [n ]
381
- state = n
383
+ node = n
382
384
383
- return state
385
+ return node
384
386
385
387
while openF and openB :
386
388
pr_min_f , f_min_f , g_min_f = find_min (openF , gF )
0 commit comments