Professional Documents
Culture Documents
-> AI APPLICATIONS
-> A*
-> IDA*
oufastupdates.com
oufastupdates.com
oufastupdates.com
oufastupdates.com
oufastupdates.com
oufastupdates.com
oufastupdates.com
oufastupdates.com
oufastupdates.com
oufastupdates.com
oufastupdates.com
oufastupdates.com
oufastupdates.com
oufastupdates.com
oufastupdates.com
oufastupdates.com
oufastupdates.com
oufastupdates.com
oufastupdates.com
oufastupdates.com
oufastupdates.com
oufastupdates.com
oufastupdates.com
oufastupdates.com
oufastupdates.com
oufastupdates.com
oufastupdates.com
oufastupdates.com
oufastupdates.com
oufastupdates.com
oufastupdates.com
oufastupdates.com
oufastupdates.com
oufastupdates.com
oufastupdates.com
oufastupdates.com
oufastupdates.com
oufastupdates.com
oufastupdates.com
oufastupdates.com
oufastupdates.com
oufastupdates.com
oufastupdates.com
The Missionaries and Cannibals Problem:
Three missionaries and three cannibals find the mselves on one side of a river. They have
would like to get to the other side. But the missionaries are not sure what else the cannibals
agreed to. So the missionaries managed the trip across the river in such a way that the
numbe r of missionaries on either side of the river is never less than the number of
cannibals who are on the same side. The only boar available holds only two at a time. How
can everyone get across the river without the missionaries risking being eaten?
Solution:-
The state for this problem can be defined as
where i represents the number missionaries in one side of a river . j represents the numbe r
of cannibals in the same side of river. The initial state is (3,3), that is three missionaries and
three cannibals one side of a river , (Bank 1) and ( 0,0) on another side of the river (bank 2)
. the goal state is to get (3,3) at bank 2 and (0,0) at bank 1.
5. There is no restriction on the numbe r of trips that can be made to reach of the goal.
oufastupdates.com
oufastupdates.com
This kind of problem is often solved by a graph search method. Represent the problem as a set of
states which are snapshots of the world and operators which transform one state into another
state are mapped to nodes of the graph and operators are the edges of the graph. The following
procedure shows the graph search algorithm in PROLOG, for Missionaries and Cannibals
Problem.
Path finding.
* The search for a path terminates when we have nowhere t0o go.
A path from start to Finish, starts with a node, X,connected to start followed by a path from X to
Finish.
Now we returen to the peoblem or rrepresenting tyhe missionaries and cannibals problem;
*A State is one "snapshot" in time.
*For this problem the only infoemation we need to fully characterize the state is :
*the number of missionaries on the left bank,
*the number of cannibals on the left bank,
*the side the boat is on.
oufastupdates.com
All other information can be deduced from these thres items.
Overview of solution.
PROLOG Code.
make_move(state(M1,C1,right),state(M2,C2,right),move M,C,left)) :-
M is M2 -M1
C is C2 - C1.
oufastupdates.com
A move is characterized by the nummber of missionar5ies and the number of canniblls taken in
the boal at6 one time.
Since the boat can carry no more than two peopel at once, the only possible combinations are:
carry (2,0)
carry (1,0)
carry (1,1)
carry (0,1)
carry (0,2).
Where carry (M,C) means the boat will carry M, missionaries and C.cannibals on one trip.
Feasible Moves
*Once we hafe found a possible move, we have to confirm that it is feasible It is not feasible to
move more missionaries or more cannibals than that are present on one bank.
When the stae is stae(M1,C1,left) and we try carry (M,C)then
M ≤ M1 and C ≥ C1
must be true.
*When the state is state(M1, C1, left) and we try carry (M,C) then
M + M1 ≤ AND C + C1 ≤ 3
must be true.
Legal Moves.
* Once we have found a feasible move, we must check that it is legal, i.e no Missionaries
must be eaten.
legal(X,X).
legal(3,X).
legal(O,X).
*The only safe combinations are when there are equal numbe rs of Missionaries and
cannibals or all the Missionaries are on one side.
oufastupdates.com
newstate(state(M1,C1,left), state(M2,C2,right)):-
carry(M,C),
M ≤ M1
C ≤ C1
M2 is M1 - M2,
C2 is C1 - C,
legal(M2,C2)
carry(M,C),
M2 is M1 + M,
C2 is C1 + C,
M2 ≤ 3,
C2 ≤ 3,
legal(M2, C2)
oufastupdates.com
WaterJugProblem
WaterJugProblem
Statement :- We are given 2 jugs, a 4 liter one and a 3- liter one. Neither has any measuring
markers on it. There is a pump that can be used to fill the jugs with water. How can we get
exactly 2 liters of water in to the 4-liter jugs?
Solution:-
The state space for this problem can be defined as
{ ( i ,j ) i = 0,1,2,3,4 j = 0,1,2,3}
‘i’ represents the number of liters of water in the 4-liter jug and ‘j’ represents the number of liters
of water in the 3-liter jug. The initial state is ( 0,0) that is no water on each jug. The goal state is
to get ( 2,n) for any value of ‘n’.
To solve this we have to make some assumptions not mentioned in the problem. They are
The various operators (Production Rules) that are available to solve this problem may be stated
as given in the following figure .
oufastupdates.com
oufastupdates.com
oufastupdates.com
Constraint Satisfaction Problem1.
CONSTRAINT SATISFACTION:-
Many problems in AI can be considered as proble ms of constraint satisfaction, in which the
goal state satisfies a given set of constraint. constraint satisfaction problems can be solved
by using any of the search strategies. The general form of the constraint satisfaction
procedure is as follows:
Until a complete solution is found or until all paths have led to lead ends, do
2. Apply the constraint inference rules to the selected node to generate all possible new
constraints.
3. If the set of constraints contains a contradiction, then report that this path is a dead end.
5. If neither a constraint nor a complete solution has been found then apply the rules to
generate new partial solutions. Insert these partial solutions into the search graph.
SEND
+ MORE
----------
MONEY
----------
Assign decimal digit to each of the letters in such a way that the answer to the proble m is
correct to the same letter occurs more than once , it must be assign the same digit each time
. no two different letters may be assigned the same digit. Consider the crypt arithmetic
problem.
SEND
+ MORE
-----------
MONEY
-----------
CONSTRAINTS:-
oufastupdates.com
2. only single digit number can be assign to a letter.
2. Assumption can be made at various levels such that they do not contradict each other.
Goal State: the digits to the letters must be assigned in such a manner so that the sum is
satisfied.
Solution Process:
1. initial guess m=1 because the sum of two single digits can generate at most a carry '1'.
2. When n=1 o=0 or 1 because the largest single digit numbe r added to m=1 can generate
the sum of either 0 or 1 depend on the carry received from the carry sum. By t his we
conclude that o=0 because m is already 1 hence we cannot assign same digit another
letter(rule no.)
3. We have m=1 and o=0 to get o=0 we have s=8 or 9, again depending on the carry
received from the earlier sum.
oufastupdates.com
The same process can be repeated further. The proble m has to be composed into various
constraints. And each constraints is to be satisfied by guessing the possible digits that the
letters can be assume d that the initial guess has been already made . rest of the process is
being shown in the form of a tree, using depth-first search for the clear understandability
of the solution process.
D>6(Controduction)
oufastupdates.com
oufastupdates.com
Breadth First Search Procedure.
Breadth First Search (BFS): This is also a brute force search procedure like DFS.
We are searching progresses level by level. Unlike DFS which goes deep into the tree. An
operator employed to generate all possible children of a node. BFS being a brute force search
generates all the nodes for identifying the goal.
oufastupdates.com
ALGORITHM:
Step 3. Remove the first node from the Start and call this node “a”
Step 5. Else if node “a” has successors generate all of them and add them at the tail of
“START”
Step 6. Go to step 2.
Advantages:
3. The amount of time needed to generate all the nodes is considerable because of the time
complexity.
5. The searching process remembers all unwanted nodes, which are not practical use for the
search process.
oufastupdates.com
What do you know about DFS.?
Depth first search: This is a very simple type of brute force searching techniques. The
search begins by expanding the initial node i.e. by using an operator generate all successors
of the initial node and test them.
This procedure finds whether the goal can be reached or not but the path it has to follow
has not been mentioned. Diving downward into a tree as quickly as possible performs Dfs
searches.
Algorithm:
Step3: Remove the first node from START. Call this node a.
Step5: Else if node a has successors, generate all of them and add the m at the beginning
Of START.
Step6: Go to Step 2.
The major draw back of the DFS is the determination of the depth citric with the search
has to proceed this depth is called cut of depth.
The value of cutoff depth is essential because the search will go on and on. If the cutoff
depth is smaller solution may not be found. And if cutoff depth is large time complexity will
be more.
Advantages: DFS requires less me mory since only the nodes on the current path are stored.
By chance DFS may find a solution with out examining much of the search space at all.
oufastupdates.com