Exemplo n.º 1
0
def findPath(start, hole, board):
  if not start or not hole or not board:
    return []
  # using dijkstra to find the shortest path (store the path to the result)
  m, n = len(board), len(board[0])
  def go(c, i, j):
    x,y = c
    d = 0
    while 0<=x+i<m and 0<=y+j<n and board[x+i][y+j] == "0":
      if (x,y) == hole:
        break
      x, y = x+i, y+j
      d += 1
    return d,(x,y)
  q = list()
  visited = set()
  heappush(q, (0, "", start))
  while q:
    count, path, cur = heappop(q)
    # print(count, path, cur)
    if cur in visited:
      continue
    visited.add(cur)
    if cur == hole:
      return path
    for d,i,j in [("u",-1,0),("l",0,-1),("r",0,1),("d",1,0)]:
      l, point = go(cur, i,j)
      # if point != cur:
      heappush(q, (l+count, path+d, point))
  return "impossible"
Exemplo n.º 2
0
def solve(grid, sx, sy):

    row = [0, 1, 1, 1, 0, -1, -1, -1]
    col = [1, 1, 0, -1, -1, -1, 0, 1]
    heap = []
    dis = [[-1] * n for i in range(m)]
    par = [[(-1, -1)] * n for i in range(m)]
    heappush(heap, (0, (sx, sy)))
    dis[sx][sy] = 0
    dest = (-1, -1)
    while (len(heap) != 0):
        (ux, uy) = heappop(heap)[1]
        if (grid[ux][uy] == 1):
            dest = (ux, uy)
            break
        for i in range(8):
            vx = ux + row[i]
            vy = uy + col[i]
            if (abs(row[i]) == 1 and abs(col[i]) == 1):
                cost = 1.414
            else:
                cost = 1
            if (issafe(grid, vx, vy) and dis[vx][vy] == -1):
                dis[vx][vy] = cost + dis[ux][uy]
                heappush(heap, (dis[vx][vy], (vx, vy)))
                par[vx][vy] = (ux, uy)
    return (par, dest)
def astar_function(_map: list, start_pos: tuple, des_pos: tuple, n_rol: int,
                   n_col: int):
    min_heap = []
    heappush(min_heap, (h_n(start_pos, des_pos), start_pos))
    visited_node = {}
    direction = [(1, 0), (0, 1), (-1, 0), (0, -1)]
    while min_heap:
        cur_f_x, cur_pos = heappop(min_heap)
        cur_h_n = h_n(cur_pos, des_pos)
        if cur_pos == des_pos:
            path = []
            path.append(cur_pos)
            while path[-1] != start_pos:
                path.append(visited_node[path[-1]])
            path.reverse()
            path.pop(0)
            return path, len(path)
        adj_node = ()
        for i in direction:
            adj_node = ((cur_pos[0] + i[0]), (cur_pos[1] + i[1]))
            if adj_node[0] not in range(n_rol) or adj_node[1] not in range(
                    n_col):
                continue
            if adj_node not in visited_node and _map[adj_node[0]][
                    adj_node[1]] is not None:
                adj_f_x = (cur_f_x - cur_h_n) + 1 + h_n(adj_node, des_pos)
                heappush(min_heap, (adj_f_x, adj_node))
                visited_node[adj_node] = cur_pos
    return None, None
 def dept_limited_astar_search(self, start, goal, limit=-1):
     print('Depth Limit =', limit)
     found, fringe, visited = False, [(self.huristics[start], start, 0)
                                      ], set([start])
     came_from, cost_so_far = {start: None}, {start: 0}
     print('{:11s} | {}'.format('Expand Node', 'Fringe'))
     print('--------------------')
     print('{:11s} | {}'.format('-', str(fringe[0][:-1])))
     while not found and len(fringe):
         _, current, depth = heappop(fringe)
         print('{:11s}'.format(current), end=' | ')
         if current == goal:
             found = True
             break
         if limit == -1 or depth < limit:
             for node in self.neighbors(current):
                 new_cost = cost_so_far[current] + self.cost(current, node)
                 if node not in visited or cost_so_far[node] > new_cost:
                     visited.add(node)
                     came_from[node] = current
                     cost_so_far[node] = new_cost
                     heappush(
                         fringe,
                         (new_cost + self.huristics[node], node, depth + 1))
         print(', '.join([str(n[:-1]) for n in fringe]))
     if found:
         print()
         return came_from, cost_so_far[goal], len(visited)
     else:
         print('No path from {} to {}'.format(start, goal))
         return None, inf, len(visited)
Exemplo n.º 5
0
 def a_star_search(self, start, goal):
     found, fringe, visited, came_from, cost_so_far = False, [
         (self.huristics[start], start)
     ], set([start]), {
         start: None
     }, {
         start: 0
     }
     print('{:11s} | {}'.format('Expand Node', 'Fringe'))
     print('--------------------')
     print('{:11s} | {}'.format('-', str(fringe[0])))
     while not found and len(fringe):
         _, current = heappop(fringe)
         print('{:11s}'.format(current), end=' | ')
         if current == goal:
             found = True
             break
         for node in self.neighbors(current):
             new_cost = cost_so_far[current] + self.cost(current, node)
             if node not in visited or cost_so_far[node] > new_cost:
                 visited.add(node)
                 came_from[node] = current
                 cost_so_far[node] = new_cost
                 heappush(fringe, (new_cost + self.huristics[node], node))
         print(', '.join([str(n) for n in fringe]))
     if found:
         print()
         return came_from, cost_so_far[goal]
     else:
         print('No path from {} to {}'.format(start, goal))
         return None, inf
Exemplo n.º 6
0
def degreeMRV(grid,x,y) :

	row = [-1,-1,-1,1,1,1,0,0]
	col = [0,1,-1,0,1,-1,1,-1]
	for i in range(8) :
		xindex = x + row[i]
		yindex = y + col[i]
		pos = m*n - count
		if(not issafe(xindex,yindex) or grid[xindex][yindex] != " ") :
			continue
		for member in slist :
			if(not mark[member]) :
				for j in range(8) :
					fxindex = xindex + row[j]
					fyindex = yindex + col[j]
					if(issafe(fxindex,fyindex)) :
						if(grid[fxindex][fyindex] != " " and grid[fxindex][fyindex] not in adj[member]) :
							pos -= 1
							break
		degree = 0
		for j in range(8) :
			fxindex = xindex + row[j]
			fyindex = yindex + col[j]
			if(issafe(fxindex,fyindex) and grid[fxindex][fyindex] == " ") :
				degree += 1

		heappush(myheap,(pos,-degree,(xindex,yindex)))
	return heappop(myheap)[2]
Exemplo n.º 7
0
def getPath_1(start, end, maze):
    """
  Dijkstra algorithm
  """
    if not maze:
        return -1
    visited = set()
    m, n = len(maze), len(maze[0])
    q = []
    heappush(q, (0, start))

    def go(point, d):
        i, j = point
        l = 0
        while 0 <= i + d[0] < m and 0 <= j + d[1] < n and maze[i + d[0]][
                j + d[1]] != "1":
            i += d[0]
            j += d[1]
            l += 1
        return l, (i, j)

    while q:
        length, cur = heappop(q)
        if cur in visited:
            continue
        visited.add(cur)
        if cur == end:
            return length
        for dir in {(-1, 0), (1, 0), (0, 1), (0, -1)}:
            l, point = go(cur, dir)
            heappush(q, (l + length, point))
    return -1
Exemplo n.º 8
0
def getPath_1(start, end, maze):
  """
  Dijkstra algorithm
  """
  if not maze:
    return -1
  visited = set()
  m, n = len(maze), len(maze[0])
  q = []
  heappush(q, (0, start))
  def go(point, d):
    i, j = point
    l = 0
    while 0<=i+d[0]<m and 0<=j+d[1]<n and maze[i+d[0]][j+d[1]] != "1":
      i += d[0]
      j += d[1]
      l += 1
    return l, (i, j)
  while q:
    length, cur = heappop(q)
    if cur in visited:
      continue
    visited.add(cur)
    if cur == end:
      return length
    for dir in {(-1, 0), (1, 0), (0, 1), (0,-1)}:
      l, point = go(cur, dir)
      heappush(q, (l+length, point))
  return -1
Exemplo n.º 9
0
def findPath(start, hole, board):
    if not start or not hole or not board:
        return []
    # using dijkstra to find the shortest path (store the path to the result)
    m, n = len(board), len(board[0])

    def go(c, i, j):
        x, y = c
        d = 0
        while 0 <= x + i < m and 0 <= y + j < n and board[x + i][y + j] == "0":
            if (x, y) == hole:
                break
            x, y = x + i, y + j
            d += 1
        return d, (x, y)

    q = list()
    visited = set()
    heappush(q, (0, "", start))
    while q:
        count, path, cur = heappop(q)
        # print(count, path, cur)
        if cur in visited:
            continue
        visited.add(cur)
        if cur == hole:
            return path
        for d, i, j in [("u", -1, 0), ("l", 0, -1), ("r", 0, 1), ("d", 1, 0)]:
            l, point = go(cur, i, j)
            # if point != cur:
            heappush(q, (l + count, path + d, point))
    return "impossible"
Exemplo n.º 10
0
 def uniform_cost_search(self, start, goal, output):
     found, fringe, visited, came_from, cost_so_far = False, [
         (0, start)
     ], set([start]), {
         start: None
     }, {
         start: 0
     }
     output.write('{:11s} | {}\n'.format('Expand Node', 'Fringe'))
     output.write('--------------------\n')
     output.write('{:11s} | {}\n'.format('-', str((0, start))))
     while not found and len(fringe):
         _, current = heappop(fringe)
         output.write('{:11s} | '.format(current))
         if current == goal:
             found = True
             break
         for node in self.neighbors(current):
             new_cost = cost_so_far[current] + self.cost(current, node)
             if node not in visited or cost_so_far[node] > new_cost:
                 visited.add(node)
                 came_from[node] = current
                 cost_so_far[node] = new_cost
                 heappush(fringe, (new_cost, node))
         output.write(', '.join([str(n) for n in fringe]) + "\n")
     if found:
         output.write("\n")
         return came_from, cost_so_far[goal]
     else:
         output.write('No path from {} to {}'.format(start, goal))
         return None, inf
Exemplo n.º 11
0
 def UCS(self):
     startT = datetime.now()
     start = self.maze.getCell(0, 0)
     goal = self.maze.getCell(self.maze.size - 1, self.maze.size - 1)
     found, fringe, visited, came_from, cost_so_far = False, [
         (0, start)
     ], set([start]), {
         start: None
     }, {
         start: 0
     }
     while not found and len(fringe):
         _, current = heappop(fringe)
         if current == goal:
             found = True
             break
         for node in current.edges.values():
             new_cost = cost_so_far[current] + 1
             if node not in visited or cost_so_far[node] > new_cost:
                 visited.add(node)
                 came_from[node] = current
                 cost_so_far[node] = new_cost
                 heappush(fringe, (new_cost, node))
     if found:
         print("UCS total time run ",
               datetime.now() - startT, " total expanded cells:",
               len(came_from), " optimum path lenght: ", self.maze.optimum)
         return came_from, cost_so_far[goal]
     else:
         print('No path from {} to {}'.format(start, goal))
         return None, inf
Exemplo n.º 12
0
    def uniform_cost_search(self, asal, tujuan):
        found, fringe, visited, sumber, cost_so_far = False, [(0, asal)
                                                              ], set([asal]), {
                                                                  asal: None
                                                              }, {
                                                                  asal: 0
                                                              }

        while not found and len(fringe):
            _, kota_sekarang = heappop(fringe)

            if kota_sekarang == tujuan:
                found = True
                break

            for kota in self.neighbors(kota_sekarang):
                new_cost = cost_so_far[kota_sekarang] + self.cost(
                    kota_sekarang, kota)

                if kota not in visited or new_cost < cost_so_far[kota]:
                    visited.add(kota)
                    sumber[kota] = kota_sekarang
                    cost_so_far[kota] = new_cost
                    heappush(fringe, (new_cost, kota))

        print("\nUniform Cost Search", end='')

        if found:
            print()
            return sumber, cost_so_far[tujuan]
        else:
            print('\nTidak Ada Rute dari {} ke {}'.format(asal, tujuan))
            return None, 0
Exemplo n.º 13
0
 def set_visited(x, y, d):
     nonlocal cells_visited
     cells_visited += 1
     cell_distance[t(x, y)] = d
     heappush(cell_by_distance, (-d, (x, y)))
     if in_bounds(*c_l(x, y)):
         cell_remaining_sides[t(*c_l(x, y))] -= 1
     if in_bounds(*c_r(x, y)):
         cell_remaining_sides[t(*c_r(x, y))] -= 1
     if in_bounds(*c_t(x, y)):
         cell_remaining_sides[t(*c_t(x, y))] -= 1
     if in_bounds(*c_b(x, y)):
         cell_remaining_sides[t(*c_b(x, y))] -= 1
Exemplo n.º 14
0
 def onClicked_SrcPath(self):
     path = self.openFolder()
     self.ui.leSrcPath.setText(path)
     self.enableBtnApply()
     paths = ""
     for root, _, files in os.walk(path):
         for filename in files:
             x = os.path.join(root, filename)
             if os.path.isfile(x):
                 isImg = imghdr.what(x)
                 if isImg:
                     paths += x + '\n'
                     queue.heappush(self.pathQueue, x)
                 else:
                     print('Not an image')
     self.ui.plainTextEdit.setPlainText(paths)
Exemplo n.º 15
0
 def minimumEffortPath(self, heights: List[List[int]]) -> int:
     di = (0, 1, 0, -1)
     dj = (1, 0, -1, 0)
     m, n = len(heights), len(heights[0])
     visited = [[False] * n for _ in range(m)]
     h = [(0, 0, 0)]
     while h:
         effort, i, j = heappop(h)
         if visited[i][j]:
             continue
         visited[i][j] = True
         if i + 1 == m and j + 1 == n:
             return effort  ## have reached the (m-1, n-1) cell
         for k in range(4):
             ii, jj = i + di[k], j + dj[k]
             if 0 <= ii < m and 0 <= jj < n and not visited[ii][jj]:
                 neffort = max(effort, abs(heights[i][j] - heights[ii][jj]))
                 heappush(h, (neffort, ii, jj))
     return ## cell (m-1, n-1) not reachable, should never happen
Exemplo n.º 16
0
 def uniform_cost_search(self, start, goal):
     # Initial State
     G1 = nx.DiGraph()
     found, fringe, visited, came_from, cost_so_far = False, [
         (0, start)
     ], set([start]), {
         start: None
     }, {
         start: 0
     }
     # Cosmetic
     print('{:15s} | {}'.format('Expand Node', 'Fringe'))
     print('-------------------------')
     print('{:15s} | {}'.format('-', str((0, start))))
     # Step
     while not found and len(fringe):
         _, current = heappop(fringe)
         print('{:15s}'.format(current), end=' | ')
         if current == goal:
             found = True
             break
         for node in self.neighbors(current):
             new_cost = cost_so_far[current] + self.cost(current, node)
             if node not in visited or cost_so_far[node] > new_cost:
                 visited.add(node)
                 came_from[node] = current
                 cost_so_far[node] = new_cost
                 heappush(fringe, (new_cost, node))
                 G1.add_node(current)
                 G1.add_edge(current, node)
         print(', '.join([str(n) for n in fringe]))
     # Result
     pos = hierarchy_pos(G1, start)
     nx.draw(G1, pos=pos, with_labels=True)
     plt.show()
     if found:
         print()
         return came_from, cost_so_far[goal]
     else:
         print('No path from {} to {}'.format(start, goal))
         return None, inf
Exemplo n.º 17
0
    def rank_files(self, query_string, list_of_files):

        query_vector = self.query_string_to_vector(query_string)
        q = []
        cnt = 0
        for file in list_of_files:
            file_vector = self.tf_idf_vector[file]
            score = self.cosine_similarity(query_vector, file_vector)
            queue.heappush(q, (score, file))
            cnt += 1
            if cnt > self.k:
                queue.heappop(q)
                cnt -= 1

        result = []
        while cnt > 0:
            result.append(queue.heappop(q))
            cnt -= 1

        result = reversed(result)

        return result
Exemplo n.º 18
0
def astar(s, d):
    l = []
    heappush(l, (mandis(s), s))
    vis[s[0]][s[1]] = 0
    result = -1
    count = 0
    parent = [[(-1, -1)] * dim[1] for i in range(dim[0])]
    row = [-1, 0, 0, 1]
    col = [0, -1, 1, 0]
    while (len(l) != 0):
        curr = heappop(l)[1]
        if (curr[0] == d[0] and curr[1] == d[1]):
            result = vis[curr[0]][curr[1]]
            break
        for index in range(4):
            u, v = curr[0] + row[index], curr[1] + col[index]

            if (check([u, v])):
                vis[u][v] = 1 + vis[curr[0]][curr[1]]
                heappush(l, (vis[u][v] + mandis([u, v]), [u, v]))
                parent[u][v] = (curr[0], curr[1])

    return (result, parent)
Exemplo n.º 19
0
def leastConstrainedValue(available,x,y) :
	
	row = [-1,-1,-1,1,1,1,0,0]
	col = [0,1,-1,0,1,-1,1,-1]
	priority_available = []
	for student in available :
		lsv = 0
		for i in range(8) :
			xindex = x + row[i]
			yindex = y + col[i]
			temp = []
			if(issafe(xindex,yindex) and grid[xindex][yindex] != " ") :
				for j in range(8) :
					fxindex = xindex + row[j]
					fyindex = yindex + col[j]
					if(issafe(fxindex,fyindex)) :
						if(grid[fxindex][fyindex] != " ") :
							temp.append(grid[fxindex][fyindex])
				if(student not in temp and student not in adj[grid[xindex][yindex]]) :
					lsv += 1
		heappush(priority_available,(lsv,student))

	available = [i[1] for i in priority_available]
	return available
Exemplo n.º 20
0
def solve(grid, sx, sy):

    heap = []
    dis = [[-1] * n for i in range(m)]
    par = [[(-1, -1)] * n for i in range(m)]
    direction = [(0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1), (-1, 0),
                 (-1, 1)]
    heappush(heap, (0, 0, (sx, sy)))
    dis[sx][sy] = 0
    dest = (-1, -1)
    while (len(heap) != 0):
        top = heappop(heap)
        (ux, uy) = top[2]
        go = top[1]
        curr_cost = top[0]
        if (grid[ux][uy] == 1):
            dest = (ux, uy)
            break
        #go in direction
        vx = ux + direction[go][0]
        vy = uy + direction[go][1]
        if (abs(direction[go][0]) == 1 and abs(direction[go][1]) == 1):
            cost = 1.414
        else:
            cost = 1
        if (issafe(grid, vx, vy) and dis[vx][vy] == -1):
            dis[vx][vy] = curr_cost + cost
            heappush(heap, (dis[vx][vy], go, (vx, vy)))
            par[vx][vy] = (ux, uy)

        #change direction clockwise
        heappush(heap, (curr_cost + 5, turnclock(go), (ux, uy)))
        #change direction anticlockwise
        heappush(heap, (curr_cost + 5, turnanticlock(go), (ux, uy)))

    return (par, dest)
Exemplo n.º 21
0
 def update_event(self, inp=-1):
     self.set_output_val(0, queue.heappush(self.input(0), self.input(1)))
Exemplo n.º 22
0
def switch(t1, n1, m1, p_matrix1, lambda_list1, q_list1, mu_list1, file_temp):

    #   create a context for time measure
    #   context = Context()

    t_w = 0
    t_s = 0
    #   frames left to be handled
    frames_left_counter = 0
    #   initialize events queue
    events = []
    time_t = 0
    while float(time_t) < float(t1):
        for i_port in range(int(n1)):
            #   pick an output port according to the port's probabilities
            outport_array = [o for o in range(int(m1))]
            output_port_array = np.random.choice(outport_array, 1, False,
                                                 p_matrix1[i_port])
            output_port = output_port_array[0]
            lambda_var1 = float(lambda_list1[i_port])
            val_exp = np.random.exponential(1.0 / lambda_var1)
            time_t += (val_exp)
            #   context.tick(float(val_exp))
            entry = [float(time_t), [output_port, True, False]]
            queue.heappush(events, entry)
            frames_left_counter += 1
            #   t_w -= context.get_time()
    #   a counter array for deleted frames in each output port
    deleted_output_port = []
    for i1 in range(int(m1)):
        deleted_output_port.append(0)

    #   a counter of the deleted frames (X)
    deleted_frames_counter = 0

    #   a counter array for finished frames in each output port
    frames_done_output_port = []
    for i2 in range(int(m1)):
        frames_done_output_port.append(0)

    #   a counter of the finished frames (Y)
    frames_done_counter = 0

    #   simulation starts here
    t_tag = 0
    #   todo: check what should be the unit
    output_ports_counter = [0] * int(m1)
    free_port = [True] * (int(m1))
    ports_service_time = [0] * (int(m1))
    while not len(events) == 0:
        curr_event = queue.heappop(events)
        o_port = int(curr_event[1][0])
        is_new_frame = bool(curr_event[1][1])
        queued = bool(curr_event[1][2])
        time_stamp = float(curr_event[0])
        is_full = (int(output_ports_counter[o_port]) == int(q_list1[o_port]))
        is_port_free = free_port[o_port]
        #   print(o_port, is_new_frame, time_stamp, is_full, sep=",")
        if is_new_frame:
            if is_full:
                if not is_port_free:
                    deleted_output_port[o_port] += 1
                    deleted_frames_counter += 1
                    if queued:
                        output_ports_counter[o_port] -= 1
                        t_w += time_stamp
                elif is_port_free:
                    #   print("bad")
                    #   add/sub start of service time
                    t_w += time_stamp
                    if not queued:
                        output_ports_counter[o_port] += 1
                        t_w -= time_stamp
                    lambda_var = float(mu_list1[o_port])
                    exp_out1 = np.random.exponential(1.0 / lambda_var)
                    time_entry = time_stamp + exp_out1
                    entry = [time_entry, [o_port, False, False]]
                    queue.heappush(events, entry)
                    free_port[o_port] = False
                    ports_service_time[o_port] = exp_out1
                #    continue
            if not is_full:
                if not is_port_free:
                    if not queued:
                        output_ports_counter[o_port] += 1
                        #   sub enter to queue time
                        t_w -= time_stamp
                    new_event = [
                        time_stamp + ports_service_time[o_port],
                        [o_port, True, True]
                    ]
                    queue.heappush(events, new_event)
                if is_port_free:
                    if not queued:
                        #   sub enter to queue time
                        t_w -= time_stamp
                        output_ports_counter[o_port] += 1
                        new_event = [
                            time_stamp + ports_service_time[o_port],
                            [o_port, True, True]
                        ]
                        queue.heappush(events, new_event)
                    else:
                        t_w += time_stamp
                        lambda_var = float(mu_list1[o_port])
                        exp_out2 = np.random.exponential(1.0 / lambda_var)
                        time_entry = time_stamp + exp_out2 + ports_service_time[
                            o_port]
                        entry = [time_entry, [o_port, False, False]]
                        queue.heappush(events, entry)
                        free_port[o_port] = False
                        ports_service_time[o_port] = exp_out2
        else:
            #   END SERVICE
            output_ports_counter[o_port] -= 1
            frames_done_counter += 1
            frames_done_output_port[o_port] += 1
            lambda_var = float(mu_list1[o_port])
            exp_out = np.random.exponential(1.0 / lambda_var)
            t_tag = time_stamp + exp_out
            #   adding end of service time
            t_s += exp_out
            free_port[o_port] = True
            ports_service_time[o_port] = 0

    y = frames_done_counter
    x = deleted_frames_counter
    t_w_avg = float(t_w / y)
    t_s_avg = float(t_s / y)

    file_temp.write(
        "T':, %.8f, x:, %d, x1:, %d, y:, %d, y1:, %d, Tw:, %.8f, Ts:, %.8f, T:, %.8f\n"
        % (t_tag, deleted_frames_counter, deleted_output_port[0],
           frames_done_counter, frames_done_output_port[0], t_w_avg, t_s_avg,
           t_w_avg + t_s_avg))
Exemplo n.º 23
0
node_i.distance=0
graph_len=len(graph)
while graph_len>1:
    if not node_i.visited:         
        for edge_i in node_i.edges:
            #print(edge_i.node1.vertex,edge_i.node2.vertex)
            if edge_i.visited:
                pass
            else:
                if edge_i.node1 == node_i:
                    sink=edge_i.node2
                else:
                    sink=edge_i.node1
                if node_i.distance+edge_i.weight < sink.distance:
                    sink.distance=node_i.distance+edge_i.weight
                q.heappush(heap_,(sink.distance,edge_i,sink))
    node_i.visited=True
    if not heap_:
            break
    vw,edge_i,sink=q.heappop(heap_)
    while sink.visited:
        if not heap_:
            break
        vw,edge_i,sink=q.heappop(heap_)
    #print(node_i.vertex,sink.vertex,vw,edge_i)
    edge_i.visited=True
    node_i=sink

ans=[]
for i in [7,37,59,82,99,115,133,165,188,197]:
    ans.append(str(graph[i].distance))