0% found this document useful (0 votes)
5 views

Lesson 4.1 Search-Additional Notice

Uploaded by

michaelodera370
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Lesson 4.1 Search-Additional Notice

Uploaded by

michaelodera370
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 33

3.

Problem Solving

3.1 General introduction to searching


3.2 Uninformed (Blind) search
3.2 Informed (Heuristic) search
3.1: Problem solving -
Searching
Objective

• At the end of the subtopic the learner


should be able to:
– Define problem space concepts
– Explain how to define a problem in a state
space
– Explain State space search techniques
– Create a search tree given a problem

SIT 305 Slides : Compiled by 3


E.Maina
Workers are always Searching

SIT 305Slides : Compiled by


Brief info on Ants, http://www.winnipeg-bugline.com/ants.html, 4
http://www.boston.com/globe/magazine/2002/0623/frontiers.htm E.Maina
State Space Search
• Many problems can be represented as a
set of states and a set of rules of how one
state is transformed to another.
• The problem is how to reach a particular
goal state, starting from an initial state and
using the state traversing rules.

SIT 305 Slides : Compiled by 5


E.Maina
Example: The City of Königsberg

SIT 305 Slides : Compiled by 6


E.Maina
A Mathematical Problem: Euler’s Graph
Theory

SIT 305 Slides : Compiled by 7


E.Maina
Graph of the Königsberg Bridge System

SIT 305 Slides : Compiled by E.Maina 8


Representation of the Königsberg Bridge
System

SIT 305 Slides : Compiled by E.Maina 9


Graph Theory: Definitions

SIT 305 Slides : Compiled by E.Maina 10


Graph Theory: Definitions (cont’d)

SIT 305 Slides : Compiled by E.Maina 11


State Space Search: Definitions

SIT 305 Slides : Compiled by 12


E.Maina
State space examples
• 8-Puzzle Partial State Space
• The Travelling Salesman Problem

SIT 305 Slides : Compiled by


E.Maina 13
8-Puzzle Partial State Space

SIT 305 Slides : Compiled by E.Maina 14


The Travelling Salesman Problem: Find the shortest

path- visit all cities and return home

SIT 305 Slides : Compiled by 15


E.Maina
The Travelling Salesman Problem : Partial State
Space

SIT 305 Slides : Compiled by 16


E.Maina
Problem solving techniques in
A.I
• Broad Approaches
– using search techniques
• e.g. in Games
– modeling
• using Knowledge Base Systems (KBS)
• using Machine Learning techniques e.g.
Artificial Neural Networks, Decision Trees,
Case-base reasoning, Genetic algorithms, ..

SIT 305 Slides : Compiled by E.Maina 17


Searching as a problem solving
technique
• Searching is the process of looking for the
solution of a problem through a set of
possibilities (state space).
• Search conditions include:
 Current state -where one is;
 Goal state – the solution reached; check whether it
has been reached;
 Cost of obtaining the solution.
• The solution is a path from the current state
to the goal state.
SIT 305 Slides : Compiled by E.Maina 18
Searching as a problem solving
technique
Process of Searching
• Searching proceeds as follows:
– Check the current state;
– Execute allowable actions to move to the next
state;
– Check if the new state is the solution state; if it is
not, then the new state becomes the current state
and the process is repeated until a solution is
found or the state space is exhausted.

SIT 305 Slides : Compiled by E.Maina 19


Search problem
• The search problem consists of finding a solution plan, which
is a path from the current state to the goal state.
• Representing search problems
– A search problem is represented using a directed graph.
The states are represented as nodes while the allowed
steps or actions are represented as arcs.
• A search problem is defined by specifying:
– State space;
– Start node;
– Goal condition, and a test to check whether the goal
condition is met;
– Rules giving how to change states.
– Path cost

SIT 305 Slides : Compiled by E.Maina 20


Problem Definition - Example, 8 puzzle

5 4 1 4
2 7
3
6 1 8 8
4
2 5 4
6
8
7 3 2 7
3 8
6 5

Initial State Goal State

SIT 305 Slides : Compiled by E.Maina 21


Problem Definition - Example, 8
puzzle
• States
– A description of each of the eight tiles in each location that it
can occupy. It is also useful to include the blank
• Operators/Action
– The blank moves left, right, up or down
• Goal Test
– The current state matches a certain state (e.g. one of the
ones shown on previous slide)
• Path Cost
– Each move of the blank costs 1

SIT 305 Slides : Compiled by E.Maina 22


Search Algorithms
• A solution path is a path from a node in S to a node in G.
• A search algorithm finds a solution path through the problem space.
• Multiple paths to a state can lead to cycles in a solution path that
prevent the algorithm from reaching a goal.
• General graph search algorithms must detect and eliminate loops
from potential solution paths.
• A tree search can gain efficiency by eliminating this test and its
overhead.
• For search purpose, one can convert a general graph to a tree by
eliminating all possible loops.
• On any path in the tree (from the root to the present node), do not
include a node twice.

SIT 305 Slides : Compiled by 23


E.Maina
Example: Implicit network of towns

A 4 B 4 C
3
S 5 5
G
4 D E F 3
2 4

• Two possible tasks:


– 1. FIND a (the) path. = computational cost
– 2. TRAVERSE the path. = travel cost
• 2. relates to finding optimal paths
SIT 305 Slides : Compiled by E.Maina 24
The associated loop-free
tree of partial paths
A 4 B 4 C
3
S 5 5
G
4 D 2 E F 3
4

3 S 4
4 A D
5 5 2
B D A E
4 5 2 4 5 4
C E E B B F
2 4 5 4 4 5 4 4 3
D F B F C E A C G
3 4 3 4
G C G F
3
SIT 305 Slides : Compiled by G 25
E.Maina
Paths:
• We are not interested in optimal paths here, so we can
drop the costs.
Denotes: S
SA A Denotes:SD D

B D A A E

C E E B B F

D F B F C E A C G

G C G F Denotes
:
G
SDEBA

SIT 305 Slides : Compiled by 26


E.Maina
Using a Tree – The Obvious
Solution?
• But
– It can be wasteful on space
– It can be difficult the implement, particularly if
there are varying number of children (e.g. in tic-
tac-toe)
– It is not always obvious which node to expand
next. We may have to search the tree looking for
the best leaf node (sometimes called the fringe or
frontier nodes). This can obviously be
computationally expensive

SIT 305 Slides : Compiled by 27


E.Maina
Search Trees
• Some issues:
– Search trees grow very quickly
– The size of the search tree is governed by the
branching factor
– Even this simple game tic-tac-toe has a complete
search tree of 984,410 potential nodes
– The search tree for chess has a branching factor
of about 35

SIT 305 Slides : Compiled by 28


E.Maina
Search Strategy
• Measuring problem-solving performance:
• does it find a solution at all?
• is it a good solution (one with a low path cost)?
• what is the search cost associated with the time and
memory required to find a solution?
• The total cost of the search is the sum of the path cost
and the search cost.

SIT 305 Slides : Compiled by E.Maina 29


Evaluating a search
• Search Strategy is evaluated in four
criteria:
1. Completeness: Is the strategy guaranteed to find a
solution?
2. Time Complexity: How long does it take to find a
solution?
3. Space Complexity: How much memory does it
take to perform the search?
4. Optimality: Does the strategy find the optimal solution
where there are several solutions?

SIT 305 Slides : Compiled by E.Maina 30


Discussion Questions
1. You are given two jugs of water, a 4 liters and a 3 liters
capacity jugs which are not calibrated. There is tap
which can fill the jugs with water. How can you get
exactly two liters of water into four liters jug?
• We have to decide:
– representation of the problem state, initial and final states
– representation of the actions available in the problem, in terms of
how they change the problem state.
– what would be the cost of the solution
Path cost
Search cost

SIT 305 Slides : Compiled by 31


E.Maina
Discussion Questions
2. A farmer with his dog, rabbit and lettuce 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 drive. The boat can only hold two items
including the driver at any one time. If the dog is ever left alone
with the rabbit, the dog will eat it. Similarly if the rabbit is ever left
alone with the lettuce, the rabbit will eat it. How can the farmer get
across the river so that all four characters arrive safely on the other
side?
– Formalize the above problem in terms of state space search. Hint:
• Suggest a suitable representation for the problem state
• State what are the initial and final states are in this representation
• State the possible operators/rules for getting from one state to
another, giving any conditions and when they may be applied

SIT 305 Slides : Compiled by 32


E.Maina
Discussion Questions
3: The missionaries and the cannibals
Three missionaries and three cannibals are on one side of a
river, along with a boat that can hold at most two people.
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.
In order to solve the problem we need to describe:
1.States
Start state
Goal state
General representation
2. Operators
3. Path cost

SIT 305 Slides : Compiled by 33


E.Maina

You might also like