Skip to content

search.ipynb: Broken A* visualizations #941

Description

@kylekyle

A few of the visualizations in the A* search (section 9) are broken. This all happened undera fresh installation of anaconda 3 (python 3.6.5). It seems to be related to the best_first_graph_search function in search.py, but I'm not positive.

Either way, the widget that provides a dropdown of algorithms to visualize on the Romania map fails with the following error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/anaconda3/lib/python3.6/site-packages/ipywidgets/widgets/interaction.py in update(self, *args)
    249                     value = widget.get_interact_value()
    250                     self.kwargs[widget._kwarg] = value
--> 251                 self.result = self.f(**self.kwargs)
    252                 show_inline_matplotlib_plots()
    253                 if self.auto_display and self.result is not None:

~/Desktop/AI/aima-python/notebook.py in visualize_callback(Visualize)
   1020                 user_algorithm = algorithm[algo_dropdown.value]
   1021 
-> 1022                 iterations, all_node_colors, node = user_algorithm(problem)
   1023                 solution = node.solution()
   1024                 all_node_colors.append(final_path_colors(all_node_colors[0], problem, solution))

TypeError: 'Node' object is not iterable

A few of the 8-puzzle (but not all) examples that follow the Romania one are also broken, all with errors similar to this:

~/Desktop/AI/aima-python/search.py in <lambda>(n)
    410     else in your Problem subclass."""
    411     h = memoize(h or problem.h, 'h')
--> 412     return best_first_graph_search(problem, lambda n: n.path_cost + h(n))
    413 
    414 # ______________________________________________________________________________

~/Desktop/AI/aima-python/utils.py in memoized_fn(obj, *args)
    374                 return getattr(obj, slot)
    375             else:
--> 376                 val = fn(obj, *args)
    377                 setattr(obj, slot, val)
    378                 return val

<ipython-input-63-594d40b3aa01> in linear(node)
      1 # Heuristics for 8 Puzzle Problem
      2 def linear(node):
----> 3     return sum([1 if node.state[i] != goal[i] else 0 for i in range(8)])
      4 
      5 def manhattan(node):

<ipython-input-63-594d40b3aa01> in <listcomp>(.0)
      1 # Heuristics for 8 Puzzle Problem
      2 def linear(node):
----> 3     return sum([1 if node.state[i] != goal[i] else 0 for i in range(8)])
      4 
      5 def manhattan(node):

TypeError: 'NoneType' object is not subscriptable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions