def fallback_cell(): while cell_by_distance: if (remaining_sides := cell_remaining_sides[t( *(cell := cell_by_distance[0][1]))]) > 1: # cell still valid as a seed point for growth after this use return cell elif remaining_sides == 1: # cell not valid as a seed point for growth after this use (the one remaining side will be used) heappop(cell_by_distance) return cell
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
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)
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
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 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"
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
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
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
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 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"
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
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]
def onClicked_Apply(self): self.ui.pbStatus.setMaximum(len(self.pathQueue)) qtd = 0 dest = self.ui.leDestPath.text().replace("\\", "/") while len(self.pathQueue) > 0: path = queue.heappop(self.pathQueue) path = path.replace("\\", "/") srcImg = cv2.imread(path) if (srcImg is None): print("Imagem nula:", path) else: aux_name = re.split('\/', path)[-1] name = '' for i in range(len(aux_name) - 4): name += aux_name[i] efx = Efx(srcImg, name) if self.ui.cbFlipH.isChecked(): efx.filpH(dest, name) if self.ui.cbFlipV.isChecked(): efx.filpV(dest, name) if self.ui.cbBlur.isChecked(): efx.blur(dest, name) if self.ui.cbGrayScale.isChecked(): efx.grayScale(dest, name) if self.ui.cbBrightness.isChecked(): efx.filter_brightnes_contrast(dest, name, 30, 1) #efx.filter_brightnes_contrast(dest,name,-30,1) #efx.filter_brightnes_contrast(dest,name,50,1) efx.filter_brightnes_contrast(dest, name, -50, 1) if self.ui.cbContrast.isChecked(): #efx.filter_brightnes_contrast(dest,name,0,0.6) #efx.filter_brightnes_contrast(dest,name,0,0.7) #efx.filter_brightnes_contrast(dest,name,0,0.8) efx.filter_brightnes_contrast(dest, name, 0, 1.2) pass if self.ui.cbRotationAnt.isChecked(): efx.rotate(dest, name, -2) efx.rotate(dest, name, -3) efx.rotate(dest, name, -5) efx.rotate(dest, name, -7) if self.ui.cbRotationAnt.isChecked(): efx.rotate(dest, name, 2) efx.rotate(dest, name, 3) efx.rotate(dest, name, 5) efx.rotate(dest, name, 7) qtd += 1 self.ui.pbStatus.setValue(qtd) self.ui.lbQtdImages.setText("{} Imagens".format(qtd)) self.ui.plainTextEdit.setPlainText("Finished")
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
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
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
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)
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)
# used to get a cell to restart maze growth when all cells hit dead ends cell_by_distance = [] def fallback_cell(): while cell_by_distance: if (remaining_sides := cell_remaining_sides[t( *(cell := cell_by_distance[0][1]))]) > 1: # cell still valid as a seed point for growth after this use return cell elif remaining_sides == 1: # cell not valid as a seed point for growth after this use (the one remaining side will be used) heappop(cell_by_distance) return cell else: # cell not valid as a seed point now, go to next heappop(cell_by_distance) 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
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))
def update_event(self, inp=-1): self.set_output_val(0, queue.heappop(self.input(0)))
def main(): #for arg in sys.argv: iterations = 2 # default if len(sys.argv) == 2: iterations = int(sys.argv[1]) print("Iterations: ") print(iterations) init() #------------------------------- # Initialisation #------------------------------- nbLignes = game.spriteBuilder.rowsize nbColonnes = game.spriteBuilder.colsize print("lignes", nbLignes) print("colonnes", nbColonnes) players = [o for o in game.layers['joueur']] nbPlayers = len(players) # on localise tous les états initiaux (loc du joueur) initStates = [o.get_rowcol() for o in game.layers['joueur']] print("Init states:", initStates) # on localise tous les objets ramassables (les restaurants) goalStates = [o.get_rowcol() for o in game.layers['ramassable']] print("Goal states:", goalStates) nbRestaus = len(goalStates) # on localise tous les murs wallStates = [w.get_rowcol() for w in game.layers['obstacle']] print("Wall states:", wallStates) # on liste toutes les positions permises allowedStates = [(x,y) for x in range(nbLignes) for y in range(nbColonnes)\ if (x,y) not in (wallStates + goalStates)] dansRestaus = {r: [] for r in range(nbRestaus)} taux = [0 for i in range(nbRestaus)] gain = [0 for i in range(nbPlayers)] restau = [0] * nbPlayers posPlayers = initStates #------------------------------- # Placement aleatoire des joueurs, en évitant les obstacles #------------------------------- for i in range(iterations): for j in range(nbPlayers): x, y = random.choice(allowedStates) players[j].set_rowcol(x, y) game.mainiteration() posPlayers[j] = (x, y) #------------------------------- # chaque joueur choisit un restaurant #------------------------------- for j in range(nbPlayers): if j % 2 == 0: c = strategie.strategie_aleatoire(nbRestaus) elif j == 1 or j == 3 or j == 5: c = strategie.strategie_tetu(j, nbRestaus) else: c = strategie.strategie_restaurant_proche( posPlayers[j], goalStates) restau[j] = c dansRestaus[c].append(j) #------------------------------- # Boucle principale de déplacements #------------------------------- for j in range(nbPlayers): pos_restau = goalStates[restau[j]] chemin = aStar.aStar(posPlayers[j], pos_restau, wallStates) print(chemin) while posPlayers[j] != pos_restau: row, col = queue.heappop(chemin) players[j].set_rowcol(row, col) print("Position du joueur : ", j, row, col) game.mainiteration() posPlayers[j] = (row, col) if (row, col) == pos_restau: game.mainiteration() print("Le joueur ", j, " est arrivé") break for i in range(nbRestaus): if len(dansRestaus[i]) == 1: j = dansRestaus[i][0] gain[j] += 1 elif len(dansRestaus[i]) > 1: j = random.choice(dansRestaus[i]) gain[j] += 1 taux[i] = len(dansRestaus[i]) / nbPlayers print("Taux du restaurant ", i, " : ", taux[i]) dansRestaus = {r: [] for r in range(nbRestaus)} for i in range(len(gain)): print("Le gain du joueur ", i, " est : ", gain[i] / iterations) pygame.quit()
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)) print(','.join(ans)) print("--- %s seconds ---" % (time.time() - start_time))