def Clusters(analyzer,l1,l2): estructura=scc.KosarajuSCC(analyzer['connections']) idscc=estructura['idscc'] #print(idscc) numero=scc.connectedComponents(estructura) land1=lt.newList() land2=lt.newList() vertices=gr.vertices(analyzer['connections']) a=lit.newIterator(vertices) answer=False while lit.hasNext(a): c=lit.next(a) h=c.split("-") #print(h) #if h[0] not in Lista: if h[0]==l1: lt.addLast(land1, c) if h[0]==l2: lt.addLast(land2, c) la1=lit.newIterator(land1) while lit.hasNext(la1): b=lit.next(la1) entry=mp.get(idscc,b) cluster=me.getValue(entry) #print(cluster) la2=lit.newIterator(land2) while lit.hasNext(la2): c=lit.next(la2) entry=mp.get(idscc,c) cluster1=me.getValue(entry) if cluster1==cluster: #print(cluster1) answer=True return (answer,numero) return (answer,numero)
def addCapital(analyzer): #print("Capital") Lista=lt.newList() for capital in (analyzer['countries']['table']['elements']): if capital['key']!=None: cap=me.getValue(mp.get(analyzer['countries'], capital['key'])) mini=100000000000 dist=0 landes=" " loc1=(float(cap['CapitalLatitude']),float(cap['CapitalLongitude'])) for landingp in (analyzer['landingpoints']['table']['elements']): if landingp['key']!=None and landingp['key'] not in Lista: land=me.getValue(mp.get(analyzer['landingpoints'], landingp['key'])) loc2=(float(land['latitude']),float(land['longitude'])) dist=hs.haversine(loc1,loc2) if dist<mini: mini=dist landes=land['landing_point_id'] vertices=gr.vertices(analyzer['connections']) a=lit.newIterator(vertices) while lit.hasNext(a): c=lit.next(a) h=c.split("-") #print(h) #if h[0] not in Lista: if h[0]==landes: #print(h[0],c) #print(h[0]) addLine(analyzer,mini,cap['CapitalName'],c) # #print(cap['CapitalName'],c) lt.addLast(Lista, landes)
def Shortestway(citiTaxi, origin, destination, HoI, HoF): lst = [] dicc = {} lista = gra.vertices(citiTaxi['graph']) iterator = it.newIterator(lista) while it.hasNext(iterator): fila = it.next(iterator) origin1 = fila.split('-') timeO = datetime.datetime.strptime(origin1[1], '%H:%M').time() if origin1[0] == origin: if HoI <= timeO and timeO <= HoF: lst.append(fila) for i in range(0, len(lst)): source = djk.Dijkstra(citiTaxi['graph'], lst[i]) iterator = it.newIterator(lista) while it.hasNext(iterator): vertice = it.next(iterator) com = vertice.split('-') if com[0] == destination: camino = djk.hasPathTo(source, vertice) if camino == True: tiempo = djk.distTo(source, vertice) ruta = djk.pathTo(source, vertice) if lst[i] not in dicc: dicc[lst[i]] = {'tiempo': tiempo, 'ruta': ruta} else: if tiempo < dicc[lst[i]]['tiempo']: dicc[lst[i]] = {'tiempo': tiempo, 'ruta': ruta} menores(dicc)
def vertices(graph): """ Retorna una lista con todos los vertices del grafo graph Args: graph: El grafo sobre el que se ejecuta la operacion Returns: El numero de vertices Raises: Exception """ return gr.vertices(graph)
def distPaises (analyzer,paisA,paisB): pA=me.getValue(mp.get(analyzer['countries'],paisA)) minin=1000000 listi=lt.newList() loc1=(float(pA['CapitalLatitude']),float(pA['CapitalLongitude'])) for landingp in (analyzer['landingpoints']['table']['elements']): if landingp['key']!=None: land=me.getValue(mp.get(analyzer['landingpoints'], landingp['key'])) loc2=(float(land['latitude']),float(land['longitude'])) dist=hs.haversine(loc1,loc2) if dist<minin: minin=dist landeA=land['landing_point_id'] pB=me.getValue(mp.get(analyzer['countries'],paisB)) Lista=lt.newList() dist=0 mini=10000000 loc1=(float(pB['CapitalLatitude']),float(pB['CapitalLongitude'])) for landingp in (analyzer['landingpoints']['table']['elements']): if landingp['key']!=None: land=me.getValue(mp.get(analyzer['landingpoints'], landingp['key'])) loc2=(float(land['latitude']),float(land['longitude'])) dist=hs.haversine(loc1,loc2) if dist<mini: mini=dist landes=land['landing_point_id'] vertices=gr.vertices(analyzer['connections']) a=lit.newIterator(vertices) while lit.hasNext(a): c=lit.next(a) h=c.split("-") if h[0]==landes: lt.addLast(Lista, c) if h[0]==landeA: x=c lt.addLast(listi, c) dist=-1 path="No" disti=1000000000000000 pathh="No" t=lit.newIterator(listi) while lit.hasNext(t): y=lit.next(t) route=dij.Dijkstra(analyzer['connections'],y) a=lit.newIterator(Lista) while lit.hasNext(a): e=lit.next(a) path=dij.hasPathTo(route, e) if path==True: dist=dij.distTo(route, e) path=dij.pathTo(route, e) if path !=None and dist<disti: disti=dist return(path,disti)
def addConnection(analyzer): vertices=gr.vertices(analyzer['connections']) a=lit.newIterator(vertices) while lit.hasNext(a): c=lit.next(a) b=lit.newIterator(vertices) while lit.hasNext(b): d=lit.next(b) if c!=d: h=c.split("-") j=d.split("-") if h[0]==j[0]: addLine(analyzer,100,c,d)
def fallas(analyzer,vertice): print(vertice) Lista=lt.newList() listi=lt.newList() #recorrer map con los landing points y decir que si vertice == [name:] entonces name=l[name] vertices=gr.vertices(analyzer['connections']) b=lit.newIterator(vertices) name=" " while lit.hasNext(b) and name== " ": c=lit.next(b) if "-" in c: h=c.split("-") if h[1]==vertice: name=c print("hola") edges=gr.adjacents(analyzer['connections'], name) b=lit.newIterator(edges) while lit.hasNext(b): c=lit.next(b) h=c.split("-") p=me.getValue(mp.get(analyzer['landingpoints'],h[0])) loc1=(float(p['latitude']),float(p['longitude'])) minin=100000000 landeA=0 for country in (analyzer['countries']['table']['elements']): if country['key']!=None: land=me.getValue(mp.get(analyzer['countries'], country['key'])) loc2=(float(land['CapitalLatitude']),float(land['CapitalLongitude'])) dist=hs.haversine(loc1,loc2) if dist<minin: minin=dist print("si") landeA=land['CountryName'] if landeA !=0: lt.addLast(Lista, landeA) return Lista