0% found this document useful (0 votes)
21 views4 pages

AI Lab-1

The document outlines a lab project to design an intelligent vacuum-cleaner agent using AI techniques to clean two rooms, A and B. It details the setup of the environment, agent characteristics, decision-making processes, and optional learning mechanisms. Additionally, it provides Python code for simulating the agent's actions and interactions with the environment over multiple steps.

Uploaded by

Batool 2002
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)
21 views4 pages

AI Lab-1

The document outlines a lab project to design an intelligent vacuum-cleaner agent using AI techniques to clean two rooms, A and B. It details the setup of the environment, agent characteristics, decision-making processes, and optional learning mechanisms. Additionally, it provides Python code for simulating the agent's actions and interactions with the environment over multiple steps.

Uploaded by

Batool 2002
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/ 4

Artificial Intelligence Vacuum-Cleaner Agent in Two Rooms (A And B) IIEE

7th Semester Institute of Industrial Electronics Engineering LAB 1

OBJECTIVE:
The objective of this lab is to design an intelligent vacuum-cleaner agent using artificial
intelligence techniques. The agent will be responsible for cleaning two rooms, labeled
as Room A and Room B. The goal is to implement a rational agent that can effectively
navigate, perceive its environment, and make decisions to keep both rooms clean.
LAB DESCRIPTION:

1. Environment Setup:
Define a simulation environment with two rooms (Room A and Room B).
Initialize the rooms with dirt in random locations.
2. Agent Characteristics:
Design a rational vacuum-cleaner agent that can:
Perceive the current state of the environment.
Decide the next action based on the perceived state.
Perform actions to clean the rooms.
3. Sensing and Acting:
Implement sensing functions for the agent to detect the presence of dirt in a room.
Develop actions for the agent to move left or right, clean the current location, or stay idle.
4. Decision-Making:
Use AI concepts such as simple rule-based systems or state-space search to make decisions.
Define rules for the agent to determine its actions based on the current state.
5. Learning (Optional):
Implement a learning mechanism for the agent to adapt its behavior over time.
Utilize reinforcement learning or other learning algorithms to improve the cleaning efficiency.
6. Visualization:
Create a graphical representation of the environment and agent's actions.
Display the rooms, the current location of the agent, and the cleanliness status.
PYTHON CODE:
import random

class VacuumCleanerAgent:

def __init__(self, environment):

self.environment = environment

self.location = random.choice(list(environment.keys()))

def sense(self):

return self.environment[self.location]

def act(self, action):

if action == "left":

self.location = "A"

elif action == "right":

self.location = "B"

elif action == "clean":

self.environment[self.location] = 0

def simulate_environment():

return {"A": random.randint(0, 1), "B": random.randint(0, 1)}

def main():

environment = simulate_environment()

agent = VacuumCleanerAgent(environment)

for _ in range(10): # Simulate 10 steps

print(f"Current State: {environment}")

print(f"Agent Location: {agent.location}")

dirt_status = agent.sense()

if dirt_status == 1:

print("Agent cleaning...")

agent.act("clean")
else:

action = random.choice(["left", "right"])

print(f"Agent moving {action}...")

agent.act(action)

print("---------")

if __name__ == "__main__":

main()
Step 1: Import Necessary Modules
python
import random
We import the `random` module to generate random values, which will be useful for initializing the
environment and making random decisions.

Step 2: Define the Vacuum Cleaner Agent Class


python
class VacuumCleanerAgent:
def __init__(self, environment):
self.environment = environment
self.location = random.choice(list(environment.keys()))
Here, we define a class `VacuumCleanerAgent`. The `__init__` method initializes the agent with a reference to
the environment and places the agent in a random location within the environment.

Step 3: Define Sensing and Acting Methods


python
def sense(self):
return self.environment[self.location]
def act(self, action):
if action == "left":
self.location = "A"
elif action == "right":
self.location = "B"
elif action == "clean":
self.environment[self.location] = 0

We define `sense` to get the dirt status of the current location and `act` to perform actions based on the input
argument. The agent can move left, right, or clean the current location.
Step 4: Simulate the Environment
python
def simulate_environment():
return {"A": random.randint(0, 1), "B": random.randint(0, 1)}
The `simulate_environment` function initializes the environment with dirt randomly placed in rooms A and B.

Step 5: Main Simulation


python
def main():
environment = simulate_environment()
agent = VacuumCleanerAgent(environment)
for _ in range(10): # Simulate 10 steps
print(f"Current State: {environment}")
print(f"Agent Location: {agent.location}")
dirt_status = agent.sense()

if dirt_status == 1:
print("Agent cleaning...")
agent.act("clean")
else:
action = random.choice(["left", "right"])
print(f"Agent moving {action}...")
agent.act(action)
print("---------")
if __name__ == "__main__":
main()

In the `main` function, we simulate the environment and the agent's actions for 10 steps. The agent senses the
dirt status, makes decisions based on the dirt status, and performs actions accordingly. The current state of the
environment and the agent's location are printed at each step.

You might also like