CS6659 AI UNIT 1 Notes
CS6659 AI UNIT 1 Notes
CS6659 AI UNIT 1 Notes
Elements of vector:
0 : Empty
1:X
2: O
The vector is a ternary number
Store inside the program a move-table (lookup table):
#Elements in the table: 19683 (=39)
Element = A vector which describes the most suitable move from the current game-board
Solution 3
Data Structure
1. Game-board: Use vector as described for the above program
2. List:
Contains possible game-boards generated from the current game-board
Each the game-board is augmented a score indicating the possibility of victory of the
current turn
Algorithm:
1. If it is a win, give it the highest rating.
2. Otherwise, consider all the moves the opponent could make next. Assume the opponent will
make the move that is worst for us. Assign the rating of that move to the current node.
3. The best node is then the one with the highest rating.
CHAPTER - 2
PROBLEMS, PROBLEM SPACES AND SEARCH
2. FORMULATING PROBLEMS
Problem formulation is the process of deciding what actions and states to consider, given
a goal
Formulate Goal, Formulate problem
Search
Execute
Kangayam Karur
61
Mettupalayam
61 74
32
Palladam
37 Trichy
38
Dindigul
320
Palani 57 97
37 Pollachi 60
Coimbatore
Chennai (Goal)
Vellore
Erode Salem
Current Position
While pawn at square (e, 2), AND Square (e, 3) is empty, AND Square (e , 4 ) is empty.
Changing Board Position
Move pawn from Square (e, 2) to Square ( e , 4 ) .
Some of the problems that fall within the scope of AI and the kinds of techniques will be useful
to solve these problems.
GoalTest
Any position in which the opponent does not have a legal move and his or her king is under
attack.
Example: 3 Water Jug Problem
A Water Jug Problem: You are given two jugs, a 4-gallon one and a 3-gallon one, a pump which
has unlimited water which you can use to ll the jug, and the ground on which water may be
poured. Neither jug has any measuring markings on it. How can you get exactly 2 gallons of
water in the 4-gallon jug?
State: (x, y) x= 0, 1, 2, 3, or 4 y= 0, 1, 2, 3
x represents quantity of water in 4-gallon jug and y represents quantity of water in 3-gallon jug.
Start state: (0, 0).
Goal state: (2, n) for any n. Attempting to end up in a goal state.( since the problem doesnt
specify the quantity of water in 3-gallon jug)
(4, 0) (0, 3)
Now for each leaf node, generate all its successors by applying all the rules that
are appropriate.
(4, 0) (0, 3)
Algorithm
1. Create a variable called NODE-LIST and set it to initial state.
2. Unit a goal state is found or NODE-LIST is empty do
a. Remove the first element from NODE-LIST and call it E. if NODE-LIST is empty,
quit.
b. For each way that each rule can match the state described in E do:
i. Apply the rule to generate a new state.
ii. If the new state is a goal state, quit and return this state.
iii. Otherwise, add the new state to the end of NODE-LIST.
2.3.1.1.2 Depth First Search
Algorithm
1.If the initial state is the goal state, quit and return success.
2.Otherwise do the following until success or failure is signaled:
a. Generate a successor, E, of initial state. If there are no more successor, signal failure.
b. Call depth first search, with E as the initial state.
c. If the success is returned, signal success. Otherwise continue in this loop.
Backtracking
In this search, we pursue a single branch of the tree until it yields a solution or until a
decision to terminate the path is made.
It makes sense to terminate a path if it reaches dead-end, produces a previous state. In
such a state backtracking occurs.
(4,3)
Advantages of Depth First search
DFS requires less memory since only the nodes on the current path are stored.
By chance DFS may find a solution without examining much of the search space at all.
Advantages of Breath First search
BFS cannot be trapped exploring a blind alley.
If there is a solution, BFS is guaranteed to find it.
If there are multiple solutions, then a minimal solution will be found.
Traveling Salesman Problem (with 5 cities):
A salesman is supposed to visit each of 5 cities shown below. There is a road between each pair
of cities and the distance is given next to the roads. Start city is A. The problem is to find the
shortest route so that the salesman visits each of the cities only once and returns to back to A.
A A A
B C D B C D
A A
B C D B C D
(6) (6)
G H E F G H E F
(3) (2)
fig:1.10 Tree getting expansion according to best first search
Here, at any step, the most promising node having least value of utility function is chosen for
expansion.
In the tree shown above, best first search technique is applied, however it is beneficial sometimes
to search a graph instead of tree to avoid the searching of duplicate paths. In the process to do so,
searching is done in a directed graph in which each node represents a point in the problem space.
This graph is known as OR-graph. Each of the branches of an OR graph represents an alternative
problem solving path.
Two lists of nodes are used to implement a graph search procedure discussed above. These are
1.OPEN: these are the nodes that have been generated and have had the heuristic function
applied to them but not have been examined yet.
2.CLOSED: these are the nodes that have already been examined. These nodes are kept in
the memory if we want to search a graph rather than a tree because whenever a node
will be generated, we will have to check whether it has been generated earlier.
Heuristics Rules
1. If sum of two n digit operands yields n+1 digit result then the n+1th digit has to be
one.
2. Sum of two digits may or may not generate carry.
3. Whatever might be the operands the carry can be either 0 or 1.
4. No two distinct alphabets can have same numeric code.
5. Whenever more than 1 solution appears to be existing, the choice is governed by the fact
that no two alphabets can have same number code.
4. What is an AI technique?