3. shiwani gupta 3
Agents
• An agent is an entity that can be viewed as perceiving its
environment through sensors and acting upon that environment
through effectors/actuators to achieve goals
• Ideal, rational, human, robotic, software, autonomous
• Simple reflex, Model Based, Goal based, Utility based
• The Simple Reflex Agent will work only if the correct decision
can be made on the basis of the current percept.
4. SHIWANI GUPTA 4
Drawback of Simple reflex agents (Module2)
• unable to plan ahead
• limited in what they can do because their actions are determined
only by the current percept
• have no knowledge of what their actions do nor of what they are
trying to achieve.
Solution:
one kind of goal-based agent… problem-solving agent.
(Problem-solving agents decide what to do by finding sequences of
actions that lead to desirable states)
• Goal formulation based on current situation
• Problem Formulation is the process of deciding what actions and
states to consider
• Search is the process of looking for different possible sequences of
actions leading to goal state
• Execution is carrying out actions recommended as solution by search
algorithm
A goal and a set of means for achieving the goal is called a problem, and
the process of exploring what the means can do is called search
8. 8
Toy Problems vs.
Real-World Problems
Toy Problems
– concise and exact
description
– used for illustration
purposes
– used for performance
comparisons
• Simple to describe
• Trivial to solve
Real-World Problems
– no single, agreed-upon
description
– people care about the
solutions
• Hours to define
9. SHIWANI GUPTA 9
Toy problems
– Touring in Romania
– 8-Puzzle/Sliding Block Puzzle
– Robotic Assembly
– 8 Queen
– Missionaries and Cannibals
– Cryptarithmetic
– Water Jug Problem
10. 10
Real-World Problem:
Touring in Romania
Oradea
Bucharest
Fagaras
Pitesti
Neamt
Iasi
Vaslui
Urziceni
Hirsova
Eforie
Giurgiu
Craiova
Rimnicu Vilcea
Sibiu
Dobreta
Mehadia
Lugoj
Timisoara
Arad
Zerind
120
140
151
75
70
111
118
75
71
85
90
211
101
97
138
146
80
99
87
92
142
98
86
Aim: find a course of action that satisfies a number of specified conditions
11. 13
Touring in Romania:
Search Problem Definition
• initial state:
– In(Arad)
• possible Actions:
– DriveTo(Zerind), DriveTo(Sibiu), DriveTo(Timisoara), etc.
• goal state:
– In(Bucharest)
• step cost:
– distances between cities
15. SHIWANI GUPTA 17
Example: robotic assembly
• states?: real-valued coordinates of robot joint angles; parts of the
object to be assembled
• actions?: continuous motions of robot joints
• goal test?: complete assembly
• path cost?: time to execute
16. SHIWANI GUPTA 18
Example: 8 queens problem
The incremental formulation involves placing queens one by one,
whereas
the complete-state formulation starts with all 8 queens on the board
and moves them around.
In either case, the path cost is of no interest because only the final
state counts; algorithms are thus compared only on search cost.
Goal test: 8 queens on board, none attacked.
Path cost: zero.
States: any arrangement of 0 to 8 queens on board.
Operators: add a queen to any square.
17. SHIWANI GUPTA 19
Incremental formulation
The fact that placing a queen where it is already attacked cannot work,
because subsequent placing of other queens will not undo the attack.
So we might try the following:
States: arrangements of 0 to 8 queens with none attacked
Operators: place a queen in the left-most empty column such that it is not
attacked by any other queen
It is easy to see that the actions given
can generate only states with no attacks;
but sometimes no actions will be possible.
For example, after making the first seven
choices (left-to-right)
A quick calculation shows that there are only
Much fewer sequences to investigate.
The right formulation makes a big
difference to the size of the search space.
18. SHIWANI GUPTA 20
Complete formulation
• States: arrangements of 8 queens, one in each column.
• Operators: move any attacked queen to another square in the
same column.
19. SHIWANI GUPTA 21
Example: Missionaries and cannibals problem
(Three missionaries and three cannibals are on one side of a river, along with a boat that can
hold max two people. Find a way to get everyone to the other side, without ever leaving a group
of missionaries in one place outnumbered by the cannibals in that place)
States: a state consists of an ordered sequence of three numbers representing
the number of missionaries, cannibals, and boats on the bank of the river
from which they started. Thus, the start state is (3,3,1)
Operators: from each state the possible operators are to take either one
missionary, one cannibal, two missionaries, two cannibals, or one of each
across in the boat. Thus, there are at most five operators, although most
states have fewer because it is necessary to avoid illegal states. Note that if
we had chosen to distinguish between individual people then there would
be 27 operators instead of just 5
Goal test: reached state (0,0,1)
Path cost: number of crossings
20. 22
Missionaries and Cannibals:
Successor Function
state set of <action, state>
(L:3m,3c,b-R:0m,0c) → {<2c, (L:3m,1c-R:0m,2c,b)>,
<1m1c, (L:2m,2c-R:1m,1c,b)>,
<1c, (L:3m,2c-R:0m,1c,b)>}
(L:3m,1c-R:0m,2c,b) → {<2c, (L:3m,3c,b-R:0m,0c) >,
<1c, (L:3m,2c,b-R:0m,1c)>}
(L:2m,2c-R:1m,1c,b) → {<1m1c, (L:3m,3c,b-R:0m,0c) >,
<1m, (L:3m,2c,b-R:0m,1c)>}
22. SHIWANI GUPTA 24
LEFT BANK RIGHT BANK
0 Initial setup: MMMCCC B -
1 Two cannibals cross over: MMMC B CC
2 One comes back: MMMCC B C
3 Two cannibals go over again: MMM B CCC
4 One comes back: MMMC B CC
5 Two missionaries cross: MC B MMCC
6 A missionary & cannibal return: MMCC B MC
7 Two missionaries cross again: CC B MMMC
8 A cannibal returns: CCC B MMM
9 Two cannibals cross: C B MMMCC
10 One returns: CC B MMMC
11 And brings over the third: - B MMMCCC
23. 25
Missionaries and Cannibals: Goal
State and Path Cost
• goal state:
– all missionaries, all
cannibals, and the
boat are on the right
bank.
• path cost
– step cost: 1 for each
crossing
– path cost: number of
crossings = length of path
• solution path:
– 4 optimal solutions
– cost: 11
24. SHIWANI GUPTA 30
Example: Cryptarithmetic
States: a cryptarithmetic puzzle with some letters replaced by digits.
Operators: replace all occurrences of a letter with a digit not already
appearing in the puzzle.
Goal test: puzzle contains only digits, and represents a correct sum.
Path cost: zero. All solutions equally valid.
One way to do this is to adopt a fixed order, e.g., alphabetical order.
A better choice is to do whichever is the most constrained substitution,
that is, the letter that has the fewest legal possibilities given the
constraints of the puzzle.
25. Crypt-Arithmetic puzzle
• Problem Statement:
– Solve the following puzzle by assigning numeral (0-9) in such a way that
each letter is assigned unique digit which satisfy the following addition.
– Constraints : No two letters have the same value. (The constraints of
arithmetic).
• Initial Problem State
– S = ? ; E = ? ;N = ? ; D = ? ; M = ? ;O = ? ; R = ? ;Y = ?
S E N D
+ M O R E
_________________________________
M O N E Y
_________________________________
26. Carries:
C4 = ? ;C3 = ? ;C2 = ? ;C1 = ?
Constraint equations:
Y = D + E C1
E = N + R + C1 C2
N = E + O + C2 C3
O = S + M + C3 C4
M = C4
C4 C3 C2 C1 Carry
S E N D
+ M O R E
_________________________________
M O N E Y
_________________________________
27. • We can easily see that M has to be non zero
digit, so the value of C4 =1
1. M = C4 M = 1
2. O = S + M + C3 → C4
For C4 =1, S + M + C3 > 9
S + 1 + C3 > 9 S+C3 > 8.
If C3 = 0, then S = 9 else if C3 = 1,
then S = 8 or 9.
• We see that for S = 9
– C3 = 0 or 1
– It can be easily seen that C3 = 1 is not
possible as O = S + M + C3 O = 11
O has to be assigned digit 1 but 1 is
already assigned to M, so not possible.
– Therefore, only choice for C3 = 0, and
thus O = 10. This implies that O is
assigned 0 (zero) digit.
• Therefore, O = 0
M = 1, O = 0
C4 C3 C2 C1 Carry
S E N D
+ M O R E
_________________________________
M O N E Y
_________________________________
Y = D + E → C1
E = N + R + C1 → C2
N = E + O + C2 → C3
O = S + M + C3 → C4
M = C4
28. 3. Since C3 = 0; N = E + O + C2 produces no
carry.
• As O = 0, N = E + C2 .
• Since N E, therefore, C2 = 1.
Hence N = E + 1
• Now E can take value from 2 to 8 {0,1,9
already assigned so far }
– If E = 2, then N = 3.
– Since C2 = 1, from E = N + R + C1 ,
we get 12 = N + R + C1
• If C1 = 0 then R = 9, which is not
possible as we are on the path with
S = 9
• If C1 = 1 then R = 8, then
» From Y = D + E , we get 10 +
Y= D + 2 .
» For no value of D, we can get Y.
– Try similarly for E = 3, 4. We fail in
each case.
C4 C3 C2 C1 Carry
S E N D
+ M O R E
_________________________________
M O N E Y
_________________________________
Y = D + E → C1
E = N + R + C1 → C2
N = E + O + C2 → C3
O = S + M + C3 → C4
M = C4
29. • If E = 5, then N = 6
– Since C2 = 1, from E = N + R + C1 ,
we get 15 = N + R + C1 ,
– If C1 = 0 then R = 9, which is not
possible as we are on the path with
S = 9.
– If C1 = 1 then R = 8, then
• From Y = D + E , we get 10 + Y=
D + 5 i.e., 5 + Y = D.
• If Y = 2 then D = 7. These values
are possible.
• Hence we get the final solution as
given below and on backtracking, we
may find more solutions.
S = 9 ; E = 5 ; N = 6 ; D = 7 ;
M = 1 ; O = 0 ; R = 8 ;Y = 2
C4 C3 C2 C1 Carry
S E N D
+ M O R E
_________________________________
M O N E Y
_________________________________
Y = D + E → C1
E = N + R + C1 → C2
N = E + O + C2 → C3
O = S + M + C3 → C4
M = C4
30. Constraints:
Y = D + E C1
E = N + R + C1 C2
N = E + O + C2 C3
O = S + M + C3 C4
M = C4
Initial State
M = 1 → C4 = 1
O = 1 + S + C3
O
S = 9 S = 8
O
C3 = 0 C3 = 1
O = 0 O = 1
Fixed
M = 1
O = 0
N = E + O + C2 = E + C2 → C2 = 1 (must) → N = E + 1
E = 2 E = 3 ….. E = 5
N = 3 N = 6
E = N + R + C1 E = N + R + C1
10 + 2 = 3 + R + C1 10 + 5 = 6 + R + C1
O O
R = 9 R = 8 R = 9 R = 8
C1 =0 C1 = 1 C1 = 0 C1 = 1
O O
10 + Y = D + E = D + 2 10 + Y = D + E = D + 5
O O
D = 8 D = 9 D = 7
Y = 0 Y = 1 Y = 2
The first solution obtained is:
M = 1, O = 0, S = 9, E = 5, N = 6, R = 8, D = 7, Y = 2
31. C4 C3 C2 C1 Carries
B A S E
+ B A L L
_________________________________
G A M E S
_________________________________
Constraints equations are:
E + L = S → C1
S + L + C1= E → C2
2A + C2 = M → C3
2B + C3 = A → C4
G = C4
Initial Problem State
G = ?; A = ?;M = ?; E = ?; S = ?; B = ?; L = ?
32. 1. G = C4 G = 1
2. 2B+ C3 = A → C4
2.1 Since C4 = 1, therefore, 2B+ C3 > 9 B can take values from 5 to 9.
2.2 Try the following steps for each value of B from 5 to 9 till we get a
possible value of B.
if C3 = 0 A = 0 M = 0 for C2 = 0 or M = 1 for C2 = 1
• If B = 5
if C3 = 1 A = 1 (as G = 1 already)
• For B = 6 we get similar contradiction while generating the search tree.
• If B = 7 , then for C3 = 0, we get A = 4 M = 8 if C2 = 0 that leads to
contradiction, so this path is pruned. If C2 = 1, then M = 9 .
3. Let us solve S + L + C1 = E and E + L = S
• Using both equations, we get 2L + C1 = 0 L = 5 and C1 = 0
• Using L = 5, we get S + 5 = E that should generate carry C2 = 1 as shown
above
• So S+5 > 9 Possible values for E are {2, 3, 6, 8} (with carry bit C2 = 1 )
• If E = 2 then S + 5 = 12 S = 7 (as B = 7 already)
• If E = 3 then S + 5 = 13 S = 8.
• Therefore E = 3 and S = 8 are fixed up.
4. Hence we get the final solution as given below and on backtracking, we may find
more solutions. In this case we get only one solution.
G = 1; A = 4; M = 9; E = 3; S = 8;B = 7; L = 5
33. SHIWANI GUPTA 39
MARS Each of the ten letters (m, a, r, s, v, e,
+ VENUS n, u, t, and p) represents a unique number
+ URANUS in the range 0 .. 9.
+ SATURN
------------
NEPTUNE Solution: NEPTUNE = 1078610
M=4, A=5, R=9, etc.
34. Water Jug Problem
• Problem Statement: "You are given two jugs, a
4-gallon one and a 3-gallon one. Neither has
any measuring markers on it. There is a tap
that can be used to fill the jugs with water.
How can you get exactly 2 gallons of water
into the 4-gallon jug?"
SHIWANI GUPTA 40
35. Production Rules
Rules Conclusions
R1:(X, Y | X < 4) → (4, Y) {Fill 4-gallon jug}
R2:(X, Y | Y < 3) →(X, 3) {Fill 3-gallon jug}
R3:(X, Y | X > 0) →(0, Y) {Empty 4-gallon jug}
R4:(X, Y | Y > 0) →(X, 0) {Empty 3-gallon jug}
R5:(X, Y | X+Y >= 4 ΛY > 0) →(4, Y –(4 –X)) {Pour water from 3-gallon jug into 4-
gallon jug until 4-gallon jug is full}
R6:(X, Y | X+Y >= 3 ΛX > 0) →(X –(3 –Y), 3)) {Pour water from 4-gallon jug into 3-
gallon jug until 3-gallon jug is full}
R7:(X, Y | X+Y <= 4 ΛY > 0) → (X+Y, 0) {Pour all water from 3-gallon jug into 4- gallon jug }
R8:(X, Y | X+Y <= 3 ΛX > 0) →(0, X+Y) {Pour all water from 4-gallon jug into 3- gallon jug }
R9:(X, Y | X > 0) → (X –D, Y) {Pour some water D out from 4- gallon jug}
R10:(X, Y | Y > 0) →(X, Y -D) {Pour some water D out from 3- gallon jug}
SHIWANI GUPTA 41
36. SHIWANI GUPTA 42
2 0
Number Rules applied 4-g jug 3-g jug
of steps
1 Initial State 0 0
2 R1 {Fill 4-gallon jug} 4 0
3 R6 {Pour from 4 to 3-g jug until it is full } 1 3
4 R4 {Empty 3-gallon jug} 1 0
5 R8 {Pour all water from 4 to 3-gallon jug} 0 1
6 R1 {Fill 4-gallon jug} 4 1
7 R6 {Pour from 4 to 3-g jug until it is full} 2 3
8 R4 {Empty 3-gallon jug}
Goal State
Solution
37. Water Jug Problem
Given a full 5-gallon jug and a full 2-gallon jug, fill the 2-gallon jug with
exactly one gallon of water.
• State: ?
• Initial State: ?
• Operators: ?
• Goal State: ?
5
2
38. SHIWANI GUPTA 45
Real World problems
• Route Finding applications, such as routing in computer networks,
automated travel advisory systems, and airline travel planning systems.
• Touring and traveling salesperson problem is a famous touring problem
in which each city must be visited exactly once. The aim is to find the
shortest tour.
• VLSI layout with cell layout and channel routing.
• Robot navigation is a generalization of the route-finding problem
described earlier. Rather than a discrete set of routes, a robot can move in a
continuous space with (in principle) an infinite set of possible actions and
states.
• Assembly sequencing of complex objects by a robot, the problem is to
find an order in which to assemble the parts of some object. If the wrong
order is chosen, there will be no way to add some part later in the sequence
without undoing some of the work already done.
• Monkey Banana Problem
39. General Route Finding Problem
• Problem Statement
• States: Locations
• Initial State: Starting Point
• Successor Function(Operators): Move from one location
to other
• Goal Test: Arrive at certain location
• Path Cost: Money, time, travel, comfort, scenery,…
SHIWANI GUPTA 46
40. Travelling Salesman Problem
• Problem Statement
• States: Locations/cities
• Initial State: Starting Point
• Successor Function(Operators): Move from one location
to other
• Goal Test: All locations visited, Agent at initial location
• Path Cost: Distance between locations
SHIWANI GUPTA 47
41. VLSI layout problem
• Problem Statement
• States: Positions of components, wires on chip
• Initial State:
– Incremental
– Complete State
• Successor Function(Operators)
– Incremental
– Complete State
• Goal Test: All components placed and connected as specified
• Path Cost: distance, capacity, no. of connections per component
SHIWANI GUPTA 48
42. Robot Navigation
• Problem Statement
• States: Locations, Position of actuator
• Initial State: Start pos
• Successor Function(Operators): Movement, actions of
actuators
• Goal Test: Task Dependent
• Path Cost: Distance, Energy consumption
SHIWANI GUPTA 49
43. Assembly Sequencing
• Problem Statement
• States: Location of components
• Initial State: No components assembled
• Successor Function(Operators): Place component
• Goal Test: System fully assembled
• Path Cost: Number of moves
SHIWANI GUPTA 50
44. Monkey Banana Problem
• Problem Statement
• States:
• Initial State: Monkey on the floor without bananas
• Successor Function(Operators)
• Goal Test
• Path Cost: The number of moves by monkey to get bananas
SHIWANI GUPTA 51
45. Search Problem
• State space
– each state is an abstract representation of the
environment
– the state space is discrete
• Initial state
• Successor function
• Goal test
• Path cost
46. Search Problem
• State space
• Initial state:
– usually the current state
– sometimes one or several hypothetical states
(“what if …”)
• Successor function
• Goal test
• Path cost
47. Search Problem
• State space
• Initial state
• Successor function:
– [state → subset of states]
– an abstract representation of the possible actions
• Goal test
• Path cost
48. Search Problem
• State space
• Initial state
• Successor function
• Goal test:
– usually a condition
– sometimes the description of a state
• Path cost
49. Search Problem
• State space
• Initial state
• Successor function
• Goal test
• Path cost:
– [path → positive number]
– usually, path cost = sum of step costs
– e.g., number of moves of the empty tile
50. Assumptions in Basic Search
• The environment is static
• The environment is discretizable
• The environment is observable
• The actions are deterministic
51. University Questions
• Solve the following Crypt arithmetic problem:
FORTY
CROSS SEND BASE TEN EAT
ROADS MORE BALL TEN THAT
DANGER MONEY GAMES SIXTY APPLE
• You are given 2 jugs of cap 4l and 3l each. Neither of the jugs have
any measuring markers on them. There is a pump that can be used to
fill jugs with water. How can u get exactly 2l of water in 4l jug?
Formulate the problem in state space and draw complete diagram
• Consider jugs of volumes 3 and 7 units are available. Show the trace
to measure 2 and 5 units.
• Solve Wolf Goat Cabbage problem.