Professional Documents
Culture Documents
Chapter Three
Chapter Three
3rd year
Course Title: Introduction to Artificial Intelligence
Course Code: CoSc3081
1
Chapter Three
2
Problem Solving agents
Problem-solving agents are one kind of goal-based agent.
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.
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.
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.
The solution of the problem is part of the map formed by the state space.
7
Problem Formulation
a) Initial state: The initial state that the agent starts in.
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.
9
Cont’d
Problem solving agents are goal-directed agents and covers the following
phases.
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.
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.
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}
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
A State Space- Set of all possible states where you can be.
A Goal Test- A function that looks at the current state returns whether
or not it is the goal state.
20
Cont..
21
Breadth-First Strategy
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.
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.
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?
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