Ai Module 2 Notes
Ai Module 2 Notes
com/c/EDULINEFORCSE
STUDENTS
Related Terminology
• Performance Measure of Agent − It is the criteria, which
determines how successful an agent is.
• Behavior of Agent − It is the action that agent performs after any
given sequence of percepts.
• Percept − It is agent’s perceptual inputs at a given instance.
• Percept Sequence − It is the history of all that an agent has
perceived till date.
• Agent Function − It is a map from the precept sequence to an
action.
MODULE 2
PROBLEM SOLVING
Problem characteristics
In order to choose the most appropriate method for a particular
problem, it is necessary to analyze the problem along several
dimensions.
• Is the problem decomposable into a set of independent smaller or
easier sub problems?
• Can solution steps be ignored or at least undone if they prove
unwise?
• Is the problem’s universe predictable?
• Is a good solution to the problem obvious without comparison to
all other possible solutions?
Prepared By Mr. EBIN PM, Chandigarh University, Punjab EDULINE 9
An Example:
Scenario:
You want to go on holiday to city ‘Chandigarh’ but currently you live in
city ‘Kottayam’ And the flight for ‘Chandigarh’ leaves from another city
‘Kochi’.
Goal:
• To reach city ‘Kochi’ from ‘Kottayam’ to catch the flight for ‘Chandigarh’.
Formulate Problem:
States: various cities
Action: movement between the cities
Solution:
• Appropriate sequence of the cities.
• Say, Kottayam->X->Y->Z->Kochi
Prepared By Mr. EBIN PM, Chandigarh University, Punjab EDULINE 11
Problem Solving
• Problem-solving is commonly known as the method to reach the
desired goal or finding a solution to a given situation.
• In computer science, problem-solving refers to artificial intelligence
techniques, including various techniques such as:
forming efficient algorithms,
heuristics, and
performing root cause analysis to find desirable solutions.
Problem space
• A ‘problem space’ is an abstract space.
• A problem space encompasses all valid states that can be
generated by the application of any combination of operators on
any combination of objects.
• The problem space may contain one or more solutions. A solution
is a combination of operations/actions and objects that achieve the
goals.
• The start state is (0, 0) and the goal state is (2, n) where n may be
any but it is limited to three holding from 0 to 3 gallons of water or
empty.
• Three and four shows the name and numerical number shows the
amount of water in jugs for solving the water jug problem.
• The major production rules for solving this problem are shown
below:
Production Rules:
1. (x,y)=(4,y)
2. (x,y)=(x,3)
3. (x,y)=(x-d,y) if x>0
4. (x,y)=(x,y-d) if y>0
5. (x,y)=(0,y) if x>0
6. (x,y)=(x,0) if y>0
7. (x,y)= (4,y-(4-x)) if y>0
8. (x,y)=(x-(3-y),3) if x>0
9. (x,y)=(x+y,0) , if x+y<=4,y>0
8 PUZZLE PROBLEM
• The 8 puzzle consists of eight numbered, movable tiles set in a
3x3 frame.
• One cell of the frame is always empty thus making it possible to
move an adjacent numbered tile into the empty cell.
The production system consists of
• Production set
• Working Memory content
• Start State
• Goal State
• Control engine
Prepared By Mr. EBIN PM, Chandigarh University, Punjab EDULINE 23
XX
EXAMPLE
EXAMPLE
S= source node
K= destination node
Path will be according to BFS concept.
S---> A--->B---->C--->D---->G--->H--->
E---->F---->I ---->K
FF
Advantages:
• It combines the benefits of BFS and DFS search algorithm in terms
of fast search and memory efficiency.
Disadvantages:
• The main drawback of IDDFS is that it repeats all the work of the
previous phase.
If b is the branching factor, and d is the depth of the goal node or
the depth at which the iteration of IDDFS function terminates, the
time complexity is O( 𝒅 )
Example 1
• Here in the given tree, the starting node is A and the depth
initialized to 0.
• The goal node is R where we have to find the depth and the path to
reach it. The depth from the figure is 4.
• In this example, we consider the tree as a finite tree, while we can
consider the same procedure for the infinite tree as well.
• We knew that in the algorithm of IDDFS we first do DFS till a
specified depth and then increase the depth at each loop.
• This special step forms the part of DLS or Depth Limited Search.
Thus the following traversal shows the IDDFS search.
EXAMPLE 2
Heuristics function
• Heuristic is a function which is used in Informed Search, and it finds
the most promising path.
• It takes the current state of the agent as its input and produces the
estimation of how close agent is from the goal.
• The heuristic method, however, might not always give the best
solution, but it guaranteed to find a good solution in reasonable
time.
• Heuristic function estimates how close a state is to the goal. It is
represented by h(n), and it calculates the cost of an optimal path
between the pair of states.
• The value of the heuristic function is always positive.
Prepared By Mr. EBIN PM, Chandigarh University, Punjab EDULINE 50
EXAMPLE
A* ALGORITHM
• It uses heuristic function h(n), and cost to reach the node n from
the start state g(n).
• A* search algorithm finds the shortest path through the search
space using the heuristic function. This search algorithm expands
less search tree and provides optimal result faster.
• A* algorithm is similar to UCS except that it uses g(n)+h(n) instead
of g(n).
• In A* search algorithm, we use search heuristic as well as the cost
to reach the node. Hence we can combine both costs as following,
and this sum is called as a fitness number.
Prepared By Mr. EBIN PM, Chandigarh University, Punjab EDULINE 55
Advantages
• A* search algorithm is the best algorithm than other search
algorithms.
• A* search algorithm is optimal and complete.
• This algorithm can solve very complex problems.
Disadvantages
• It does not always produce the shortest path as it mostly based on
heuristics and approximation.
• A* search algorithm has some complexity issues.
• The main drawback of A* is memory requirement as it keeps all
generated nodes in the memory, so it is not practical for various
large-scale problems.
Algorithm of A* search:
• Step1: Place the starting node in the OPEN list.
• Step 2: Check if the OPEN list is empty or not, if the list is empty then
return failure and stops.
• Step 3: Select the node from the OPEN list which has the smallest value
of evaluation function (g+h), if node n is goal node then return success
and stop, otherwise
• Step 4: Expand node n and generate all of its successors, and put n into
the closed list. For each successor n', check whether n' is already in the
OPEN or CLOSED list, if not then compute evaluation function for n' and
place into Open list.
• Step 5: Else if node n' is already in OPEN and CLOSED, then it should be
attached to the back pointer which reflects the lowest g(n') value.
• Step 6: Return to Step 2.
Prepared By Mr. EBIN PM, Chandigarh University, Punjab EDULINE 58
Example