from Assignment2 import UCS_Traversal cost = [[0, 0, 0, 0, 0, 0, 0], [0, 0, 2, 0, 0, 10, 7], [0, 0, 0, 3, 0, 0, 0], [0, 0, 0, 0, 2, 0, 2], [0, 0, 0, 0, 0, 3, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 3, 0]] print(UCS_Traversal(cost, 1, [5]))
from Assignment2 import UCS_Traversal cost = [[0 if i == j else -1 for j in range(9)] for i in range(9)] cost[1][3] = 3 cost[1][2] = 7 cost[3][4] = 9 cost[2][5] = 6 cost[2][3] = 2 cost[4][5] = 3 cost[4][8] = 13 cost[5][6] = 2 cost[5][7] = 1 for j in range(9): for k in range(9): if cost[j][k] > 0: cost[k][j] = cost[j][k] heuristic = [0 for i in range(9)] goals = [8] l = UCS_Traversal(cost, 1, goals) print(l)
def test(start_point, goals, result): l = UCS_Traversal(cost, start_point, goals) path = [number_to_city[v] for v in l] print("->".join(path)) return l == result
from Assignment2 import UCS_Traversal cost = [[0, 0, 0, 0], [0, 0, 5, 10], [0, 5, 0, 5], [0, 10, 5, 0]] goal = [3] start = 1 l = UCS_Traversal(cost, start, goal) print(l)