Professional Documents
Culture Documents
2
Uniform Cost Search
3
Uniform Cost Search
4
Uniform Cost Search
5
Properties of Uniform Cost Search
Complete
◦ Yes
Time
◦ O(bd)
Space
◦ O(bd)
Optimal
◦ Yes
Bidirectional Search
The idea of bidirectional search is to reduce the search time by
searching forward from the start and backward from the goal
simultaneously
When the two search frontiers intersect, the algorithm can
reconstruct a single path that extends from the start state through
the frontier intersection to the goal.
A new problem arises during a bidirectional search, namely
ensuring that the two search frontiers actually meet.
◦ For example, a depth-first search in both directions is not likely to work
well because its small search frontiers are likely to pass each other by.
Breadth-first search in both directions would be guaranteed to meet.
7
Properties of Bidirectional Search
Complete
◦ Yes
Time
◦ O(bd/2)
Space
◦ Algorithm dependent
Optimal
◦ Yes
Avoiding Repeated States
There are three ways to deal with repeated states, in
increasing order of effectiveness and computational
overhead
◦ Do not return to the state you just came from. Have the expand
function (or the operator set) refuse to generate any successor that is
the same state as the node's parent.
◦ Do not create paths with cycles in them. Have the expand function
(or the operator set) refuse to generate any successor of a node that is
the same as any of the node's ancestors.
◦ Do not generate any state that was ever generated before. This
requires every state that is generated to be kept in memory, resulting
in a space complexity of O(bd), potentially. It is better to think of this
as O(s), where s is the number of states in the entire state space.
9
Examples
MISSIONARIES AND
CANNIBALS
10
Exercise
The missionaries and cannibals: Three missionaries and three cannibals are on one side of a river,
along with a boat that can hold one or two people (one for rowing). Find a way to get everyone to
the other side, without ever leaving a group of missionaries in one place outnumbered by the
cannibals in that place (the cannibals eat the missionaries then).
a. Formulate the problem precisely, making only those distinctions necessary to ensure a valid
solution. Draw a diagram of the complete state space.
b. Implement and solve the problem optimally using an appropriate search algorithm. Is it a good idea
to check for repeated states?
c. Why do you think people have a hard time solving this puzzle, given that the state space is so
simple?
Assumes that passengers have to get out of the boat after the trip.
Red states = missionaries get eaten.
Breadth-first search on
Missionaries & Cannibals
Depth-first search on
Missionaries & Cannibals
Expanded 30 nodes
A farmer with his wolf, duck and bag of corn come to the east side of a river
they wish to cross. There is a boat at the rivers edge, but of course only the
farmer can row. The boat can only hold two things (including the rower) at any
one time. If the wolf is ever left alone with the duck, the wolf will eat it.
Similarly if the duck is ever left alone with the corn, the duck will eat it. How
can the farmer get across the river so that all four arrive safely on the other side?
This means that
everybody/everything is on the
same side of the river.
FWDC
WD C D C W C WD
F F W F D F C
WD C D C W C WD
F F W F D F C
F W C F WD C
D
WD C D C W C WD
F F W F D F C
F W C F WD C
D
W C C W
F D F WD F D C
F C F W C F D C F W F WD F W C
WD D W D C C D
D C C D WD D W
F W F WD F W C F C F W C F D C
F D F WD F D C
W C C W
D
F W C F WD C
Search Tree for “Farmer, Wolf, Duck, Illegal State Repeated Goal State
Corn”
State
F WD C F WD C
Initial State
W C
F D F
W
D
C Farmer takes duck to left bank
F W C
D
F W
D
C Farmer returns alone
C
F WD F WD
C Farmer takes wolf to left bank
F D C
W
F
W
D C
Farmer returns with duck
D D
F W C F W C
Farmer takes corn to left bank
F D F D
W C W C Farmer returns alone
Success!
References
Example taken from: http://algorithmicthoughts.wordpress.com
/2012/12/15/artificial-intelligence-uniform-cost-searchucs/
35