purpose is to adapt the Iterative Deepening Search (IDS) method learnt in class to a realistic problem that is of relevance to Industry.
9/29/21, 12:33 PM project 1.ipynb - Colaboratory
https://colab.research.google.com/drive/1wnJNx5lok6JBVBotnaz3Kt8-NqePt4NW?authuser=1#scrollTo=82bde6dc&uniqifier=23&printMode=true 1/5
1. Sneha Yerramsetti 2. Charitha Rajala
Fundamentals of Arti�cial Intelligence - Project 1
import random as rd from operator import add
#warehouse grids 6*6
w = [ ['P', '', 'D', '', '', ''], ['', 'A', '', '', 'G', ''], ['E', '', 'B', '', 'I', ''], ['', 'C', '', '', '', ''], ['', '', 'F', '', '', 'H'], ['', '', '', 'J', '', ''] ] items = ['A', 'B','C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'] #items present in the
# Modified warehouse grid layout 2 w1 = [
['D', '', 'B', '', 'M', ''], ['E', '', 'F', '', 'K', ''], ['C', '', 'H', '', '', 'O'], ['G', '', 'J', '', '', 'Q'], ['I', '', '', '', 'N', ''] ] items1 = ['A', 'P','D', 'B', 'M', 'E', 'F', 'K', 'C', 'H','O','G','J','Q','I', 'N']
['P', '', 'A', '', 'P', ''],
# Original warehouse grid layout 1
# gird layout1
#items present in the gird layot 2
#the possible positions for the robot to move are up,down,left and right
positionsavailable = [ list(map(add, [0,-1],current_position )), #up list(map(add, [0,1], current_position)), #left list(map(add, [-1,0],current_position)), #down list(map(add, [1,0], current_position)) #right ]
def route(current_position,previous_position, itemsordered,w):
9/29/21, 12:33 PM project 1.ipynb - Colaboratory
https://colab.research.google.com/drive/1wnJNx5lok6JBVBotnaz3Kt8-NqePt4NW?authuser=1#scrollTo=82bde6dc&uniqifier=23&printMode=true 2/5
p = list(filter(lambda position:
0 <= position[1] < len(w[0]) , positionsavailable))
next_position = movements(p, itemsordered, w) if(len(next_position) == 0): next_position = p return next_position[rd.randint(0,len(next_position)-1)]
0 <= position[0] < len(w) and
#the random movements of to robot in order to get the customer ordered items
movements = [] rn = rd.randint(1,10); #random number from the items A-J are choosen for position in p : if rn in range(1,11) and w[position[0]][position[1]] in ordered_items: movements.append(position) elif rn == 9: movements.append(position) else: break
def movements(p,ordered_items ,w ): #p is position of the robot
return movements
def agent(w,avail_items): #available items in the grid
sp_score = 0 #shortest path score lp_score = 0 #longest path score total = 0
for order in range(0,norders): # no of orders nitems = rd.randint(1, len(avail_items)) #random number is generated ordereditems = rd.sample(avail_items, nitems) #the items ordered or listed by the ran rem_items = list(ordereditems) #remaining items left out from the listed items current_position = [0,0] #starting position of the robot is P score = 0 path = [(current_position[0], current_position[1])] while len(rem_items) > 0: #if the items listed are still need to be picked by the rob previous_position = current_position #the last position of the robot will be the current_position = route(current_position,previous_position, rem_items, w)
shortest_path = [] s_ordereditems = [] longest_path = [] l_ordereditems = []
scoredtotal = 0 norders = 1000
9/29/21, 12:33 PM project 1.ipynb - Colaboratory
https://colab.research.google.com/drive/1wnJNx5lok6JBVBotnaz3Kt8-NqePt4NW?authuser=1#scrollTo=82bde6dc&uniqifier=23&printMode=true 3/5
path.append((current_position[0], current_position[1])) if w[current_position[0]][current_position[1]] in rem_items: score += 3 #reached to the required grid position(item needed) rem_items.remove(w[current_position[0]][current_position[1]]); else: score -=-1 #if the robot goes to an unwanted grid position just to travel if(len(shortest_path) == 0 or len(shortest_path) > len(path)): shortestpath = path sp_score = score s_ordereditems = ordereditems if(len(longest_path) < len(path)): longest_path = path lp_score = score l_ordereditems = ordereditems
scoredtotal += score avg_items = total/ norders avg_score = scoredtotal / norders
total += nitems
#Shortest path print('The scores for 1000 episodes are') print('Customer Ordered Items are: \n' + str(s_ordereditems)) print('Shortest Path: \n' + str(shortestpath)) print('Score of the shortest path:' + str(sp_score))
#longest path print('Customer Ordered Items: ' + str(l_ordereditems)) print('Longest Path:\n' + str(longest_path)) print('Score of the logest path: ' + str(lp_score)) print('\n')
print('Average Score : ' + str(avg_score))
print('\n')
print('Average(no. of items ordered): ' + str(avg_items))
print('brute force : ' + str(brute_force(avg_items)))
def brute_force(nitems): return -35+4*nitems
The scores for 1000 episodes are Customer Ordered Items are: ['I', 'A', 'D', 'B', 'J', 'E', 'C'] Shortest Path: [(0, 0), (1, 0), (2, 0), (2, 1), (1, 1), (2, 1), (1, 1), (0, 1), (0, 0), (1, 0), (2, 0), Score of the shortest path:162
#output for the grid layout 1 agent(w,items)
9/29/21, 12:33 PM project 1.ipynb - Colaboratory
https://colab.research.google.com/drive/1wnJNx5lok6JBVBotnaz3Kt8-NqePt4NW?authuser=1#scrollTo=82bde6dc&uniqifier=23&printMode=true 4/5
Customer Ordered Items: ['D', 'I', 'G', 'F', 'H', 'A', 'B', 'C', 'E'] Longest Path: [(0, 0), (0, 1), (0, 0), (1, 0), (1, 1), (0, 1), (0, 0), (0, 1), (1, 1), (2, 1), (2, 0), Score of the logest path: 639
Average(no. of items ordered): 5.484 Average Score : 126.74 brute force : -13.064
The scores for 1000 episodes are Customer Ordered Items are: ['P', 'N'] Shortest Path: [(0, 0), (0, 1), (0, 0), (0, 1), (1, 1), (0, 1), (0, 2), (0, 1), (1, 1), (2, 1), (1, 1), Score of the shortest path:89
Customer Ordered Items: ['Q', 'F', 'K', 'N', 'J', 'M', 'O', 'G', 'B', 'H', 'C', 'P', 'D Longest Path: [(0, 0), (0, 1), (0, 0), (0, 1), (0, 2), (1, 2), (1, 1), (1, 0), (1, 1), (1, 0), (0, 0), Score of the logest path: 737
Average(no. of items ordered): 8.384 Average Score : 169.465 brute force : -1.4639999999999986
#output for the grid layout 2 agent(w1,items1)
9/29/21, 12:33 PM project 1.ipynb - Colaboratory
https://colab.research.google.com/drive/1wnJNx5lok6JBVBotnaz3Kt8-NqePt4NW?authuser=1#scrollTo=82bde6dc&uniqifier=23&printMode=true 5/5
Could not connect to the reCAPTCHA service. Please check your internet connection and reload to get a reCAPTCHA challenge.
1s completed at 12:32 PM