Toy Problem: Missionaries and Cannibals On one bank of a river are three missionaries (black triangles) and three cannibals (red circles). There is one boat available that can hold up to two people and that they would like to use to cross the river. If the cannibals ever outnumber the missionaries on either of the river’s banks, the missionaries will get eaten. How can the boat be used to safely carry all the missionaries and cannibals across the river? Solving Problems by Searching 1 Search Problems initial state set of possible actions/applicability conditions • • • successor function: state set of <action, state> successor function + initial state = state space path (solution) goal • goal test function or goal state path cost function • • assumption: path cost = sum of step costs for optimality Solving Problems by Searching 2 Missionaries and Cannibals: Initial State and Actions initial state: • all missionaries, all cannibals, and the boat are on the left bank 5 possible actions: • • • • • one missionary crossing one cannibal crossing two missionaries crossing two cannibals crossing one missionary and one cannibal crossing Solving Problems by Searching 3 Missionaries and Cannibals: State Space 1c 1c 2c 1m 1c 2c 1m 1m 2c 2c 1m 1c 1c 1c 1c 1c 2m 2m 1m 1c Solving Problems by Searching 4 Breadth-First Search strategy: • expand root node • expand successors of root node • expand successors of successors of root • node etc. implementation: • use FIFO queue to store fringe nodes in general tree search algorithm Solving Problems by Searching 5 depth = 3 depth = 2 depth = 1 depth = 0 Breadth-First Search: Missionaries and Cannibals Solving Problems by Searching 6 Depth-First Search strategy: • • always expand the deepest node in the current fringe first when a sub-tree has been completely explored, delete it from memory and “back up” implementation: • • use LIFO queue (stack) to store fringe nodes in general tree search algorithm alternative: recursive function that calls itself on each of its children in turn Solving Problems by Searching 7 depth = 3 depth = 2 depth = 1 depth = 0 Depth-First Search: Missionaries and Cannibals Solving Problems by Searching 8 Depth-First Search: Finding the Optimal Path first solution discovered may not be optimal must keep searching continued search: • assumption: non-decreasing path costs • remember path cost of cheapest path found • so far do not expand nodes for which path cost exceeds cheapest found so far Solving Problems by Searching 9
© Copyright 2026 Paperzz