Esempio n. 1
0
def strongly_conected(catalog,v1,v2):

    if m.contains(catalog["connections_scc"]["idscc"],v1)==False or m.contains(catalog["connections_scc"]["idscc"],v2)==False:
        return False
    elif  scc.stronglyConnected(catalog["connections_scc"],v1,v2)==False:
        return 0
    elif  scc.stronglyConnected(catalog["connections_scc"],v1,v2)==True:
        return True
Esempio n. 2
0
def areConnected(analyzer, lp1, lp2):
    analyzer['components'] = scc.KosarajuSCC(analyzer['connections'])
    connected = scc.stronglyConnected(analyzer['components'], lp1, lp2)
    if connected:
        return 1
    else:
        return 0
Esempio n. 3
0
def stronglyConnectedVertexs(analyzer, vertexa, vertexb):
    """
    Retorna si dos vértices están fuertemente
    conectados o no
    """
    sccomponents = analyzer['sccomponents']
    return scc.stronglyConnected(sccomponents, vertexa, vertexb)
Esempio n. 4
0
def req1(analyzer,landingp1,landingp2):
    kosaraju=scc.KosarajuSCC(analyzer['connections_normal'])
    num_clusters=kosaraju['components']
    origin=str(cityname_to_id(analyzer,landingp1))
    destination=str(cityname_to_id(analyzer,landingp2))
    estan_o_no=scc.stronglyConnected(kosaraju,origin,destination)
    return (num_clusters,estan_o_no)
Esempio n. 5
0
def Requirement1(analyzer, landing_point1, landing_point2):

    tracemalloc.start()

    delta_time = -1.0
    delta_memory = -1.0

    start_time = getTime()
    start_memory = getMemory()

    analyzer['components'] = scc.KosarajuSCC(
        analyzer['connections_origin_destination'])

    connected_components = scc.connectedComponents(analyzer['components'])

    lp1 = matchLandingPoint(analyzer, landing_point1)
    lp2 = matchLandingPoint(analyzer, landing_point2)

    parameter1 = matchGraphKeyOrigin(analyzer, lp1)
    parameter2 = matchGraphKeyDestination(analyzer, lp2)

    same_cluster = scc.stronglyConnected(analyzer["components"], parameter1,
                                         parameter2)

    stop_memory = getMemory()
    stop_time = getTime()
    tracemalloc.stop()

    delta_time = stop_time - start_time
    delta_memory = deltaMemory(start_memory, stop_memory)

    return connected_components, same_cluster, delta_time, delta_memory
def Requerimiento1(analyzer, landing1, landing2):
    analyzer['element'] = scc.KosarajuSCC(analyzer['connections_directed'])
    cluster_number = scc.connectedComponents(analyzer['element'])
    get_landing1 = mp.get(analyzer['landing_names_id'], landing1)
    id_landing1 = me.getValue(get_landing1)
    dict_landing_pareja1 = om.get(analyzer['landing_points'], id_landing1)
    dict_landing1 = me.getValue(dict_landing_pareja1)
    lista_cables1 = dict_landing1['cables']
    vectorA = lt.getElement(lista_cables1, 1)
    get_landing2 = mp.get(analyzer['landing_names_id'], landing2)
    id_landing2 = me.getValue(get_landing2)
    dict_landing_pareja2 = om.get(analyzer['landing_points'], id_landing2)
    dict_landing2 = me.getValue(dict_landing_pareja2)
    lista_cables2 = dict_landing1['cables']
    vectorB = lt.getElement(lista_cables2, 1)
    inform_cluster = scc.stronglyConnected(analyzer['element'], vectorA,
                                           vectorB)

    if inform_cluster == False:
        print('Los landing points consultados no estan en el mismo cluster')
    else:
        print(
            'Los landing points cosnultados se encuentran en el mismo cluster')
        print('El total de clústers presentes en la red es igual a ' +
              str(cluster_number))
def dfsVertexc(search, graph, vertex, source, sc):
    try:
        adjlst = gr.adjacents(graph, vertex)

        adjslstiter = it.newIterator(adjlst)
        while (it.hasNext(adjslstiter)):
            w = it.next(adjslstiter)
            visited = m.get(search['visited'], w)

            if visited is None:
                m.put(search['visited'], w, {'marked': True, 'edgeTo': vertex})
                if scc.stronglyConnected(sc, w, source):
                    dfsVertexc(search, graph, w, source, sc)
            elif w == source and gr.getEdge(graph, vertex, source) != None:
                cycle = lt.newList()
                lt.addLast(cycle, vertex)
                lt.addLast(cycle, w)
                x = me.getValue(m.get(search['visited'], vertex))['edgeTo']

                while x != None:
                    lt.addFirst(cycle, x)
                    x = me.getValue(m.get(search['visited'], x))['edgeTo']
                lt.addLast(search['cycles'], cycle)
        return search
    except Exception as exp:
        error.reraise(exp, 'dfs:dfsVertex')
Esempio n. 8
0
def requerimiento1(catalog, point1, point2):
    catalog['compo'] = scc.KosarajuSCC(catalog['connections'])
    k = 1
    g = 1
    tr1 = False
    tr2 = False
    while k <= lt.size(gr.vertices(catalog['connections'])) and not tr1:
        j = lt.getElement(gr.vertices(catalog['connections']), k)
        idd1 = j.split("-", 1)
        ll1 = mp.get(catalog['points'], idd1[0])
        name1 = ll1['value']['name']
        if point1.lower() in name1.lower():
            ver1 = j
            tr1 = True
        k += 1
    while g <= lt.size(gr.vertices(catalog['connections'])) and not tr2:
        i = lt.getElement(gr.vertices(catalog['connections']), g)
        idd2 = i.split("-", 1)
        ll2 = mp.get(catalog['points'], idd2[0])
        name2 = ll2['value']['name']
        if point2.lower() in name2.lower():
            ver2 = i
            tr2 = True
        g += 1
    con = scc.stronglyConnected(catalog['compo'], ver1, ver2)
    requerimiento8(catalog)
    return scc.connectedComponents(catalog['compo']), con
Esempio n. 9
0
def req1(catalog, lp1, lp2):

    grafo = catalog["connections"]
    landing_points = catalog["landing_points"]
    traductor = catalog["traduccion"]

    componentes = scc.KosarajuSCC(grafo)

    numComponentes = componentes["components"]

    try:
        lp1 = lt.getElement(mp.get(traductor, lp1)["value"], 1)
        vertice1 = lp1 + "|" + lt.getElement(
            mp.keySet(mp.get(landing_points, lp1)["value"][1]), 1)
    except TypeError:
        vertice1 = lp1

    try:
        lp2 = lt.getElement(mp.get(traductor, lp2)["value"], 1)
        vertice2 = lp2 + "|" + lt.getElement(
            mp.keySet(mp.get(landing_points, lp2)["value"][1]), 1)
    except TypeError:
        vertice2 = lp2

    areConnected = scc.stronglyConnected(componentes, vertice1, vertice2)

    return numComponentes, areConnected
Esempio n. 10
0
def cantidadClusters(analyzer, id1, id2):  #Req. 1
    """
    ----------REQUERIMIENTO 1------------
    OUTPUTS:
        TUPLE: (1,2)
            1: Clusters
            2: Sí dos nodos están en el mismo clúster
            3: Variable del algoritmo
    """
    try:
        var = scc.KosarajuSCC(analyzer['graph'])
        vertices = gr.vertices(analyzer['graph'])
        clusters = {'size': 0}
        iterator = it.newIterator(vertices)
        while it.hasNext(iterator):
            current = it.next(iterator)
            cod = m.get(var['idscc'], current)['value']
            if cod not in clusters:
                clusters[cod] = lt.newList(cmpfunction=compareConnections)
                clusters['size'] += 1
            lt.addLast(clusters[cod], current)
        conected = False
        if m.get(var['idscc'], id1) != None and m.get(var['idscc'],
                                                      id2) != None:
            conected = scc.stronglyConnected(var, id1, id2)
        return (clusters, conected, var)
    except:
        return -1
Esempio n. 11
0
def clusteres(analyzer,lp1,lp2):
    cfc=scc.KosarajuSCC(analyzer['connections'])
    numero=scc.connectedComponents(cfc)
    vertice1=me.getValue(mp.get(analyzer['nombrelp_codigo'],lp1))
    vertice2=me.getValue(mp.get(analyzer['nombrelp_codigo'],lp2))
    conectados=scc.stronglyConnected(cfc,vertice1,vertice2)
    return(numero,conectados)
Esempio n. 12
0
def clusters(catalogo, lp1, lp2):
    componentes = scc.KosarajuSCC(catalogo["conexiones"])
    conexionlp = scc.stronglyConnected(
        componentes,
        m.get(catalogo["invertices"], lp1)["value"],
        m.get(catalogo["invertices"], lp2)["value"])
    return componentes["components"], conexionlp
Esempio n. 13
0
def Requerimiento1(analyzer, landing_point1, landing_point2):
    """
    Retorna ...
    """
    clusters = scc.KosarajuSCC(analyzer['connections'])
    numClusters = scc.connectedComponents(clusters)
    mismoCluster = -1
    punto1 = None
    punto2 = None
    listaPuntos = mp.valueSet(analyzer['landing_points'])
    for punto in lt.iterator(listaPuntos):
        nombre = punto['name'].split(", ")[0]
        if nombre == landing_point1.title():
            punto1 = punto['landing_point_id']
        if nombre == landing_point2.title():
            punto2 = punto['landing_point_id']
    if punto1 is not None and punto2 is not None:
        entry = mp.get(analyzer["points_vertices"], punto1)
        if entry is not None:
            lstLP1 = me.getValue(entry)
            lp1 = lt.firstElement(lstLP1)
        entry = mp.get(analyzer["points_vertices"], punto2)
        if entry is not None:
            lstLP2 = me.getValue(entry)
            lp2 = lt.firstElement(lstLP2)
        if lp1 != "" and lp2 != "":
            mismoCluster = scc.stronglyConnected(clusters, lp1, lp2)
    return numClusters, mismoCluster
 def req_1(self, lp1, lp2):
     id_1 = self.name_to_id(lp1)
     id_2 = self.name_to_id(lp2)
     respuesta = scc.stronglyConnected(self.clusters, id_1, id_2)
     if respuesta:
         graphing_helper(self).all_points_cluster(
             mp.get(self.clusters['idscc'], id_1)['value'])
     return respuesta
def clusteredStations(citibike, id1,id2):
    try:
        clusters = connectedComponents(citibike)
        isThereCluster = scc.stronglyConnected(citibike["components"], id1,id2)
        retorno = (clusters, isThereCluster)
    except:
        retorno = (clusters, "")
    return retorno
Esempio n. 16
0
def estan_closter(analyzer, pais1, pais2):
    Entry1 = mp.get(analyzer["landing_points"], pais1)
    Pais_1 = me.getValue(Entry1)
    entry2 = mp.get(analyzer["landing_points"], pais2)
    pais_2 = me.getValue(entry2)
    booleano = scc.stronglyConnected(analyzer["components"],
                                     str(Pais_1["landing_point_id"]),
                                     str(pais_2["landing_point_id"]))
    return booleano
Esempio n. 17
0
def calcConnectedComponents(catalog, lp1, lp2):
    """
    Usa el algoritmo de Kosaraju Para calcular los componentes connectados del grafo.
    El numero de clusters (componenetes conectados)  y si dos lps estan fuertemente conectados (pertencecen al mismo cluster)
    """
    catalog['components'] = scc.KosarajuSCC(catalog['internet_graph'])
    num_clusters = scc.connectedComponents(catalog['components'])
    landpts_cluster = scc.stronglyConnected(catalog['components'], lp1, lp2)
    return num_clusters, landpts_cluster
def comprobarCamino(cont, initialStation, salidas):
    lista=[]
    for a in range(0,len(salidas)):
        nuevo_scc= scc.KosarajuSCC(cont["connections"])
        verdad = scc.stronglyConnected(nuevo_scc, initialStation, salidas[a])
        if verdad:
            lista.append(salidas[a])
    if lista == []:
        lista = "NO EXISTEN"
    return lista   
Esempio n. 19
0
def ClusterCheck(macrostructure, vertex1, vertex2):
    connected = scc.KosarajuSCC(macrostructure['connections'])
    lp1 = lt.getElement((mp.get(macrostructure['lp-names'], vertex1))['value'],
                        1)
    lp2 = lt.getElement((mp.get(macrostructure['lp-names'], vertex2))['value'],
                        1)
    pertains = scc.stronglyConnected(macrostructure['connections'], lp1, lp2)
    #pertains = None
    ans = (int(connected['components']), pertains)
    return ans
Esempio n. 20
0
def vertexComponents(analyzer, verta, vertb):
    analyzer['components'] = scc.KosarajuSCC(analyzer['connections'])
    numero = scc.connectedComponents(analyzer['components'])
    try:
        connect = scc.stronglyConnected(analyzer['components'], verta, vertb)
        if connect:
            print("el numero de vertices es: " + str(numero))
            return "estan conectados"
    except:
        print("el numero de vertices es: " + str(numero))
        return "NO estan conectados"
def sameCC(analyzer, station1, station2):
    vert1 = gr.containsVertex(analyzer["graph"], station1)
    vert2 = gr.containsVertex(analyzer["graph"], station2)
    if vert1 is False and vert2 is False:
        return "0"
    elif vert1 is False:
        return "1"
    elif vert2 is False:
        return "2"
    else:
        return scc.stronglyConnected(analyzer['components'], station1, station2)
Esempio n. 22
0
def sameCC(graph, station1, station2):
    """
    RETO4 | REQ1
    Consulta si dos vértices pertenecen al mismo componente
    fuertemente conectado.
    """
    sc = scc.KosarajuSCC(graph)
    if gr.containsVertex(graph, station1) and gr.containsVertex(
            graph, station2):
        return scc.stronglyConnected(sc, station1, station2)
    else:
        return None
Esempio n. 23
0
def IsItConnected(analyzer, verta, vertb):
    """
    Calcula los componentes conectados del grafo
    Se utiliza el algoritmo de Kosaraju
    """
    if gr.containsVertex(analyzer["graph"], verta) and gr.containsVertex(
            analyzer["graph"], vertb):
        analyzer['components'] = scc.KosarajuSCC(analyzer['graph'])
        return scc.stronglyConnected(analyzer['components'], verta, vertb)
    else:
        print("La estación no existe")
        return False
Esempio n. 24
0
def clustersandlandingpoints(analyzer, lp1, lp2):
    analyzer['components'] = scc.KosarajuSCC(analyzer['cables'])
    clusters = scc.connectedComponents(analyzer['components'])
    a = mp.get(analyzer["landing_points_cables"], lp1)
    lp1list = me.getValue(a)
    b = mp.get(analyzer["landing_points_cables"], lp2)
    lp2list = me.getValue(b)

    for i in lt.iterator(lp1list):
        for e in lt.iterator(lp2list):
            connected = scc.stronglyConnected(analyzer['components'], i, e)
            if connected:
                break

    return (clusters, connected)
Esempio n. 25
0
def getClusters(catalog, LP1, LP2):
    SCCc = scc.KosarajuSCC(catalog['connections'])
    numComponentes1 = scc.connectedComponents(SCCc)
    boolean = False
    infoLP1 = me.getValue(mp.get(catalog['landing_points'], LP1))
    infoLP2 = me.getValue(mp.get(catalog['landing_points'], LP2))
    for cable1 in lt.iterator(infoLP1['cables']):
        cable_LP1 = formatVertex(LP1, cable1['cable_name'])
        for cable2 in lt.iterator(infoLP2['cables']):
            cable_LP2 = formatVertex(LP2, cable2['cable_name'])

            boolean = scc.stronglyConnected(SCCc, cable_LP1, cable_LP2)
            if boolean:
                break

    return numComponentes1, boolean
Esempio n. 26
0
def req1(catalog,vera,verb):
    cities=catalog['cities']
    veraid=mp.get(cities,vera)['value']
    verbid=mp.get(cities,verb)['value']
    scc=sc.KosarajuSCC(catalog['connections'])
    print('La cantidad de clusteres es: '+str(sc.connectedComponents(scc))+'.')
    ldka=mp.get(catalog['lpkeys'],veraid)['value']
    ldkb=mp.get(catalog['lpkeys'],verbid)['value']
    for a in ldka:
        for b in ldkb:
            v=sc.stronglyConnected(scc,a,b)
            if v == True:
                print('Los landing points {0} y {1} hacen parte de un mismo cluster'.format(veraid,verbid))
                break
    
    print('Los landing points {0} y {1} no hacen parte de un mismo cluster'.format(veraid,verbid))
Esempio n. 27
0
def identificar_cluster (graph,lndPoint1,lndPoint2,pMap):

    idLndP1 = obtener_codeLP(pMap,lndPoint1)
    idLndP2 = obtener_codeLP(pMap,lndPoint2)

    sccGraph = scc.KosarajuSCC(graph)
    sccCant = scc.connectedComponents(sccGraph)

    clusterLP1 = mp.get(sccGraph['idscc'],idLndP1)['value']
    clusterLP2 = mp.get(sccGraph['idscc'],idLndP2)['value']

    cfc = scc.stronglyConnected(sccGraph,idLndP1,idLndP2)

    clts = clusterLP1,clusterLP2
    rta = sccCant,cfc
    return clts,rta
Esempio n. 28
0
def connected_components(analyzer, landing_name1, landing_name2):
    #req 1
    """
    Calcula los componentes conectados del grafo
    Se utiliza el algoritmo de Kosaraju
    """
    landing_id1 = name_to_id(analyzer, landing_name1)
    landing_id2 = name_to_id(analyzer, landing_name2)
    cable1 = lt.getElement(
        m.get(analyzer['landing_points_cables'], landing_id1)['value'], 1)
    cable2 = lt.getElement(
        m.get(analyzer['landing_points_cables'], landing_id2)['value'], 1)
    verta = format_vertex(landing_id1, cable1)
    vertb = format_vertex(landing_id2, cable2)
    analyzer['components'] = scc.KosarajuSCC(analyzer['connections'])
    connected = scc.stronglyConnected(analyzer['components'], verta, vertb)
    return scc.connectedComponents(analyzer['components']), connected
Esempio n. 29
0
def clusterL(analyzer, point1, point2):
    data = analyzer['cables']
    ciclos = scc.KosarajuSCC(data)
    #numero de componenetes conectados
    cone= scc.connectedComponents(ciclos)
    #conectados
    lista = gr.vertices(data)
    r = mp.keySet(analyzer['LPnames'])
    for i in lt.iterator(r):
        if point1 in i:
            id1 = (mp.get(analyzer['LPnames'], i))['value']
        elif point2 in i:
            id2 = (mp.get(analyzer['LPnames'], i))['value']
    
    ans = scc.stronglyConnected(ciclos,id1, id2)
    
    return cone, ans
Esempio n. 30
0
def connectedComponents(analyzer, verta, vertb):
    """
    Calcula los componentes conectados del grafo
    Se utiliza el algoritmo de Kosaraju
    """
    analyzer['components'] = scc.KosarajuSCC(analyzer['connections_distancia'])
    id_a = traduccion(verta, analyzer)
    id_b = traduccion(vertb, analyzer)
    pareja1 = m.get(analyzer['landing_points'], id_a)
    cableid1 = lt.getElement(me.getValue(pareja1)['conexiones'],
                             1)['vertice'][1]
    pareja2 = m.get(analyzer['landing_points'], id_b)
    cableid2 = lt.getElement(me.getValue(pareja2)['conexiones'],
                             1)['vertice'][1]
    vertice1 = (id_a, cableid1)
    vertice2 = (id_b, cableid2)
    conectados = scc.stronglyConnected(analyzer['components'], vertice1,
                                       vertice2)
    return (scc.connectedComponents(analyzer['components']), conectados)