Implementation of Uniform Cost Search: Assignment-3
Implementation of Uniform Cost Search: Assignment-3
Implementation of UCS
def main():
# test case
gird size n = 5
#
start location = (1, 1)
#
goal location = (5, 3)
#
grid values = [[100, 99, 120, 30, 70], [3, 1, 110, 97, 68], [103, 2,
#
105, 89, 92], [87, 4, 2, 201, 73],
# [110, 90, 5, 80, 81]]
# -----------------------------------------
# the grid:
# 110 90 5 80 81
# 87 4 2 201 73
# 103 2 105 89 92
# 3 1 110 97 68
# 100 99 120 30 70
# ------------------------------------------
# the least cost path = [(1, 1), (2, 1), (2, 2), (3, 2), (4, 2), (4,
3), (5, 3)]
# the least cost = 23
least_cost_path = path_find(5, (1,1), (5,3), [[100,99,1
20,3 0,70],
[3,1,110,97,68], [103,2,105,89,92], [87,4,2,201,73], [110,9 0,5, 80,81]])
print "the least-cost path is: ", least_cost_path
main()