CS计算机代考程序代写 from search import *

from search import *

class BFSFrontier(Frontier):
“””Implements a frontier container appropriate for breadth-first
search.”””

def __init__(self):
“””The constructor takes no argument. It initialises the
container to an empty list.”””
self.container = []

def add(self, path):
self.container.append(path)

def __iter__(self):
while len(self.container) > 0:
yield self.container.pop(0)

def main():
# Example 1
graph = ExplicitGraph(nodes=set(‘SAG’),
edge_list = [(‘S’,’A’), (‘S’, ‘G’), (‘A’, ‘G’)],
starting_list = [‘S’],
goal_nodes = {‘G’})

solutions = generic_search(graph, BFSFrontier())
solution = next(solutions, None)
print_actions(solution)
# Example 2
flights = ExplicitGraph(nodes=[‘Christchurch’, ‘Auckland’,
‘Wellington’, ‘Gold Coast’],
edge_list = [(‘Christchurch’, ‘Gold Coast’),
(‘Christchurch’,’Auckland’),
(‘Christchurch’,’Wellington’),
(‘Wellington’, ‘Gold Coast’),
(‘Wellington’, ‘Auckland’),
(‘Auckland’, ‘Gold Coast’)],
starting_list = [‘Christchurch’],
goal_nodes = {‘Gold Coast’})

my_itinerary = next(generic_search(flights, BFSFrontier()), None)
print_actions(my_itinerary)

if __name__ == “__main__”:
main()