def test_delMin(iminpq): iminpq = pq.decreaseKey(iminpq, 'A', 1) key = pq.min(iminpq) assert key == 'A' iminpq = pq.increaseKey(iminpq, 'A', 12) key = pq.min(iminpq) assert key == 'D' pq.delMin(iminpq) key = pq.min(iminpq) assert key == 'B'
def Dijkstra(graph, source): """ Implementa el algoritmo de Dijkstra Args: graph: El grafo de busqueda source: El vertice de inicio Returns: Un nuevo grafo vacĂo Raises: Exception """ try: search = initSearch(graph, source) while not iminpq.isEmpty(search['iminpq']): v = iminpq.delMin(search['iminpq']) edges = g.adjacentEdges(graph, v) if edges is not None: edgesiter = it.newIterator(edges) while (it.hasNext(edgesiter)): edge = it.next(edgesiter) relax(search, edge) return search except Exception as exp: error.reraise(exp, 'dks:dijkstra')
def critical_Station(bikes): retorno = {"listuso": None, "listsalida": None, "listllegada": None} retorno["listuso"] = lt.newList('SINGLELINKED', comparevalues) retorno["listsalida"] = lt.newList('SINGLELINKED', comparevalues) retorno["listllegada"] = lt.newList('SINGLELINKED', comparevalues) while lt.size(retorno["listuso"]) < 3: x = iminpq.delMin(bikes["topuso"]) x = m.get(bikes["names"], x) x = me.getValue(x) lt.addLast(retorno["listuso"], x) while lt.size(retorno["listsalida"]) < 3: x = iminpq.delMin(bikes["topsalida"]) x = m.get(bikes["names"], x) x = me.getValue(x) lt.addLast(retorno["listsalida"], x) while lt.size(retorno["listllegada"]) < 3: x = iminpq.delMin(bikes["topllegada"]) x = m.get(bikes["names"], x) x = me.getValue(x) lt.addLast(retorno["listllegada"], x) return retorno
def companiesByServices(analyzer, num): maxPQ = analyzer['ServicePQ']['PQ'].copy() PQ_map = analyzer['ServicePQ']['Map'] cont = 0 companies = lt.newList() while cont < num: comp = ipq.delMin(maxPQ) index = lt.size(me.getValue(m.get(PQ_map, comp))) entry = {'company': comp, 'servicios': index} lt.addLast(companies, entry) cont += 1 return companies
def prim(graph, search, v): """ Args: search: La estructura de busqueda v: Vertice desde donde se relajan los pesos Returns: El grafo con los arcos relajados Raises: Exception """ try: map.put(search['distTo'], v, 0.0) pq.insert(search['pq'], v, 0.0) while (not pq.isEmpty(search['pq'])): min = pq.delMin(search['pq']) scan(graph, search, min) return search except Exception as exp: error.reraise(exp, 'prim:prim')