AI Lab-1
AI 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:
self.environment = environment
self.location = random.choice(list(environment.keys()))
def sense(self):
return self.environment[self.location]
if action == "left":
self.location = "A"
self.location = "B"
self.environment[self.location] = 0
def simulate_environment():
def main():
environment = simulate_environment()
agent = VacuumCleanerAgent(environment)
dirt_status = agent.sense()
if dirt_status == 1:
print("Agent cleaning...")
agent.act("clean")
else:
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.
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.
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.