"""Example of Missionaries and Cannibals for use with AIMA code""" #! /usr/bin/python from search import * class MC(Problem): """ Classic missionaries and Cannibals problem. A state is represented by a three typle (M,C,B) where M, C and B are the number of missionaries, cannibals and boats on the left bank, repsectively. A state is legal if it is not the case that there are missionaries on a bank that re outnumbered by canniabls. Actions are that one or two people can row the boat from one bank to the other. The problem is to find a sequence of actions to go from (3,3,1) to (0,0,0).""" def __init__(self, *args): pass def __repr__(self): """returns a string representing the object""" pass def goal_test (self, state): """returns true if state is a goal state""" pass def successor(self, state): """returns a list of successors to state""" pass def main(): searchers = [breadth_first_tree_search, breadth_first_graph_search, depth_first_graph_search, iterative_deepening_search, depth_limited_search] problems =[MC()] for p in problems: for s in searchers: print "Solution to %s found by %s" % (p, s.__name__) path = s(MC()).path() path.reverse() print path print print "SUMMARY: successors/goal tests/states generated/solution" compare_searchers(problems=problems, header=['', ''], searchers=searchers) # if called from the command line, call main() if __name__ == "__main__": main()