0

This was the error in the terminal.

Loading data...
Data loaded.
Name: Kevin Bacon
Name: Tom Cruise
Traceback (most recent call last):
  File "/home/ubuntu/AI/degrees/degrees.py", line 208, in <module>
    main()
  File "/home/ubuntu/AI/degrees/degrees.py", line 72, in main
    path = shortest_path(source, target)
  File "/home/ubuntu/AI/degrees/degrees.py", line 92, in shortest_path
    frontier = QueueFrontier(StackFrontier)
TypeError: __init__() takes 1 positional argument but 2 were given

Here is my python code.

def shortest_path(source, target):

    num_explored = 0

    start = Node(state = source, parent = None, action = None)
    frontier = QueueFrontier(StackFrontier)
    frontier.add(start)

    explored = set()

    target_found = False

    while target_found == False:
        if frontier.empty():
            return None

        node = frontier.remove()
        num_explored += 1

        if node.state == target:
            target_found = True

            actions = []
            person_id = []

            while node.parent is not None:

                actions.append(node.action)
                person_id.append(node.state)
                node = node.parent

            actions.reverse()
            person_id.reverse()

            solution = []
            for x in range(len(actions)):
                solution.append((actions[x], person_id[x]))

            return solution

        explored.add(node.state)

        for action, state in neighbors_for_person(node.state):
            if not action or not state:
                return None
            elif state not in frontier and state not in self.explored:
                child = Node(state = state, parent = node, action = action)
                frontier.add(child)

You must log in to answer this question.

Browse other questions tagged .