2.1. Search and Problem Solving
2.1. Search and Problem Solving
Imagine you’re in a foreign city, at some address (say a hotel) and want to use public transport to
get to another address (a nice restaurant, perhaps). What do you do? If you are like many people,
you pull out your smartphone, type in the destination and start following the instructions.
This question belongs to the class of search and planning problems. Similar problems need to be
solved by self-driving cars, and (perhaps less obviously) AI for playing games. In the game of
chess, for example, the difficulty is not so much in getting a piece from A to B as keeping your
pieces safe from the opponent.
Often there are many different ways to solve the problem, some of which may be more preferable
in terms of time, effort, cost or other criteria. Different search techniques may lead to different
solutions, and developing advanced search algorithms is an established research area.
We will not focus on the actual search algorithms. Instead, we emphasize the first stage of the
problem solving process: defining the choices and their consequences, which is often far from
trivial and can require careful thinking. We also need to define what our goal is, or in other words,
when we can consider the problem solved. After this has been done, we can look for a sequence of
actions that leads from the initial state to the goal.
These categories don’t cover all possible real-world scenarios, but they are generic enough to
demonstrate the main concepts and techniques.
Before we address complex search tasks like navigation or playing chess, let us start from a much
simplified model in order to build up our understanding of how we can solve problems by AI.
We’ll start from a simple puzzle to illustrate the ideas. A robot on a rowboat needs to move three
pieces of cargo across a river: a fox, a chicken, and a sack of chicken-feed. The fox will eat the
chicken if it has the chance, and the chicken will eat the chicken-feed if it has the chance, and
neither is a desirable outcome. The robot is capable of keeping the animals from doing harm
when it is near them, but only the robot can operate the rowboat and only two of the pieces of
cargo can fit on the rowboat together with the robot. How can the robot move all of its cargo to the
opposite bank of the river?
Note
We have given short names to the states, because otherwise it would be cumbersome to talk about
them. Now we can say that the starting state is NNNN and the goal state is FFFF, instead of
something like “in the starting state, the robot is on the near side, the fox is on the near side, the
chicken is on the near side, and also the chicken-feed is on the near side, and in the goal state the
robot is on the far side”, and so on.
Some of these states are forbidden by the puzzle conditions. For example, in state NFFN (meaning
that the robot is on the near side with the chicken-feed but the fox and the chicken are on the far
side), the fox will eat the chicken, which we cannot have. Thus we can rule out states NFFN,
NFFF, FNNF, FNNN, NNFF, and FFNN (you can check each one if you doubt our reasoning). We
are left with the following ten states:
Next we will figure out which state transitions are possible, meaning simply that as the robot rows
the boat with some of the items as cargo, what the resulting state is in each case. It’s best to draw a
diagram of the transitions, and since in any transition the first letter alternates between N and F,
it is convenient to draw the states starting with N (so the robot is on the near side) in one row and
the states starting with F in another row:
Now let's draw the transitions. We could draw arrows that have a direction so that they point from
one node to another, but in this puzzle the transitions are symmetric: if the robot can row from
state NNNN to state FNFF, it can equally well row the other way from FNFF to NNNN. Thus it is
simpler to draw the transitions simply with lines that don't have a direction. Starting from NNNN,
we can go to FNFN, FNFF, FFNF, and FFFN:
One such path is colored in the following picture. The path proceeds from NNNN to FFFN (the
robot takes the fox and the chicken to the other side), thence to NFNN (the robot takes the
chicken back on the starting side) and finally to FFFF (the robot can now move the chicken and
the chicken-feed to the other side).
To formalize a planning problem, we use concepts such as the state space, transitions, and costs.
Key terminology
Costs
refer to the fact that, oftentimes the different transitions aren´t all alike. They can differ in ways that
make some transitions more preferable or cheaper (in a not necessarily monetary sense of the word)
and others more costly. We can express this by associating with each transition a certain cost. If the
goal is to minimize the total distance traveled, then a natural cost is the geographical distance
between states. On the other hand, the goal could actually be to minimize the time instead of the
distance, in which case the natural cost would obviously be the time. If all the transitions are equal,
then we can ignore the costs.
Answered
In the traditional version of this puzzle the robot can only fit one thing on the boat with it. The state
space is still the same, but fewer transitions are possible.
Using the diagram with the possible states below as a starting point, draw the possible
transitions in it (it is MUCH easier to do this with a pencil and paper than without).
Having drawn the state transition diagram, find the shortest path from NNNN to FFFF, and
calculate the number of transitions on it.
Please type your answer as the number of transitions in the shortest path (just a single number like
"12"). Hint: Do not count the number of states, but the number of transitions. For example, the number
of transitions in the path NNNN→FFNF→NFNF→FFFF is 3 instead of 4.
You answered
7
There are two shortest paths that lead from the start NNNN to the goal FFFF. One of them is NNNN -> FNFN ->
NNFN -> FFFN -> NFNN -> FFNF -> NFNF -> FFFF, and the other NNNN -> FNFN -> NNFN -> FNFF -> NNNF -> FFNF
-> NFNF -> FFFF. Intuitively, the strategy is to move the chicken on the other side first, and then go back get
either the fox or the feed, and take it to the far side too. The robot then takes the chicken back to the near side
to save it from being eaten or from eating the feed, and takes the other remaining object (fox or feed) from the
near side to the far side. Finally, the robot goes to fetch the chicken and takes it to the far side to reach the
goal.
Answered
Let's do another puzzle: the well-known Towers of Hanoi. In our version, the puzzle involves three pegs,
and two discs: one large, and one small (actually, there can be any number of discs but for the
exercise, two is enough to demonstrate the principle).
In the initial state, both discs are stacked in the first (leftmost) peg. The goal is to move the discs to
the third peg. You can move one disc at a time, from any peg to another, as long as there is no other
disc on top of it. It is not allowed to put a larger disc on top of a smaller disc.
This picture shows the initial state and the goal state. There are also seven other states so that the
total number of possible states is nine: three ways to place the large disc and for each of them, three
ways to place the small disc.
After solving the task using pen and paper, enter your solution by choosing which state belongs to
which node in the diagram. (Hint: Each state belongs to exactly one node).
1 4
2 3 5 6
Choose for each node (1–6) in the above diagram the correct state A—F from below.
A B C
D E F
Correct
Correct
Correct
Correct
Correct
Correct
Your score:
6/ 6
Next section
Course overview
About
FAQ
Privacy Policy