Symbiosis Skills and Open University
Symbiosis Skills and Open University
● model based,
● Learning agent.
Q3. Write the algorithms for implementing different kinds of agents for different
scenarios.
SYMBIOSIS SKILLS AND OPEN UNIVERSITY
B.Sc. in Data Science
Assignment sheet
Subject- Introduction to Artificial Intelligence
Skill : 1
Date: 23-06-2021
Q1. Optimise the given Code for automated vacuum cleaner implementing self-reflex
agent.
import random
class Environment(object):
def __init__(self):
# instantiate locations and conditions
# 0 indicates Clean and 1 indicates Dirty
self.locationCondition = {'A': '0', 'B': '0'}
class SimpleReflexVacuumAgent(Environment):
def __init__(self, Environment):
print (Environment.locationCondition)
# Instantiate performance measurement
Score = 0
# place vacuum at random location
vacuumLocation = random.randint(0, 1)
# if vacuum at A
if vacuumLocation == 0:
print ("Vacuum is randomly placed at Location A.")
# and Location A is Dirty.
if (Environment.locationCondition['A'] == 1):
print ("Location A is Dirty.")
# suck the dirt and mark it clean
Environment.locationCondition['A'] = 0;
Score += 1
print ("Location A has been Cleaned.")
# move to B
print ("Moving to Location B...")
Score -= 1
# if B is Dirty
if Environment.locationCondition['B'] == 1:
print ("Location B is Dirty.")
# suck and mark clean
Environment.locationCondition['B'] = 0;
Score += 1
print ("Location B has been Cleaned.")
else:
# move to B
Score -= 1
print ("Moving to Location B...")
# if B is Dirty
if (Environment.locationCondition['B'] == 1):
print ("Location B is Dirty.")
# suck and mark clean
Environment.locationCondition['B'] = 0;
Score += 1
print ("Location B has been Cleaned.")
elif vacuumLocation == 1:
print ("Vacuum randomly placed at Location B.")
# and B is Dirty
if Environment.locationCondition['B'] == 1:
print ("Location B is Dirty.")
# suck and mark clean
Environment.locationCondition['B'] = 0;
Score += 1
print ("Location B has been Cleaned.")
# move to A
Score -= 1
print ("Moving to Location A...")
# if A is Dirty
if (Environment.locationCondition['A'] == 1):
print ("Location A is Dirty.")
# suck and mark clean
Environment.locationCondition['A'] = 0;
Score += 1
print ("Location A has been Cleaned.")
else:
# move to A
print ("Moving to Location A...")
Score -= 1
# if A is Dirty
if (Environment.locationCondition['A'] == 1):
print ("Location A is Dirty.")
# suck and mark clean
Environment.locationCondition['A'] = 0;
Score += 1
print ("Location A has been Cleaned.")
# done cleaning
print( Environment.locationCondition)
print ("Performance Measurement: " + str(Score))
theEnvironment = Environment()
theVacuum = SimpleReflexVacuumAgent(theEnvironment)