You are on page 1of 31

Hawassa University (Bensa Daye Campus)

Department of Computer Science

3rd year
Course Title: Introduction to Artificial Intelligence
Course Code: CoSc3081

1
Chapter Three

Searching and Planning

2
Problem Solving agents
 Problem-solving agents are one kind of goal-based agent.

 Problem-solving agents decide what to do by finding sequences of actions


that lead to desirable states.

 Intelligent agents are supposed to act in such a way that the environment
goes through a sequence of states that maximizes the performance
measure.

sensors

?
environment
agent

actuators
3
Problem
 It is a collection of information that the agent will use to decide what to do.
A number of problems are addressed in AI, both:
Toy problems: are problems that are useful to test and demonstrate
methodologies.
 Can be used by researchers to compare the performance of different
algorithms
 e.g. 8-puzzle, n-queens, vacuum cleaner world, towers of Hanoi,
Real-life problems: are problems that have much greater
commercial/economic impact if solved.
 Such problems are more difficult and complex to solve, and there is
no single agreed-upon description
 E.g. Route finding, Traveling sales person, etc. 4
A problem can be defined formally by four components:
 The initial state :- defines where the agent starts or begins its task.

 The state space defines the set of all relevant states reachable from the
initial state by (any) sequence of actions through iterative application of all
permutations and combinations of operators

 The goal test, which determines whether a given state is a goal state or not.

 A path cost function that assigns a numeric cost to each path.

5
Problem Solving by Searching
 Problem is a goal and a means for achieving the goal.
 Search is the process of considering various possible sequences of operators
applied to the initial state, and finding out a sequence which finishes in a
goal sate.
 Solution will be a sequence of operations (actions) leading from initial state
to goal state (plan).
 In Artificial Intelligence, Search techniques are universal problem-solving
methods.
 Rational agents or Problem-solving agents in AI mostly used these search
strategies or algorithms to solve a specific problem and provide the best
result.
 Problem-solving agents are the goal-based agents and use some technique
of representation.

6
Problem States
 A problem is defined by its elements and their relations.

 A state is a representation of those elements in a given moment.

Two special states are defined:

 Initial state (starting point)

 Final state (goal state)

 The state space is the set of all states reachable from the initial state.

 It forms a graph (or map) in which the nodes are states and the arcs
between nodes are actions.

 A path in the state space is a sequence of states connected by a sequence of


actions.

 The solution of the problem is part of the map formed by the state space.
7
Problem Formulation

 A well-defined problem can be described by:

a) Initial state: The initial state that the agent starts in.

b) Action: A description of the possible actions available to the agent.

c) Transition model :A description of what each action does;

d) Path cost- functions that assigns a cost to a path

e) Goal test- test to determine the goal state

8
Problem Solution
 A solution in the state space is a path from the initial state to a goal
state or, sometimes, just a goal state.

 Path/solution cost: function that assigns a numeric cost to each path,


the cost of applying the operators to the states.

 Solution quality is measured by the path cost function, and an optimal


solution has the lowest path cost among all solutions.

 Solutions: The final goal state. Cost is important depending on the


problem and the type of solution required.

9
Cont’d

 Problem solving agents are goal-directed agents and covers the following
phases.

 Goal Formulation: Set of one or more (desirable) world states

 Problem formulation: What actions and states to consider given a


goal and an initial state.

 Search for solution: Given the problem, search for a solution that is
a sequence of actions to achieve the goal starting from the initial state.

 Execution of the solution

10
Example 1: The wolf-goat-cabbage problem

11
Cont..
A farmer has a goat a wolf and a cabbage on the west side of the river. He
wants to get all of his animals and his cabbage across the river onto the
cost side.

The farmer has a boat but he only has enough room for himself and one
other thing.

Case 1: The goat will eat the cabbage if they are left together alone.

Case 2: The wolf will eat the goat if they are left alone.

How can the farmer get everything on the other side?

12
Possible solution
 State Space Representation:

 We can represent the states of the problem with two sets W and E.
 We can also can have representations for the elements in the two sets
as f,g,w,c representing the farmer, goat, wolf, and cabbage
respectively.
 Initial state:
W={f,g,c,w), E={}
 Actions :
Move f from the E to W and vice versa
Move f and one of g,c,w from E to W and vice versa.

 Goal state:

W={},E={f,g,c,w}

13
possible Solution…
 Farmer takes goat across the river, W={w,c},E={f,g}

 Farmer comes back alone, W={f,c,w,},E={g}

 Farmer takes wolf across the river,W={c},E=f,g,w}

 Farmer comes back with goat, W=={f,g,c},E={w}

 Farmer takes cabbage across the river,W={g},E={f,w,c}

 Farmer comes back alone, W={f,g}, E={w,c}

 Farmer takes goat across the river, W={},E={f,g,w,c}

14
Cont..

15
Search Strategies
 The process of looking for a sequence of actions that reaches the goal is
called search.
 A search algorithm takes a problem as input and returns a solution in the
form of an action sequence.
 Once a solution is found, the actions it recommends can be carried out. This
is called the execution phase.
Performance Measures:
 Completeness – does it always find a solution if one exists?
 Time complexity – number of nodes generated/expanded
 Space complexity – maximum number of nodes in memory
 Optimality – does it always find a least-cost solution
 Time and space complexity are measured in terms of
 b – maximum branching factor of the search tree
 d – depth of the least-cost solution
16
Search Algorithms in AI

 Artificial Intelligence is the study of building agents that act rationally.


Most of the time, these agents perform some kind of search algorithm in
the background in order to achieve their tasks.

A search problem consists of:

 A State Space- Set of all possible states where you can be.

 A Start State- The state from where the search begins.

 A Goal Test- A function that looks at the current state returns whether
or not it is the goal state.

 The Solution to a search problem is a sequence of actions, called


the plan that transforms the start state to the goal state.

 This plan is achieved through search algorithms. 17


Search Algorithm Terminologies:
A search problem can have three main factors:
 Search Space: Search space represents a set of possible solutions,
which a system may have.
 Start State: It is a state from where agent begins the search.
 Goal test: It is a function which observe the current state and returns
whether the goal state is achieved or not.
 Search tree: A tree representation of search problem. The root of the
search tree is the root node which is corresponding to the initial state.
 Actions: It gives the description of all the available actions to the agent.
 Transition model: A description of what each action do, can be
represented as a transition model.
 Path Cost: It is a function which assigns a numeric cost to each path.
 Solution: It is an action sequence which leads from the start node to the
18
goal node.
Properties of Search Algorithms:
Following are the four essential properties of search algorithms to compare the
efficiency of these algorithms:

 Completeness: A search algorithm is said to be complete if it guarantees to


return a solution if at least any solution exists for any random input.

 Optimality: If a solution found for an algorithm is guaranteed to be the


best solution (lowest path cost) among all other solutions, then such a
solution for is said to be an optimal solution.

 Time Complexity: Time complexity is a measure of time for an algorithm


to complete its task.

 Space Complexity: It is the maximum storage space required at any point


during the search, as the complexity of the problem.
19
Types of search algorithms
 There are far too many powerful search algorithms out there to fit in a
single article. The fundamental search algorithms divided
into two categories, as shown below.

20
Cont..

21
Breadth-First Strategy

 Breadth-first search is the most common search strategy for traversing a


tree or graph.

 This algorithm searches breadthwise in a tree or graph, so it is called


breadth-first search.

 BFS algorithm starts searching from the root node of the tree and expands
all successor node at the current level before moving to nodes of next
level.

 The breadth-first search algorithm is an example of a general-graph search


algorithm.

 Breadth-first search implemented using FIFO queue data structure.


22
Cont’d
Advantages:

 BFS will provide a solution if any solution exists.

 If there are more than one solutions for a given problem, then BFS will
provide the minimal solution which requires the least number of steps.

Disadvantages:

 It requires lots of memory since each level of the tree must be saved into
memory to expand the next level.

 BFS needs lots of time if the solution is far away from the root node.

23
Depth-first search
 Depth-first search is a recursive algorithm for traversing a tree or graph data structure.
 It is called the depth-first search because it starts from the root node and follows each path
to its greatest depth node before moving to the next path.
 DFS uses a stack data structure for its implementation.
 The process of the DFS algorithm is similar to the BFS algorithm.
Advantage:
 DFS requires very less memory as it only needs to store a stack of the nodes on the path
from root node to the current node.
 It takes less time to reach to the goal node than BFS algorithm (if it traverses in the right
path).
Disadvantage:
 There is the possibility that many states keep re-occurring, and there is no guarantee of
finding the solution.
 DFS algorithm goes for deep down searching and sometime it may go to the infinite loop.
24
Difference between BFS and DFS | BFS vs. DFS
BFS DFS
 BFS Stands for “Breadth First Search”.  DFS stands for “Depth First Search”.
 BFS starts traversal from the root node and
 DFS starts the traversal from the root node and
then explore the search in the level by level
explore the search as far as possible from the
manner i.e. as close as possible from the
root node i.e. depth wise.
root node.
 Breadth First Search can be done with the  Depth First Search can be done with the help of
help of queue i.e. FIFO implementation. Stack i.e. LIFO implementations.
 This algorithm works in two stages – in the first
 This algorithm works in single stage. The
stage the visited vertices are pushed onto the
visited vertices are removed from the queue
stack and later on when there is no vertex
and then displayed at once.
further to visit those are popped-off.
 BFS is slower than DFS.  DFS is more faster than BFS.
 BFS requires more memory compare to
 DFS require less memory compare to BFS.
25
DFS.
Difference between BFS and DFS | BFS vs. DFS

BFS DFS

26
BFS vs DFS for Binary Tree
 What are BFS and DFS for Binary Tree?
A Tree is typically traversed in two ways:
 Breadth First Traversal (Or Level Order Traversal)
Depth First Traversal
 In order Traversal (Left-Root-Right)
 Preorder Traversal (Root-Left-Right)
 Post order Traversal (Left-Right-Root)
BFS and DFSs of above Tree
 Breadth First Traversal : 1 2 3 4 5
Depth First Traversals:
 Preorder Traversal : 1 2 4 5 3
 In order Traversal : 4 2 5 1 3
27
 Post order Traversal : 4 5 2 3 1
Uniform-cost Search Algorithm
 Uniform-cost search is a searching algorithm used for traversing a weighted
tree or graph.
 This algorithm comes into play when a different cost is available for each
edge.
 The primary goal of the uniform-cost search is to find a path to the goal
node which has the lowest cumulative cost.
 Uniform-cost search expands nodes according to their path costs form the
root node.
 It can be used to solve any graph/tree where the optimal cost is in demand.
 A uniform-cost search algorithm is implemented by the priority queue.
 It gives maximum priority to the lowest cumulative cost.
 Uniform cost search is equivalent to BFS algorithm if the path cost of all
edges is the same. 28
Cont’d
Advantages:

 Uniform cost search is optimal because at every state the path with
the least cost is chosen.

Disadvantages:

 It does not care about the number of steps involve in searching and
only concerned about path cost.

 Due to which this algorithm may be stuck in an infinite loop.

29
Assignment one
1. What is an informed searching algorithm and discuss some informed
searching algorithms in artificial intelligence?
2. What are Constraint Satisfaction Search and its type?

3. What is Avoiding Repeated States in artificial intelligence?

4. What is Games as Search Problems in artificial intelligence?

NB:-
 Do with a member of 4(four) student
 Submission date 30/01/2016 E.C
 A copy can make your work dismissed.
30
31

You might also like