Professional Documents
Culture Documents
Artificial Intelligence: Bahria University, Islamabad
Artificial Intelligence: Bahria University, Islamabad
Lab Journal 8
SAMMA KHALIL
01-134191-099
BSCS-6B
Objectives:
Tools Used:
Spyder IDE.
Submission Date:14/4/2020
Apply forward checking to solve the problem of hotel room assignment. Map of rooms
is given below. Two adjacent rooms should not be allocated to persons of same
country. Persons x,y and z belongs to country P. Persons a and b belongs to country Q,
person s belong to country R.
A D F
B C
Procedure/Program:
Rooms = [
[0,1,0,0,0,0] ,
[1,0,1,0,0,0] ,
[0,1,0,0,0,0] ,
[0,0,0,0,0,1] ,
[0,0,0,0,0,0] ,
[0,0,0,1,0,0]
]
def Select_Person():
for i in range(len(Countries)):
for j in range(len(Countries[i])):
return Countries[i][j]
def Select_Other_Country_Person(p):
for i in range(len(Countries)):
if p in Countries[i]:
if len(Countries[i-1]) !=0 :
return Countries[i-1][0]
def Remove_Person(p):
for i in range(len(Countries)):
if p in Countries[i]:
Countries[i].remove(p)
def Check_Neighbours(k,person):
for i in range (0,6):
if (Rooms[k][i]==1):
neighbour = Solution[i]
for i in range(0,len(Persons)):
if( person in Persons[i] ) and (neighbour in Persons[i]):
return False
return True
def Assign_Rooms(k):
p = Select_Person()
if(Check_Neighbours(k,p) == True):
Solution[k]=p
Remove_Person(p)
if(k+1<6):
Assign_Rooms(k+1)
else:
p = Select_Other_Country_Person(p)
if(Check_Neighbours(k,p) == True):
Solution[k]=p
Remove_Person(p)
if(k+1<6):
Assign_Rooms(k+1)
Assign_Rooms(0)
print('Person : ' , Solution[0] , " in Room A")
print('Person : ' , Solution[1] , " in Room B")
print('Person : ' , Solution[2] , " in Room C")
print('Person : ' , Solution[3] , " in Room D")
print('Person : ' , Solution[4] , " in Room E")
print('Person : ' , Solution[5] , " in Room F")
Result/Output:
Analysis/Conclusion:
In this task we learn Allocate the Rooms to Persons with the help of Forward Checking
Algorithm.
Task # 2:
Procedure/Program:
from random import randint
Stalls=['food','cosmetics','garments','toys','shoes','jewellery']
A=list()
B=list()
C=list()
i=randint(0,5)
j=randint(0,5)
B.append(Stalls[i])
B.append(Stalls[j])
for k in range(0,len(Stalls)):
if(k!=i and k != j):
A.append(Stalls[k])
C.append(Stalls[k])
print("A : ",A)
print("B : ",B)
print("C : ",C)
Result/Output:
Analysis/Conclusion:
In this task we learn Allocate the stalls with Forward Checking Algorithm.