3. § The disparity (perceived gap) between the existing
state and the desired state.
§ A problem is an obstacle which hinders the achievement
of a particular goal, objective or purpose.
§ A problem may have multiple solutions.
WHAT IS PROBLEM
Artificial Intelligence - UMT Search [2]
4. § Many problems can be solved by searching for a good
solution in a search space
§ Where reasoning consists of exploring alternatives.
§ Declarative knowledge creates alternatives
• Which pieces of knowledge to use?
• How to use them?
§ Search is a about exploring alternatives.
• It is a major approach to exploit knowledge
§ Examples of such problems are:
• 8 puzzle problem
• Maze
• TSP
SEARCH PROBLEMS
Artificial Intelligence - UMT Search [3]
6. § We model the real problem
• We magnify the parts of the problem that are important
for the solution and neglect the ones that are not
• We have to count and measure the important parts
• We need to identify the possible “operators” that can
be used to change reality
§ We solve the modelled problem
• Chose a framework that can solve the problem
• Set the model in the framework
• The framework solves the problem
• Validate the solution choice to show how good is the
method
§ With the help of the solution found in the model, we
solve the real problem
PROBLEM SOLVING
Artificial Intelligence - UMT Search [5]
7. § A problem is defined by following items:
• A search Space
• Initial state
• Actions Or Successor function
• Goal test, can be
• explicit, e.g., x = "at Lahore"
• implicit, e.g., Checkmate(x)
• Path cost (additive)
• e.g., sum of distances, number of actions
executed, etc.
• A solution, a sequence of actions
leading from the initial state to a goal
state
PROBLEM MODELING/FORMULATION
Artificial Intelligence - UMT Search [6]
8. § A convenient way of representing search spaces is as
a graph
§ A graph consists of nodes and links
• nodes represent states in a problem solving process
• links represent transitions or relationships
between nodes
§ A special case of a graph is a rooted tree
• A rooted tree has
• a unique node (the root) from which it is possible
to reach all other nodes in the graph
• at most one link between any two nodes
• no cycles
§ Trees are common in search problems
REPRESENTING A SEARCH SPACE
Artificial Intelligence - UMT Search [7]
9. § A start state (where we are at the start, for
example the starting position of a game of chess)
§ Intermediary states (where we are now, for
example the current position of the board of
chess)
§ One or more goal states where the search for a
solution terminates (for example a check-mate
position in chess)
REPRESENTING A PROBLEM WITH A GRAPH
Artificial Intelligence - UMT Search [8]
10. § State: Any arrangement of 8 numbered tiles and an
empty tile on a 3x3 board
EXAMPLE: 8 PUZZLE
Artificial Intelligence - UMT Search [9]
11. 8 PUZZLE – PARTIAL STATE SPACE
Artificial Intelligence - UMT Search [10]
12. § We have 3 jugs of capacities 3, 5, and 8 liters,
respectively.
§ There is no scale on the jugs, so it's only their
capacities that we certainly know.
§ Initially, the 8-litre jug is full of water, the other
two are empty:
§ We can pour water from one jug to another, and the goal
is to have exactly 4 liters of water in any of the jugs.
WATER JUG PROBLEM
Artificial Intelligence - UMT Search [11]
15. MAN, WOLF, GOAT AND CABBAGE PROBLEM
Artificial Intelligence - UMT Search [14]
§ A Farmer needs to bring a wolf, a goat, and a cabbage
across the river.
§ The boat is tiny and can only carry one passenger/load
at a time.
• If he leaves the wolf and the goat alone together, the
wolf will eat the goat.
• If he leaves the goat and the cabbage alone together,
the goat will eat the cabbage.
§ How can he bring all three safely across the river?
16. MAN, WOLF, GOAT AND CABBAGE PROBLEM
Artificial Intelligence - UMT Search [15]
E
17. MAN, WOLF, GOAT AND CABBAGE PROBLEM
Artificial Intelligence - UMT Search [16]
18. § A solution is a path connecting the initial node
to a goal node (any one)
SOLUTION TO THE SEARCH PROBLEM
Artificial Intelligence - UMT Search [17]
19. § A solution is a path connecting the initial node
to a goal node (any one)
§ The cost of a path is the sum of the arc costs
along this path
§ An optimal solution is a solution path of minimum
cost
• There might be no solution !
SOLUTION TO THE SEARCH PROBLEM
Artificial Intelligence - UMT Search [18]
20. § Often it is not feasible (or too expensive) to
build a complete representation of the state graph
§ A problem solver must construct a solution by
exploring a small portion of the graph
SOLUTION TO THE SEARCH PROBLEM
Artificial Intelligence - UMT Search [19]
22. § A search is said to be exhaustive if the search is
guaranteed to generate all reachable states
(outcomes) before it terminates with failure.
§ Depth-first search (DFS)
§ Breadth-first search(BFS)
EXHAUSTIVE SEARCH
Artificial Intelligence - UMT Search [21]
23. § A search strategy that extends the current path as
far as possible before backtracking to the last
choice point and trying the next alternative path
§ Does not guarantee the optimal
§ In this strategy, search reaches a satisfactory
solution more rapidly than breadth first
• an advantage when the search space is large
DEPTH FIRST SEARCH
Artificial Intelligence - UMT Search [22]
24. § Algorithm - Depth-first search
§ Put the root node on a stack;
while (stack is not empty)
{ remove a node from the stack;
if (node is a goal node) return success;
put all children of node onto the stack;}
return failure;
DEPTH FIRST SEARCH
Artificial Intelligence - UMT Search [23]
25. DEPTH FIRST SEARCH
Artificial Intelligence - UMT Search [24]
In case of graph:
Maintain the visited node
information as well !!
26. § DFS systematically proceeds towards depth before
another path is considered.
§ If the maximum depth of search tree is reached and
if the solution has not been found, then the
search backtracks to the previous level and
explores any remaining alternatives at this
level, and so on.
§ It is this systematic backtracking procedure that
guarantees that it will systematically and
exhaustively examine all of the possibilities.
DEPTH FIRST SEARCH
Artificial Intelligence - UMT Search [25]
27. § A Search strategy, in which the highest layer of a
decision tree is searched completely before
proceeding to the next layer
§ In this strategy, no viable solution is omitted
and therefore guarantee that optimal solution is
found.
§ This strategy is often not feasible when the
search space is large
BREADTH FIRST SEARCH
Artificial Intelligence - UMT Search [26]
28. § Algorithm - Breadth-first search
§ Put the root node on a queue;
while (queue is not empty)
{ remove a node from the queue;
if (node is a goal node) return success;
put all children of node onto the queue;}
return failure;
BREADTH FIRST SEARCH
Artificial Intelligence - UMT Search [27]
30. § The search generates all nodes at a particular level before
proceeding to the next level of the tree.
§ The search systematically proceeds testing each node that is
reachable from a parent node before it expands to any child of
those nodes.
§ The control regime guarantees that the space of possible moves is
systematically examined; this search requires considerable memory
resources.
§ The space that is searched is quite large and the solution may
lie a thousand steps away from the start node. It does, however,
guarantee that if we find a solution it will be the shortest
possible.
§ Search terminates when a solution is found and the test returns
true.
BREADTH FIRST SEARCH
Artificial Intelligence - UMT Search [29]