Ai Unit 2
Ai Unit 2
Search
MODULE-II
Adversarial Search : Games, Optimal Decisions in Games, The minimax algorithm, Alpha–Beta
Pruning, Defining Constraint Satisfaction Problems, Constraint Propagation, Backtracking Search
for CSPs, Knowledge-Based Agents, The wumpus world.
Adversarial Search
• Mostly the search strategies which are only associated with a single agent
that aims to find the solution which often expressed in the form of a
sequence of actions. But, there might be some situations where more than
one agent is searching for the solution in the same search space, and this
situation usually occurs in game playing.
• So, Searches in which two or more players with conflicting goals are
trying to explore the same search space for the solution, are called
adversarial searches, often known as Games.
• Perfect information:
A game with the perfect information is that in which agents can look into the
complete board. Agents have all the information about the game, and they can see each
other moves also. Examples are Chess, Checkers, Go, etc.
• Imperfect information:
If in a game agents do not have all information about the game and not aware
with what's going on, such type of games are called the game with imperfect information,
such as tic-tac-toe, Battleship, blind, Bridge, etc.
• Deterministic games:
Deterministic games are those games which follow a strict pattern and set of
rules for the games, and there is no randomness associated with them. Examples are chess,
Checkers, Go, tic-tac-toe, etc.
• Non-deterministic games:
Non-deterministic are those games which have various unpredictable events and
has a factor of chance or luck. This factor of chance or luck is introduced by either dice or
cards. These are random, and each action response is not fixed. Such games are also called
as stochastic games.
Example: Backgammon, Monopoly, Poker, etc.
Games
• Game Playing is an important domain of artificial intelligence. Games
don’t require much knowledge; the only knowledge we need to provide
is the rules, legal moves and the conditions of winning or losing
the game.
• Both players try to win the game. So, both of them try to make the
best move possible at each turn.
1.Rule-based systems
use a set of fixed rules to play the game.
2.Machine learning-based systems
use algorithms to learn from experience and make decisions based on
that experience.
Zero-Sum Game
• The Zero-sum game involved embedded thinking in which one agent or player is
trying to figure out:
• What to do.
• How to decide the move
• Needs to think about his opponent as well
• The opponent also thinks what to do
• Each of the players is trying to find out the response of his opponent to their
actions. This requires embedded thinking or backward reasoning to solve the
game problems in AI.
A game can be defined as a type of search in AI which can be formalized of the
following elements:
• Basic idea: choose move with highest minimax value= best achievable payoff against best play
• Algorithm:
1. Generate game tree completely
2. Determine utility of each terminal state
3. Propagate the utility values upward in the tree by applying MIN and MAX operators on the nodes in
the current level
4. At the root node use minimax decision to select the move with the max (of the min) utility value
• Steps 2 and 3 in the algorithm assume that the opponent will play perfectly.
ALGORITHM
also 3.
4 3 6 2 2 1 9 5
Constrain Satisfaction Problem
• Finding a solution that meets a set of constraints is the goal of constraint
satisfaction problems (CSPs).
• Finding values for a group of variables that fulfill a set of restrictions or rules is
the aim of constraint satisfaction problems.
• These constraints impose restrictions on the values or assignments of variables
in such a way that the variables must be assigned values from their respective
domains while meeting all specified conditions.
• For tasks including resource allocation, planning, scheduling, and decision-
making, CSPs are frequently employed in AI.
Significance of Constraint Satisfaction Problem in AI
There are mainly three basic components in the constraint satisfaction problem:
Variables: The things that need to be determined are variables. Variables in a CSP are the
objects that must have values assigned to them in order to satisfy a particular set of
constraints. Boolean, integer, and categorical variables are just a few examples of the
• Domains: The range of potential values that a
variable can have is represented by domains. Depending
on the issue, a domain may be finite or limitless. For
instance, in Sudoku, the set of numbers from 1 to 9 can
serve as the domain of a variable representing a problem
cell.
Examples
• Unary Constraints: Unary constraints limit the possible values of a single
variable without considering the values of other variables. It is the easiest
constraint to find, as it has only one parameter. Example: The expression X1
≠ 7 says that the variable X1 cannot have the value 7.
Algorithms in CSP
Constraint Satisfaction Problems (CSPs) are typically solved
using various algorithms designed to find a consistent
assignment of values to variables that satisfies all the
constraints. Some of the common algorithms used for solving
CSPs include:
• The Backtracking Algorithm: The backtracking algorithm is a
popular method for resolving CSPs. It looks for the search
space by picking a variable, setting a value for it, and
then recursively scanning through the other variables. In
the event of a conflict, it goes back and tries a different value
for the preceding variable. The backtracking algorithm’s
essential elements are:
• Variable Ordering: The order in which variables are chosen is known
as variable ordering.
• Value Ordering: The sequence in which values are assigned to
variables is known as value ordering.
• Constraint Propagation: Reducing the domain of variables based on
constraint compliance is known as constraint propagation.
• Forward Checking: The backtracking technique has been
improved using forward checking. It tracks the remaining
accurate values of the unassigned variables after each
assignment and reduces the domains of variables whose
values don’t match the assigned ones. As a result, the search
space is smaller, and constraint propagation is more
effectively accomplished.
• Constraint Propagation: Constraint propagation techniques
reduce the search space by removing values inconsistent
with current assignments through local consistency checks.
To do this, techniques like generalized arc consistency and
path consistency are applied
Domain Categories in CSP
• In Constraint Satisfaction Problems (CSPs), domain categories
refer to the set of possible values that can be assigned to each
variable in the problem. The specific categories or domains can
vary depending on the nature of the CSP, but here are some
common domain categories:
• Finite Domain: Variables in many CSPs have finite domains
that are made up of discrete values. Examples comprise:
• Binary Domains: Domains that only have two values (for binary
CSPs, this would be 0 and 1).
• Integer Domains: Domains made up of a limited number of integer
values, such as 1, 2, 3, and 4, are known as integer domains.
• Enumeration Domains: Domains containing a limited number of
distinct values, such as “red, green, and blue” in an issue involving
color assignment.
• Continuous Domains: Some CSPs contain variables
whose domains are continuous, i.e., they can accept
any real number falling within a given range. Examples
comprise:
• Real-valued Domains: Variables may accept any real
number that falls within a given range (for example, X [0, 1]).
• Interval Domains: Variables are limited to a specific range of
real values in the interval domain. e.g., X ∈ [−π, π])
Applications OF CSP -The map coloring problem.
• We are given the task of coloring each region red, green, or blue in such a way that the neighboring regions
must not have the same color.
• To formulate this as CSP, we define the variable to be the regions: WA, NT, Q, NSW, V, SA, and T.
• The domain of each variable is the set {red, green, blue}.
• The constraints require neighboring regions to have distinct colors: for example, the allowable combinations
for WA and NT are the pairs {(red,green),(red,blue),(green,red),(green,blue),(blue,red),(blue,green)}.
• (The constraint can also be represented as the inequality WA ≠ NT). There are many possible solutions, such as
{WA = red, NT = green, Q = red, NSW = green, V = red, SA = blue, T = red}.
• Map of Australia showing each of its states and territories
• With the map colouring algorithm, a graph G and the colours to be added to the graph
are taken as an input and a coloured graph with no two adjacent vertices having the
same colour is achieved
Algorithm
•Initiate all the vertices in the graph.
•Select the node with the highest degree to colour it with any colour.
•Choose the colour to be used on the graph with the help of the selection colour function so that no
adjacent vertex is having the same colour.
•Check if the colour can be added and if it does, add it to the solution set.
•Repeat the process from step 2 until the output set is ready.
The map-coloring problem represented as a constraint graph.
CSP can be viewed as a standard search problem as follows:
• Initial state : the empty assignment {},in which all variables are unassigned.
• Successor function: a value can be assigned to any unassigned variable, provided
that it does not conflict with previously assigned variables.
• Goal test: the current assignment is complete.
• Path cost: a constant cost(E.g.,1) for every step.
Solution:
WA: red
NT: green
SA: blue
Q: red
NSW: green
V: red
T: green
Map Coloring Examples
A Simple example
Variables
A,B,C
Domains
D = {1, 2, 3} for all A, B, C
Constraints
C1: A > B
C2: B ≠ C
C3: A ≠ C
One Solution [A Complete
Assignment]
Using backtracking Method: A simplest Algo. For CSP
A = 1 (Partial assignment), ok
A = 1, B = 1 [C1 is broken, backtrack on B]
A = 1, B = 2 [C1 is broken, backtrack on B]
A = 1, B = 3 [C1 is broken, backtrack on A]
A = 2 (Partial assignment), ok
A = 2, B = 1 (Partial assignment), ok
A = 2, B = 1, c = 1 [C2 is broken, backtrack on C]
A = 2, B = 1, c = 2 [C3 is broken, backtrack on C]
A = 2, B = 1, c = 3 [ALL CONSTRAINTS SATISFIED]'
One Solution (Complete assignment) = { A = 2, B = 1, C = 3}
Constraint Propagation
Constraint propagation is the process of using the constraints to reduce the
domain of possible values for each variable and to infer new constraints from the
existing ones.
For example, if you have a variable X that can take values from 1 to 10, and a
constraint that X must be even, then you can reduce the domain of X to 2, 4, 6, 8,
and 10. Similarly, if you have a constraint that X + Y = 12, and you know that X = 4,
then you can infer that Y = 8. By applying constraint propagation iteratively, you
can eliminate inconsistent values and simplify the problem.
One of the main advantages of constraint propagation is that it can reduce the
search space and prune branches that lead to dead ends. This can make the
problem easier to solve and improve the performance of your algorithm.
For example, if you use constraint propagation to assign colors to a map, you
might find that some regions have only one possible color left, and you can assign
it without further exploration.
Solving Constraint Satisfaction Problems in Artificial Intelligence:
2. Constraint Propagation:
• Constraint propagation is a powerful technique that enforces constraints throughout
the CSP solving process. It narrows down the domains of variables by iteratively
applying constraints. It's often used in conjunction with backtracking to improve
efficiency. The concept of constraint propagation can be illustrated as follows:
• Step 1: Start with an initial CSP problem in ai with variables, domains, and
constraints.
• Step 2: Apply constraints that have been specified in the problem to narrow down
the domains of variables. For instance, if two variables have a binary constraint that
one must be double the other, this constraint will eliminate many inconsistent
assignments.
• Step 3: After constraint propagation, some variables may have their domains reduced
to only a few possibilities, making it easier to find valid assignments.
• Step 4: If a variable's domain becomes empty during propagation, it indicates that
the current assignment is inconsistent, and backtracking is needed.
Illustration with a Simple CSP Example:
Let's consider a simplified Sudoku puzzle to illustrate the problem-solving process step by step:
Variables: 9x9 grid cells
Domains: Numbers from 1 to 9
Constraints: No number can repeat in the same row, column, or 3x3 subgrid.
Step 1: Start with an empty Sudoku grid.
Step 2: Apply the initial constraints for the given numbers, reducing the domains of variables
based on the puzzle's clues.
Step 3: Use constraint propagation to narrow down the domains further. For example, if a row
has two cells with domains {2, 5}, and the constraint specifies that these two cells cannot have
the same number, we can eliminate the possibility of 5 for one of them.
Step 4: Continue applying constraints and propagating until the domains of variables are either
empty or filled with single values. If they are all filled, you have a valid solution. If any variable's
domain is empty, you backtrack to the previous step and try an alternative assignment.
This simple example demonstrates how backtracking and constraint propagation work together
to efficiently find a solution to a CSP. The combination of systematic search and constraint
enforcement allows for solving complex problems in various domains.
The process of constraint propagation typically involves three main
steps:
• Propagation: During this step, the constraints propagate information
throughout the problem domain. This propagation usually involves
iteratively applying inference rules based on the constraints to
reduce the domains of variables.
• Detection: After propagation, the algorithm checks for any
inconsistencies or conflicts that may have arisen due to the constraint
propagation. If such conflicts are detected, the current assignment is
not feasible.
• Resolution: If conflicts are detected, the algorithm must backtrack
and revise the previous decisions made. This could involve undoing
variable assignments or making choices to resolve the conflicts.
Techniques of Constraint Propagation:
• Arc Consistency: Arc consistency is a basic form of constraint propagation
where each variable is made consistent with its neighboring variables based
on the constraints. This involves checking for consistency between each pair
of variables connected by a constraint.
• Path Consistency: Path consistency extends arc consistency by considering
longer paths of variables and constraints. It ensures that the constraints are
consistent along any path of variables in the CSP.
• Forward Checking: Forward checking is a more efficient form of constraint
propagation that is used during the search process. After each variable
assignment, forward checking updates the domains of neighboring variables,
eliminating any values that are inconsistent with the current assignment.
• Constraint Propagation Algorithms: There are specific algorithms designed
for constraint propagation, such as AC-3 (Arc Consistency 3) and AC-4, which
efficiently enforce arc consistency in a CSP.
Arc Consistency Arc consistency between B and C: We
Consider a CSP with three variables: A, B, and C. check each value in the domain of B
Each variable has a domain of {1, 2, 3}. against each value in the domain of C to
Additionally, we have the following constraints: ensure no conflicts with the constraint
A≠B B≠C B ≠ C.
Step 1: Initial Setup For B = 1, we check if there is any
• Initially, each variable has a domain of {1, 2, 3}. value in C's domain that satisfies C ≠
Step 2: Arc Consistency Enforcement 1. Since C's domain is {1, 2, 3}, and C
• Arc consistency between A and B: We check each ≠ 1 holds for all values in C's
value in the domain of A against each value in the domain, B = 1 remains consistent.
domain of B to ensure no conflicts with the
constraint A ≠ B. Similarly, we check for B = 2 and B =
• For A = 1, we check if there is any value in B's 3.
domain that satisfies B ≠ 1. Since B's domain is After this step, no values are eliminated
{1, 2, 3}, and B ≠ 1 holds for all values in B's from B's domain, and the arc
domain, A = 1 remains consistent. consistency between B and C is
• Similarly, we check for A = 2 and A = 3. maintained.
After this step, no values are eliminated from A's
domain, and the arc consistency between A and B is
Path Consistency
Let's consider a slightly more complex CSP with four variables: A, B, C, and D. Each variable has a domain of
{1, 2, 3}.
The constraints for this CSP are as follows:
• A≠B
• B≠C
• C≠D
We'll demonstrate the process of enforcing path consistency step by step:
Step 1: Initial Setup
• Initially, each variable has a domain of {1, 2, 3}.
Step 2: Path Consistency Enforcement
• Path consistency between A and B: Since there's a direct constraint A ≠ B, we enforce arc consistency
between A and B. As we've seen in the previous example, this doesn't eliminate any values from A or B's
domain.
• Path consistency between B and C: Similarly, since there's a direct constraint B ≠ C, we enforce arc
consistency between B and C. Again, no values are eliminated from B or C's domain.
• Path consistency between C and D: There's a direct constraint C ≠ D. We enforce arc consistency between
C and D. As before, no values are eliminated from C or D's domain.
AC-3:
Consider a CSP with three variables: A, B, and C. Each variable has a domain of
{1, 2, 3}.
Additionally, we have the following constraints:
A≠B
B≠C
Step 1: Initial Setup
• Initialize a queue with all the arcs (binary constraints) in the CSP.
Initial domains:
• Domain(A) = {1, 2, 3}
• Domain(B) = {1, 2, 3}
• Domain(C) = {1, 2, 3}
• Initial queue: {(A, B), (B, C)}
Step 2: AC-3 Algorithm
The AC-3 algorithm processes each arc in the queue, checking and possibly reducing the
domains of variables based on arc consistency.
• Processing (A, B):
• For each value a in Domain(A), check if there exists any value b in Domain(B) such that a ≠ b holds.
• If there's no value b in Domain(B) satisfying a ≠ b, remove a from Domain(A).
• Since A ≠ B, all values in Domain(A) remain consistent.
• Processing (B, C):
• For each value b in Domain(B), check if there exists any value c in Domain(C) such that b ≠ c holds.
• If there's no value c in Domain(C) satisfying b ≠ c, remove b from Domain(B).
• Since B ≠ C, all values in Domain(B) remain consistent.
Step 3: Result
After processing all arcs, the domains are:
• Domain(A) = {1, 2, 3}
• Domain(B) = {1, 2, 3}
• Domain(C) = {1, 2, 3}
No values were removed from any domain, indicating that the CSP remains consistent with
the given constraints.
Forward CheckingStep 2: Forward Checking Algorithm
Consider a CSP with three
variables: A, B, and C. Each variable
Assignment: Suppose we assign a value
has a domain of {1, 2, 3}. to variable A, let's say A = 1.
Additionally, we have the following Forward Checking:
constraints: Since A is assigned the value 1, we check the
constraints involving A.
• A≠B For A ≠ B, we remove 1 from the domain of B.
• B≠C For B ≠ C, no action is needed since B is not assigned
yet.
Step 1: Initial Setup Updated domains:
Initialize the domains of variables: Domain(A) = {1}
• Domain(A) = {1, 2, 3} Domain(B) = {2, 3}
Domain(C) = {1, 2, 3}
• Domain(B) = {1, 2, 3}
• Domain(C) = {1, 2, 3}
Assignment: Now, let's assign a value to variable B, let's say B = 2.
• Forward Checking:
• Since B is assigned the value 2, we check the constraints involving B.
• For A ≠ B, no action is needed since A is already assigned.
• For B ≠ C, we remove 2 from the domain of C.
• Updated domains:
• Domain(A) = {1}
• Domain(B) = {2}
• Domain(C) = {1, 3}
Assignment: Finally, let's assign a value to variable C, let's say C = 3.
• Forward Checking:
• Since C is assigned the value 3, we check the constraints involving C.
• For A ≠ B, no action is needed since neither A nor B are assigned.
• For B ≠ C, no action is needed since B is already assigned.
• Updated domains remain unchanged:
• Domain(A) = {1}
• Domain(B) = {2}
• Domain(C) = {3}
Cryptarithmetic Problem
Cryptarithmetic Problem is a type of constraint satisfaction problem where
the game is about digits and its unique replacement either with alphabets
or other symbols. In cryptarithmetic problem, the digits (0-9) get
substituted by some possible alphabets or symbols. The task in
cryptarithmetic problem is to substitute each digit with an alphabet
to get the result arithmetically correct.
The rules or constraints on a cryptarithmetic problem are as
follows:
•There should be a unique digit to be replaced with a unique alphabet.
•The result should satisfy the predefined arithmetic rules, i.e., 2+2 =4,
nothing else.
•Digits should be from 0-9 only.
•There should be only one carry forward, while performing the addition
operation on a problem.
•The problem can be solved from both sides, i.e., lefthand side (L.H.S),
or righthand side (R.H.S)
Let’s understand the cryptarithmetic problem as well its constraints
better with the help of an example:
1) here result is 3 digit no so leftmost digit must be carry now if we add
any 2 no between 0 to 9 we can get max 18 so O=1.
2) so T becomes 2 and we need to add 2+ G=U+10. The G value must
produce carry so we can take G=8 hence U=0.
3)We cant take G=9 bcoz 2+9=11 it means U=1 which is not possible.
T O letter digit
+G O T 2 2 1
------------- O 1 8 1
OU T G 8 -----------------------
U 0 1 0 2
S E ND • S+M,if m=1,S+M>=10,S=9
+MORE • E+O=N but O=zero if C2=0 then we can take any
___________ • value from 0 to 9
MONEY
• for E but in that case Both E and N will be same
C3(1) C2(1) C1(1) • which is not possible.
S(9) E (5) N(6) D(7) • Hence our assumption of C2=0 is wrong.
+ M(1) O(0) R (8) E(5) • So now C2=1
-------------------------------------
• Let E=5 so N=C2+E+O=1+5+0=6.
1 0 6 5 2
• Let R=9 so N+R=6+9=15 as E is already 5 so 15
means 5 and 1 carry.
• But already we assigned S=9 so we cant assign R=9.
TWO + TWO = FOUR • So we can take C1=1 and R=8 so that 1+6+8=15.
GERALD + DONALD = ROBERT
CROSS + ROADS = DANGER
• Now D+E=Y and it should produce carry C1=1
POTATO + TOMATO = PUMPKIN • which is possible only when D>=5.
(P-1,O-6,T-8,A-4,M-3,U-0,K-9,I-7,N-2)
• So D+5=Y and D can be between 5 to 9.
Wumpus world:
• The Wumpus world is a simple world example to illustrate the worth of a knowledge-based agent and to represent
knowledge representation. It was inspired by a video game Hunt the Wumpus by Gregory Yob in 1973.
• The Wumpus world is a cave which has 4/4 rooms connected with passageways. So there are total 16 rooms which are
connected with each other. We have a knowledge-based agent who will go forward in this world.
• The cave has a room with a beast which is called Wumpus, who eats anyone who enters the room. The Wumpus can be
• In the Wumpus world, there are some Pits rooms which are bottomless, and if agent falls in Pits, then he will be stuck
there forever. The exciting thing with this cave is that in one room there is a possibility of finding a heap of gold.
• So the agent goal is to find the gold and climb out the cave without fallen into Pits or eaten by Wumpus. The agent
will get a reward if he comes out with gold, and he will get a penalty if eaten by Wumpus or falls in the pit.
Components of Wumpus WORLD:
1. The rooms adjacent to the Wumpus room are smelly, so that it would have some stench.
2. The room adjacent to PITs has a breeze, so if the agent reaches near to PIT, then he will perceive the breeze.
3. There will be glitter in the room if and only if the room has gold.
4. The Wumpus can be killed by the agent if the agent is facing to it, and Wumpus will emit a horrible scream which can be
heard anywhere in the cave.
PEAS description of Wumpus world:
Performance measure:
• +1000 reward points if the agent comes out of the cave with the gold.
• -1000 points penalty for being eaten by the Wumpus or falling into the pit.
• -1 for each action, and -10 for using an arrow.
• The game ends if either agent dies or came out of the cave.
Environment:
• A 4*4 grid of rooms.
• The agent initially in room square [1, 1], facing toward the right.
• Location of Wumpus and gold are chosen randomly except the first square [1,1].
• Each square of the cave can be a pit with probability 0.2 except the first square.
Actuators:
• Left turn,
• Right turn
• Move forward
• Grab
• Release
• Shoot.
Sensors:
• The agent will perceive the stench if he is in the room adjacent to the Wumpus. (Not diagonally).
• The agent will perceive breeze if he is in the room directly adjacent to the Pit.
• The agent will perceive the glitter in the room where the gold is present.
• The agent will perceive the bump if he walks into a wall.
• When the Wumpus is shot, it emits a horrible scream which can be perceived anywhere in the cave.
• These percepts can be represented as five element list, in which we will have different indicators for each
sensor.
• Example if agent perceives stench, breeze, but no glitter, no bump, and no scream then it can be represented
as:
[Stench, Breeze, None, None, None].
Wumpus World
•
INTRODUCTION
•
Wumpus, Strenchy, Agent, Pit, Breeze, Gold, Arrow
Environment
Agent enters in [1,1]
16 rooms
Empty Rooms
Room with Wumpus: A deadly beast who kills anyone entering his
room.
Stenchy rooms
Breezy rooms
Room with gold
Arrow
Cave of 4×4
Pits: Bottomless pits that will
trap you forever.
Agents Sensors:
Odor sensor -Stench next to Wumpus
Odor sensor -Breeze next to pit
Camera-Glitter in square with gold
Bump when agent moves
into a wall
Audio Sensor-Scream from wumpus when killed
Agents actions
Agent can move forward, turn left or turn right
Shoot, one shot from arrow
Grab Gold
Wumpus world
Awards and punishments
+1000 for picking up gold
-1000 got falling into pit
-1 for each move
-10 for using arrow
Performance measure
- +1000 for picking up gold
-1000 got falling into pit
-1 for each move
-10 for using arrow
• [2,1] = breeze
• indicates that there is a pit in [2,2] or [3,1],
• return to [1,1] to try next safe cell
Exploring the Wumpus World
• Exploring the Wumpus World
• [1,2] Stench in cell which means that wumpus is in [1,3] or [2,2]
• YET … not in [1,1]
• YET … not in [2,2] or stench would have been detected in [2,1]
• (this is relatively sophisticated reasoning!)
Exploring the Wumpus World
• THUS … wumpus is in [1,3]
• THUS [2,2] is safe because of lack of breeze in [1,2]
• THUS pit in [3,1] (again a clever inference)
• move to next safe cell [2,2]
Exploring the Wumpus World
• [2,2] move to [2,3]
• [2,3] detect glitter , stench, breeze
• THUS pick up gold
• THUS pit in [3,3] or [2,4]
Knowledge-Based Agent in Artificial intelligence
• An intelligent agent needs knowledge about the real The learning element of KBA regularly updates the
world for taking decisions and reasoning to act
efficiently. KB by learning new knowledge .
• Knowledge-based agents are those agents who have
the capability of maintaining an internal state of
knowledge, reason over that knowledge, update
their knowledge after observations and take
actions. These agents can represent the world
with some formal representation and act
intelligently.
• Knowledge-based agents are composed of two main
parts:
• Knowledge-base and
• Inference system.
• The is showing how knowledge-based agent (KBA)
take input from the environment by perceiving the
environment. The input is taken by the inference
engine of the agent and which also communicate
with KB to decide as per the knowledge store in KB.
Knowledge base: Knowledge-base is a central component of a knowledge-based agent, it is also
known as KB. It is a collection of sentences. These sentences are expressed in a language which is
called a knowledge representation language. The Knowledge-base of KBA stores fact about the world.
Inference system: Inference means deriving new sentences from old. Inference system allows us to
add a new sentence to the knowledge base. A sentence is a proposition ( In AI, a proposition refers to a
declarative sentence that is either true or false.)about the world. Inference system applies logical rules to
the KB to deduce new information. Inference system generates new facts so that an agent can update
the KB. An inference system works mainly in two rules which are given as: Forward chaining,
Backward chaining
Three operations which are performed by KBA in order to show the intelligent behavior:
1. TELL: This operation tells the knowledge base what it perceives from the environment.
2. ASK: This operation asks the knowledge base what action it should perform.
3. Perform: It performs the selected action.
And the structure of a generic knowledge-based agents program:
function KB-AGENT(percept):
persistent: KB, a knowledge base
t, a counter, initially 0, indicating time
TELL(KB, MAKE-PERCEPT-SENTENCE(percept, t))
Action = ASK(KB, MAKE-ACTION-QUERY(t))
TELL(KB, MAKE-ACTION-SENTENCE(action, t))
t=t+1
return action
• The knowledge-based agent takes percept as input and returns an action as output.
The agent maintains the knowledge base, KB, and it initially has some background
knowledge of the real world.
• It also has a counter to indicate the time for the whole process, and this counter is
initialized with zero.
Each time when the function is called, it performs its three operations:
• Firstly it TELLs the KB what it perceives.
• Secondly, it asks KB what action it should take
• Third agent program TELLS the KB that which action was chosen.
The MAKE-PERCEPT-SENTENCE generates a sentence as setting that the agent
perceived the given percept at the given time.
The MAKE-ACTION-QUERY generates a sentence to ask which action should be
done at the current time.
MAKE-ACTION-SENTENCE generates a sentence which asserts that the chosen
action was executed.
levels of knowledge-based agent:
1. Knowledge level: Knowledge level is the first level of knowledge-based agent, and in this level, we
need to specify what the agent knows, and what the agent goals are. With these specifications, we can
fix its behavior. For example, suppose an automated taxi agent needs to go from a station A to station
B, and he knows the way from A to B, so this comes at the knowledge level.
2. Logical level: At this level, we understand that how the knowledge representation of knowledge is
stored. At this level, sentences are encoded into different logics. At the logical level, an encoding of
knowledge into logical sentences occurs. At the logical level we can expect to the automated taxi agent
to reach to the destination B.
3. Implementation level: This is the physical representation of logic and knowledge. At the
implementation level agent perform actions as per logical and knowledge level. At this level, an
automated taxi agent actually implement his knowledge and logic so that he can reach to the
destination.
Approaches to designing a knowledge-based agent:
Declarative approach: We can create a knowledge-based agent by initializing with an empty
knowledge base and telling the agent all the sentences with which we want to start with. This approach
is called Declarative approach.
Procedural approach: In the procedural approach, we directly encode desired behavior as a program
code. Which means we just need to write a program that already encodes the desired behavior or agent.
Procedural Knowledge vs Declarative Knowledge