Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

python This assignment asks you to use the problem coding infrastructure provided with the AIMA textbook and the searching algorithms provided to find a solution

python

This assignment asks you to use the problem coding infrastructure provided with the AIMA textbook and the searching algorithms provided to find a solution the the Missionaries and Cannibals problem. Recall that this problem is trying to find the way to transport a group of missionaries and cannibals from one bank of a river to the other using one boat. The boat can carry 1 or 2 people. At no point can the number of cannibals outnumber the number of missionaries on a given side of the river.

This file implements the missionaries and cannibals problem using the problem class specfied for the AIMA python search.py file It then finds solutions to this problem using 2 different search algorithms: Depth First and Breadth First 
from search import * class MandC(Problem): ''' This is the Missionaries and Cannibals Problem it's inherited from the Problem class (see search.py). ''' def __init__(self, initial, goal): #call ths parent class's constructor Problem.__init__(self,initial,goal) def actions(self,state): # This method should return a set of legal actions from # the current state def result(self, state, action): # This method returns the new state after applying action # to state # are there additional methods you'd like to define to help solve this problem? #Now you should test this: def main(): intial_state = #whatever your representation of the initial state is goal_state = #whatever your representation of the goal state is mc = MandC(initial_state,goal_state) soln =depth_first_graph_search(mc) print("Depth First Search") print("Solution Length: " + str(len(soln.path()))) print("Nodes Traversed:") print(soln.path()) print("Actions Taken:") print(soln.solution()) soln = bredth_first_search(mc) print("Breadth First Search") print("Solution Length: " + str(len(soln.path()))) print("Nodes Traversed:") print(soln.path()) print("Actions Taken:") print(soln.solution()) if __name__ == "__main__": main() search file that we use methods from 
class Problem(object): """The abstract class for a formal problem. You should subclass this and implement the methods actions and result, and possibly __init__, goal_test, and path_cost. Then you will create instances of your subclass and solve them with the various search functions.""" def __init__(self, initial, goal=None): """The constructor specifies the initial state, and possibly a goal state, if there is a unique goal. Your subclass's constructor can add other arguments.""" self.initial = initial self.goal = goal def actions(self, state): """Return the actions that can be executed in the given state. The result would typically be a list, but if there are many actions, consider yielding them one at a time in an iterator, rather than building them all at once.""" raise NotImplementedError def result(self, state, action): """Return the state that results from executing the given action in the given state. The action must be one of self.actions(state).""" raise NotImplementedError def goal_test(self, state): """Return True if the state is a goal. The default method compares the state to self.goal or checks for state in self.goal if it is a list, as specified in the constructor. Override this method if checking against a single self.goal is not enough.""" if isinstance(self.goal, list): return is_in(state, self.goal) else: return state == self.goal def path_cost(self, c, state1, action, state2): """Return the cost of a solution path that arrives at state2 from state1 via action, assuming cost c to get up to state1. If the problem is such that the path doesn't matter, this function will only look at state2. If the path does matter, it will consider c and maybe state1 and action. The default method costs 1 for every step in the path.""" return c + 1 def value(self, state): """For optimization problems, each state has a value. Hill-climbing and related algorithms try to maximize this value.""" raise NotImplementedError

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

More Books

Students also viewed these Databases questions

Question

Explain the importance of Human Resource Management

Answered: 1 week ago

Question

Discuss the scope of Human Resource Management

Answered: 1 week ago

Question

Discuss the different types of leadership

Answered: 1 week ago

Question

Write a note on Organisation manuals

Answered: 1 week ago

Question

Define Scientific Management

Answered: 1 week ago

Question

Why do HCMSs exist? Do they change over time?

Answered: 1 week ago