0% found this document useful (0 votes)
69 views3 pages

Ai Week-2

The document implements and compares three agent programs - a table-driven agent, simple reflex agent, and model-based reflex agent - for a vacuum cleaner world. The programs take in percepts of the agent's location and the cleanliness status and return actions. The model-based agent also tracks a history of past percepts and actions. The programs are run on a sample percept sequence and their actions are printed and compared.

Uploaded by

sadiqali4244
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views3 pages

Ai Week-2

The document implements and compares three agent programs - a table-driven agent, simple reflex agent, and model-based reflex agent - for a vacuum cleaner world. The programs take in percepts of the agent's location and the cleanliness status and return actions. The model-based agent also tracks a history of past percepts and actions. The programs are run on a sample percept sequence and their actions are printed and compared.

Uploaded by

sadiqali4244
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

EXERCISE - 02

Problem Statement:

Implement agent programs for Simple reflex agents and Model-based reflex agents
using the agent function of vacuum-cleaner world.

Aim: To Implement agent programs for Simple reflex agents and Model-based reflex
agents using the agent function of vacuum-cleaner world.

Program code:

# Table-driven agent program


def table_driven_agent(percept):
location, status = percept
table = {
('A', 'Dirty'): 'Clean_A',
('A', 'Clean'): 'Move_B',
('B', 'Dirty'): 'Clean_B',
('B', 'Clean'): 'Move_A',
}

action = table.get((location, status), 'NoOp')

return action

# Simple reflex agent program


def simple_reflex_agent(percept):
location, status = percept
action = 'NoOp'

if status == 'Dirty':
action = 'Clean'
else:
action = 'Move'

return action

# Model-based reflex agent program


def model_based_reflex_agent(percept, percept_sequence):
location, status = percept
action = 'NoOp'

if status == 'Dirty':
action = 'Clean'
else:
action = 'Move'
percept_sequence.append((location, status, action))

return action, percept_sequence

# Example percept sequence


percept_sequence_model_based = []

# Example percept sequence


percept_sequence = [('A', 'Dirty'), ('A', 'Clean'), ('B', 'Dirty'), ('B', 'Clean')]

# Initialize the current square


current_square = 'A'

# Run agents for each percept


for percept in percept_sequence:
# Table-driven agent
table_driven_action = table_driven_agent(percept)
print(f'Table-driven agent: {table_driven_action}')

# Simple reflex agent


simple_reflex_action = simple_reflex_agent(percept)
print(f'Simple reflex agent: {simple_reflex_action}')

# Model-based reflex agent


model_based_action, percept_sequence_model_based =
model_based_reflex_agent(percept, percept_sequence_model_based)
print(f'Model-based reflex agent: {model_based_action}')

# Display percept sequence for Model-based reflex agent


print(f'Percept sequence for Model-based agent:
{percept_sequence_model_based}')

# Update current square for the next iteration


current_square = 'B' if current_square == 'A' else 'A'

print('\n')

Output :
Table-driven agent: Clean_A
Simple reflex agent: Clean
Model-based reflex agent: Clean
Percept sequence for Model-based agent: [('A', 'Dirty', 'Clean')]

Table-driven agent: Move_B


Simple reflex agent: Move
Model-based reflex agent: Move
Percept sequence for Model-based agent: [('A', 'Dirty', 'Clean'),
('A', 'Clean', 'Move')]
Table-driven agent: Clean_B
Simple reflex agent: Clean
Model-based reflex agent: Clean
Percept sequence for Model-based agent: [('A', 'Dirty', 'Clean'),
('A', 'Clean', 'Move'), ('B', 'Dirty', 'Clean')]

Table-driven agent: Move_A


Simple reflex agent: Move
Model-based reflex agent: Move
Percept sequence for Model-based agent: [('A', 'Dirty', 'Clean'),
('A', 'Clean', 'Move'), ('B', 'Dirty', 'Clean'), ('B', 'Clean',
'Move')]

You might also like