Ai Chap 1 To 6
Ai Chap 1 To 6
Ai Chap 1 To 6
1.
CE /IT Department
Hand Book
ARTIFICIAL INTELLIGENCE
(2180703)
Year: 2020-2021
Artificial Intelligence
Prof. Dhaval Khatri
What is Artificial Intelligence ?
According to the father of Artificial Intelligence, John McCarthy, it
is “The science and engineering of making intelligent machines,
especially intelligent computer programs”.
Weak AI
Strong AI
Evolutionary AI
Advantages of Artificial Intelligence
Following are some main advantages of Artificial Intelligence:
High Accuracy with less errors:
High-Speed:
High reliability:
Useful for risky areas:
Digital Assistant:
Useful as a public utility:
Disadvantages of Artificial Intelligence
Following are the disadvantages of AI:
High Cost:
Can't think out of the box:
No feelings and emotions:
Increase dependency on machines:
No Original Creativity:
Applications of AI
AI has been dominant in various fields such as −
Gaming
Natural Language Processing
Expert Systems
Vision Systems
Speech Recognition
Handwriting Recognition
Intelligent Robots
Artificial Intelligence Problem Solving
2
Problem Solving Through AI
2.1 INTRODUCTION
In the last chapter, we have tried to explain that Artificial Intelligence is the science
and technology applied to make machines intelligent. The ultimate aim of
researchers is to develop universal intelligent system to match the intelligence
capabilities of human beings. In this regard, lot of progress has been made and
considerable amount of success has been achieved, although, universal intelligent
system is still a dream. Scientists have developed techniques to use AI in a limited
domain and have successfully developed many AI systems, which work in a
problem specific domain and show expertise not only matching those of human
experts, but also exceeding those in many ways and in many applications. It should
be kept in mind that for the time being, the most important application of AI is to
develop intelligent systems to solve real world problems, which otherwise take
considerable amount of time and human efforts, and hence, become uneconomical
as well as inefficient at times. Hence, problem solving becomes major area of
study, which involves methods and various techniques used in problem solving
using AI.
In this chapter, we will discuss the methods of solving real world problems
using Artificial Intelligence (AI) techniques. In real world, there are different types
of problems. We will try to explain various characteristics of problems and their
solution methodologies.
The method of solving problem through AI involves the process of defining
the search space, deciding start and goal states and then finding the path from start
state to goal state through search space. The movement from start state to goal
state is guided by set of rules specifically designed for that particular problem
(sometimes called production rules). The production rules are nothing but valid
moves described by the problems.
Let us first discuss some terms related with AI problem solution methodology:
techniques are devised for this phase. These KR methodologies have their
respective advantages and disadvantages, and specific techniques are suitable for
specific applications. Various KR techniques are described in detail in following
chapters.
way of getting from an initial state to a goal state. They are described as
set of rules consisting of a left hand side that serves as a pattern to be matched
against the current board position and a right hand side that describes changes
to be made to board position to reflect the move.
3. The procedural part will be methods for applying appropriate rule for winning
the game. It will include representing the “set of winning moves”
of standard chess playing. Out of all legal moves, only those moves, which
bring the board position to a winning position of respective player arecaptured
and stored in procedural part.
However, in chess the total ‘legal moves’ are of the order of 10120.
Such a large number of moves are difficult to be written, so only ‘useful
moves’ are written. It should be noted that there is a difference between legal
moves and useful moves. The legal moves are all those moves which are
permissible according to game rules and useful moves will be thoselegal
moves which bring the game in a winning position. Hence the ‘useful moves’
will be a subset of ‘legal moves’. The state space is total validstates
possible in a problem and finding a problem solution is “starting atan initial
state, using a set of rules to move from one state to another and attempting to
end up in one of a set of final states.”
4. The semantic part is not required in “chess game” because, there is no
hidden meaning associated with any piece and all the move meanings are
explicit. However in natural language processing type of applications, where
there is “meaning” associated with words and “complete message” associated
with sentence, the semantic part captures and stores, the meaning of words
and message conveyed by sentence.
Thus, in AI, to design a program for solution, the first step is the creation of a
formal and manipulable description of problem itself. This includes performing
following activities:
1. Define a state space that contains all the possible configurations of therelevant
objects.
2. Specify one or more states within that space, which describe possible
situations from which problem solving process may start. These are called
initial states.
3. Specify one or more states that would be acceptable as solutions to the
problem. These are called goal states.
4. Specify a set of rules that describes the action (operators) available.
3 Opacity: Along with the advantages, there are certain disadvantages also
associated with production systems. Opacity is the problem generated by
combination of production rules. Though, the individual production rules
may be models of clarity, the combined operation and effects of control
program may be opaque. The opacity is generated because of less
prioritization of rules.
Any board position satisfying this condition would be declared as win for
corresponding player. The valid transitions of this problem are simply putting ‘1’
or ‘2’ in any of the element position containing 0.
In practice, all the valid moves are defined and stored. While selecting a move
Prof. Dhaval Khatri
Artificial Intelligence Problem Solving
it is taken from this store. In this game, valid transition table will be a vector
(having 39 entries), having 9 elements in each.
Start state 0 0
2 0 3
9 3 0
2 3 3
7 4 2
5 0 2
9 2 0
The tile adjacent to blank space can move into it. Wehave to
arrange the tiles in a sequence.”
The start state is any situation of tiles, and goal state is tiles arranged in a
specific sequence. Solution of this problem is reporting of “movement of tiles” in
order to reach the goal state. The transition function or legal move is any one tile
movement by one space in any direction (i.e. towards left or right or up or down)
if that space is blank. It is shown in following Fig. 2.4:
Here the data structure to represent the states can be 9-element vector indicating
the tiles in each board position. Hence, a starting state corresponding to above
configuration will be {1, blank, 4, 6, 5, 8, 2, 3, 7} (there can be various different
start positions). The goal state is {1, 2, 3, 4, 5, 6, 7, 8, blank}. Here, the possible
movement outcomes after applying a move can be many. They are represented as
tree. This tree is called state space tree. The depth of the tree will depend upon the
number of steps in the solution. The part of state space tree of 8-puzzle is shown
in Fig 2.5.
Table 2.2: Rules applied and their sequence in Missionaries and Cannibals problem
10 M, M, M, C C, C bank-1
3 M, C C, C, M, M bank-2
6 M, C, C, M C, M bank-1
3 C, C C, M, M, M bank-2
10 C, C, C M, M, M bank-1
7 C M, M, M, C, C bank-2
10 C, C M, M, M, C bank-1
7 0 M, M, M, C, C, C bank-2
1 1
2 1 -2-1
3 1 -2 -3 1
1 -3 -2 1
4 1- 2- 3- 4-1
1- 2- 4- 3- 1
1- 3- 2- 4- 1
1- 3- 4- 2- 1
1- 4- 2- 3-1
1- 4- 3- 2- 1
We can notice from here that the number of routes between cities is proportional
to the factorial of the (number of cities – 1), i.e., for three cities, the number of
routes will be equal to !2 (2x1), and for four cities, !3 (3x2x1).
While there are !9 = 362880 routes for 10 cities, there are !29 = 8.8 E30
possible routes for 30 cities. The travelling salesperson problem is a classic
example of combinatorial explosion, because the number of routes increases so
rapidly that there are no practical solutions for realistic number of cities. If it takes
1 hour of a mainframe CPU time to solve for 30 cities, it will take 30 hoursfor 31
cities and 330 hours for 32 cities. Practically, the actual application of such type
of problem is for routing a data packet on computer networks. It requires managing
thousands of cities. Hence for this much large amount of data the required problem
solution time will be unaffordable.
The solution of this problem is done using neural network. The neural network
can solve the 10 city case just as fast as the 30 city case whereas a conventional
computer takes much longer time for these.
Therefore, the 3 ¥ 3 square and 4 ¥ 4 square would require any set of 9 and 16
consecutive numbers respectively. The problem is finding out the placement of
numbers. The magic squares of order 3 ¥ 3, where numbers from 1 to 9 are filled,
is shown in Fig 2.10. It should be noted that there could be multiple solutions of
magic square problem.
Now, since we know the sum of numbers in each row, column and diagonals
is 15, we can form following equations:
x1 +x2 +x3 = 15 ……. (1)
x4 +x5 +x6 = 15 ……. (2)
x7 +x8 +x9 = 15 ……. (3)
x1 +x4 +x7 = 15 ……. (4)
x2 +x5 +x8 = 15 ……. (5)
Prof. Dhaval Khatri
Artificial Intelligence Problem Solving
Step 3: We will have to solve the above equations for finding the values of
numbers. You may notice that number x5 comes in most of the equations hence;
we should try to find the value of x5 first.
Add the equations (5), (7) and (8), to get:
x2 +x5 +x8 + x1 +x5 +x9 + x3 +x5 +x7 = 45
Putting values from equations (1) and (3), we get,
3 x5 = 15 x5 = 5.
Step 4: Put the value of x5 in the equations where it appears, we get,
x4 +x6 = 10 ……. (9)
x2 +x8 = 10 ……. (10)
x1 +x9 = 10 ……. (11)
x3 +x7 = 10 ……. (12)
Step 5: Assume x1 =1, hence x9 = 9 [from equation (11)]
After getting three values, our magic square will look like:
Now, try to find the location of number 2. Any number out of x2, x3, x4, and x7
cannot be 2, because in that case remaining number will be 12 to make the sum as
15, which is not permissible. Hence, either x6 or x8 will be 2. But, it is also not
possible, because in that case, x3 or x7 will be 4 and x2 or x4 will become 10, which
is again not possible. Therefore, x1 cannot be 1. Revise this step with another
assumption.
Step 6: Assume x2 = 1, hence x8 = 9 [from equation (10)].
After getting three values, our magic square will look like drawn ahead.
Now, any number out of x1 and x3 cannot be 2, because of the reason mentioned
in the above step, hence one number out of x4, x6, x7 and x9 will be equal to 2.
Assume x4 = 2, hence x6 = 8 [from equation (9)]. Notice that 3 can not come in the
same row, column or diagonal in which either 1 or 2 comes, because then, the
remaining number will be either 11 or 10, which is not possible. Hence, for x4 = 2,
x1, x3, and x7 cannot be 3, resulting in x9 = 3. However, this is also not possible,
because number 3 cannot come with 9 since the remaining number in that case
will also be 3, which cannot be. Therefore, x2 or x4 cannot be 2. Try another
assumption.
Step 7: Assume x7 or x9 = 2, resulting in x3 or x1 = 8 [from equations (12) and
(11)].
After getting one more number, our magic square will look like:
From the above squares, we can calculate the remaining numbers as, x9 = 4, x1
= 6, x3 =8, x6 =3 and x4 = 7 for the first square; and x7 = 4, x3 = 6, x1 =8, x4 =3 and
x6 = 7 for the second square; and the solutions for the magic square will be:
Solution of this problem means finding the sequence of actions for the monkey
to reach the banana. It is much simpler than the problems of water and jug or
Missionaries and Cannibals discussed above, hence, we leave it for the readers to
formulate the set of production rules and to find the appropriate sequence of
the actions required for the solution. The problem is pictorially represented in Fig
2.12.
R I NG
+ D O OR
—————
B ELL
Fig. 2.13: A cryptarithmatic problem
Fig. 2.14: The start and goal configuration of block world problem
structure necessary for problem solution. There is another type of problems like
“theorem proving” where the steps can be ignored. These are called ignorable
problems. These can be solved using simple control structures, which are easy
to implement. But there are certain types of problems like medical diagnosis
problems where if an operator is applied, it cannot be reverted to original state.
In such types of problems, the selection of operator is very critical because if a
wrong operator is applied, it may be possible that a solution is never obtained even
if it exists. Such types of problems are called ‘irrecoverable’ problems. Chess
playing is another irrecoverable problem where once you apply a move, you are
not allowed to revert. The recoverable problems require little complex control
structure, which checks the outcomes of every move and in case themove is
found to be wrong, it is reverted and initial state is restored back. The control
structure of irrecoverable problems is difficult because it will involve a system that
expands a great deal of effort in exploring each decision, since the decisions once
chosen must be final.
Thus, we can say that there are certain types of problems where any one solution
is enough and in other types of problems where to accept a solution all the possible
solutions need to be checked.
In this chapter, we will discuss the unguided search techniques and the guided
search techniques will be dealt with in the next chapter. Following search techniques
comes under the category of unguided search techniques:
(i) Breadth-First search (BFS)
(ii) Depth-First search (DFS)
(iii) Depth-Limited search (DLS)
(iv) Bidirectional search
The procedure to perform DFS for tree of node ‘n’ is given below:Procedure: unbounded DFS for tree
of node n, [ DFS1(n)].
Start
If n is a goal node thenStart
Solution : = n;
Exit;
End;
For each successor ni of n do
If ni is not an ancestor of n then
P1(ni);
in the backward direction (i.e. starting from goal node towards start node). Wherever two searches meet, the
process stops. The bidirectional search is advantageous then unidirectional search, because for a tree of depth
‘d’ and branching factor ‘b’, the unidirectional search requires bd number of comparisonsbut bidirectional
search requires bd/2 comparisons in each direction. Asbd/2 + bd/2 < bd, the bidirectional search has lesser time
complexity. However, it is applicable to only on those situations where search tree is completely defined, i.e.
all actions in state space are reversible. A bidirectional search is shown in Fig 2.17.
Here A, B, C, E, F are cities to be traveled and the distance between each pair of cities is mentioned in the
graph. In the solution of this problem, the location ofcities can be represented in graph by nodes indicating
the cities. The starting state
Informed Search is another technique that has additional information about the estimate distance from the
current state to the goal.
BFS stands for Breadth First Search is a vertex based technique for finding a shortest path in graph. It uses
a Queue data structure which follows first in first out. In BFS, one vertex is selected at a time when it is visited
and marked then its adjacent are visited and stored in the queue. It is slower than DFS.
Ex-
A
/\
B C
/ /\
D E F
Output is:
A, B, C, D, E, F
Depth First Search
DFS stands for Depth First Search is a edge based technique. It uses the Stack data structure, performs two
stages, first visited vertices are pushed into stack and second if there is no vertices then visited vertices are
popped.
Ex-
A
/\
B C
/ /\
D E F
Output is:
A, B, D, C, E, F
BFS vs DFS
S.NOBFS DFS
1. BFS stands for Breadth First Search. DFS stands for Depth First Search.
The Time complexity of BFS is O(V + The Time complexity of DFS is also
E) when Adjacency List is used and O(V + E) when Adjacency List is used
O(V^2) when Adjacency Matrix is used, and O(V^2) when Adjacency Matrix is
where V stands for vertices and E stands used, where V stands for vertices and E
5. for edges. stands for edges.
1. Breadth-first Search
2. Depth-first Search
3. Depth-limited Search
6. Bidirectional Search
1. Breadth-first Search:
o 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.
o 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.
Advantages:
o 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:
o It requires lots of memory since each level of the tree must be saved into memory to expand the next
level.
o BFS needs lots of time if the solution is far away from the root node.
Example: In the below tree structure, we have shown the traversing of the tree using BFS algorithm
from the root node S to goal node K. BFS search algorithm traverse in layers, so it will follow the path
which is shown by the dotted arrow, and the traversed path will be:
1. S---> A--->B---->C--->D---->G--->H--->E---->F---->I---->K
Time Complexity: Time Complexity of BFS algorithm can be obtained by the number of nodes traversed in
BFS until the shallowest Node. Where the d= depth of shallowest solution and b is a node at every state.
Space Complexity: Space complexity of BFS algorithm is given by the Memory size of frontier which is
O(bd).
Completeness: BFS is complete, which means if the shallowest goal node is at some finite depth, then BFS
will find a solution.
Optimality: BFS is optimal if path cost is a non-decreasing function of the depth of the node.
2. Depth-first Search
o Depth-first search isa recursive algorithm for traversing a tree or graph data structure.
o 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.
Note: Backtracking is an algorithm technique for finding all possible solutions using recursion.
Advantage:
o 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.
o It takes less time to reach to the goal node than BFS algorithm (if it traverses in the right path).
Disadvantage:
o There is the possibility that many states keep re-occurring, and there is no guarantee of finding the
solution.
o DFS algorithm goes for deep down searching and sometime it may go to the infinite loop.
Example:
In the below search tree, we have shown the flow of depth-first search, and it will follow the order as:
It will start searching from root node S, and traverse A, then B, then D and E, after traversing E, it will
backtrack the tree as E has no other successor and still goal node is not found. After backtracking it will
traverse node C and then G, and here it will terminate as it found goal node.
Completeness: DFS search algorithm is complete within finite state space as it will expand every node within
a limited search tree.
Time Complexity: Time complexity of DFS will be equivalent to the node traversed by the algorithm. It is
given by:
Where, m= maximum depth of any node and this can be much larger than d (Shallowest solution depth)
Space Complexity: DFS algorithm needs to store only single path from the root node, hence space complexity
of DFS is equivalent to the size of the fringe set, which is O(bm).
Optimal: DFS search algorithm is non-optimal, as it may generate a large number of steps or high cost to
reach to the goal node.
o Standard failure value: It indicates that problem does not have any solution.
o Cutoff failure value: It defines no solution for the problem within a given depth limit.
Advantages:
Disadvantages:
o It may not be optimal if the problem has more than one solution.
Example:
Completeness: DLS search algorithm is complete if the solution is above the depth-limit.
Optimal: Depth-limited search can be viewed as a special case of DFS, and it is also not optimal even if ℓ>d.
Advantages:
o Uniform cost search is optimal because at every state the path with the least cost is chosen.
Disadvantages:
o 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.
Example:
Completeness:
Uniform-cost search is complete, such as if there is a solution, UCS will find it.
Time Complexity:
Let C* is Cost of the optimal solution, and ε is each step to get closer to the goal node. Then the number of
steps is = C*/ε+1. Here we have taken +1, as we start from state 0 and end to C*/ε.
Space Complexity:
The same logic is for space complexity so, the worst-case space complexity of Uniform-cost search is O(b1 +
[C*/ε]).
Optimal:
Uniform-cost search is always optimal as it only selects a path with the lowest path cost.
This algorithm performs depth-first search up to a certain "depth limit", and it keeps increasing the depth limit
after each iteration until the goal node is found.
This Search algorithm combines the benefits of Breadth-first search's fast search and depth-first search's
memory efficiency.
The iterative search algorithm is useful uninformed search when search space is large, and depth of goal node
is unknown.
Advantages:
o Itcombines the benefits of BFS and DFS search algorithm in terms of fast search and memory
efficiency.
Disadvantages:
o The main drawback of IDDFS is that it repeats all the work of the previous phase.
Example:
Following tree structure is showing the iterative deepening depth-first search. IDDFS algorithm performs
various iterations until it does not find the goal node. The iteration performed by the algorithm is given as:
1'st Iteration-----> A
2'nd Iteration----> A, B, C
3'rd Iteration------>A, B, D, E, C, F, G
4'th Iteration------>A, B, D, H, I, E, C, F, K, G
In the fourth iteration, the algorithm will find the goal node.
Completeness:
Time Complexity:
Let's suppose b is the branching factor and depth is d then the worst-case time complexity is O(bd).
Space Complexity:
Optimal:
IDDFS algorithm is optimal if path cost is a non- decreasing function of the depth of the node.
Bidirectional search can use search techniques such as BFS, DFS, DLS, etc.
Advantages:
Disadvantages:
Example:
In the below search tree, bidirectional search algorithm is applied. This algorithm divides one graph/tree into
two sub-graphs. It starts traversing from node 1 in the forward direction and starts from goal node 16 in the
backward direction.
Problem Solving in games such as “Sudoku” can be an example. It can be done by building an
artificially intelligent system to solve that particular problem. To do this, one needs to define the
problem statements first and then generating the solution by keeping the conditions in mind.
Some of the most popularly used problem solving with the help of artificial intelligence are:
1. Chess.
2. Travelling Salesman Problem.
3. Tower of Hanoi Problem.
4. Water-Jug Problem.
5. N-Queen Problem.
Problem Searching
In general, searching refers to as finding information one needs.
Searching is the most commonly used technique of problem solving in artificial intelligence.
The searching algorithm helps us to search for solution of particular problem.
Problem
Problems are the issues which comes across any system. A solution is needed to solve that
particular problem.