Homework 2
|
Write a function to display the nodes in the fringe queue after calling INSERT-ALL. Hint: use the Node display() to display each node.
Make minor changes to INSERT-ALL to perform breadth-first search.
Add a cycle to the STATE_SPACE, for example, state C has as a successor state A. Verify that the cycle causes TREE_SEARCH to execute without terminating. Pressing Ctrl and C simultaneously will terminate Python execution.
Verify correct operation for each of the cases with 1) a solution, 2) cutoff , and 3) failure.
(location, A status, B status)
and a list holds successor states for each action.
[ (Suck, (location, A status, B status)),
(Left, (location, A status, B status)),
(Right, (location, A status, B status))]
For example:
('A', 'Dirty', 'Dirty') :
[('Suck', ('A', 'Clean', 'Dirty')) ,
('Left', ('A', 'Dirty', 'Dirty')) ,
('Right', ('B', 'Dirty', 'Dirty'))]
A farmer has a goat, a cabbage and a wolf to move across a river with a boat that can only hold himself and one other passenger. If the goat and wolf are alone, the wolf will eat the goat. If the goat and cabbage are alone, the goat will eat the cabbage.
Define the state space for the problem. Hint: Use a tuple to represent the side of the river each is located; for example ('W', 'E', 'W', 'W') can represent the (farmer, wolf, goat, cabbage) locations. Use a list of tuples for the successor states. Include successor states that violate the problem constraints, that is ('W', 'W', 'E', 'E') which is the goat is alone with the cabbage; don't violate requirement that the boat can hold only two passengers (e.g all four passengers cannot move from one side to another at once, that is ('W', 'W', 'W', 'W') cannot become ('E', 'E', 'E', 'E')).
Define successor_fn to return a list of states that do not violate the problem constraints.